Skip to content

Continuous Integration #3697

Continuous Integration

Continuous Integration #3697

Workflow file for this run

name: Continuous Integration
on:
push:
branches:
- "master"
tags:
- "*"
pull_request:
types: [synchronize]
schedule:
- cron: "0 0 * * *"
env:
DOTNET_NOLOGO: "true"
CONFIGURATION: Release
NUGET_FEED_URL: https://api.nuget.org/v3/index.json
GITHUB_PACKAGES_FEED_URL: https://nuget.pkg.github.com/cythral/index.json
permissions:
contents: read
id-token: write
jobs:
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_OSS_ROLE }}
aws-region: us-east-1
- name: Set version
shell: bash
run: echo "VERSION=$(cat version.json | jq -r '.version')" >> $GITHUB_ENV
- name: Display version
run: echo ${{ env.VERSION }}
- name: Check for Stale Version Number
if: ${{ !startsWith(github.ref , 'refs/tags/v') }}
shell: bash
run: |
lastTaggedVersion=$(git describe --abbrev=0 --tags)
lastTaggedVersionSha=$(git rev-list -n 1 $lastTaggedVersion)
if [ "$lastTaggedVersion" = "v$VERSION" ] && [ "$lastTaggedVersionSha" != "${{ github.sha }}" ]; then exit 1; fi
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "6.0.x"
global-json-file: "./global.json"
- name: Display .NET Info
run: dotnet --info
- name: Restore
run: dotnet restore
- name: Build
shell: bash
run: dotnet build --no-restore -m -bl:obj/logs/build-${{ matrix.os }}.binlog -p:OutputLayerTemplateFilePath=$(pwd)/Layer.template.yml
env:
UPLOAD_LAYER_TEMPLATE: ${{ matrix.os == 'ubuntu-latest' }}
- name: Test
run: dotnet test --no-build --collect:"XPlat Code coverage"
- name: Upload Coverage
uses: codecov/codecov-action@v3
if: matrix.os == 'ubuntu-latest'
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./obj/Tests/Release/net7.0/coverage.xml
fail_ci_if_error: true
- name: Upload Nugets
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v3
with:
name: nugets
path: bin/Packages/${{ env.CONFIGURATION }}
- name: Upload Logs
uses: actions/upload-artifact@v3
with:
name: logs-${{ matrix.os }}
path: obj/logs/
- name: Upload Layer Template
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v3
with:
name: layer-template
path: Layer.template.yml
if-no-files-found: ignore
- name: Deploy to Github Packages
if: matrix.os == 'ubuntu-latest' && github.event_name == 'push'
run: dotnet nuget push "bin/Packages/${CONFIGURATION}/*.nupkg" -k ${FEED_TOKEN} -s ${FEED_URL} --skip-duplicate --no-symbols
env:
FEED_TOKEN: ${{ secrets.GH_TOKEN }}
FEED_URL: ${{ env.GITHUB_PACKAGES_FEED_URL }}
- name: Discord Failure Notification
uses: Ilshidur/action-discord@master
if: failure() && (github.event_name == 'push' || github.event_name == 'schedule')
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
DISCORD_EMBEDS: |
[
{
"title": "[${{ github.repository }}] Build Failed",
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"description": "An error occurred while building ${{ github.repository }} ${{ env.VERSION }} on ${{ matrix.os }}",
"color": 12720135
}
]
end-to-end-tests:
runs-on: ubuntu-latest
needs: build
concurrency: end-to-end
if: startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'E2E') || github.event_name == 'schedule'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
- name: Display .NET Info
run: dotnet --info
- name: Download NuGets
uses: actions/download-artifact@v3
id: download-nugets
with:
name: nugets
path: bin/Packages/Release
- name: Download Layer Template
uses: actions/download-artifact@v3
id: download-layer-template
with:
name: layer-template
path: ./
- name: Set version
shell: bash
run: echo "VERSION=$(cat version.json | jq -r '.version')" >> $GITHUB_ENV
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_OSS_ROLE }}
aws-region: us-east-1
- name: Test
run: dotnet build -t:EndToEndTests -p:PackageBucket=${BUCKET}
env:
BUCKET: ${{ secrets.ARTIFACT_BUCKET }}
- name: Discord Failure Notification
uses: Ilshidur/action-discord@master
if: failure() && (github.event_name == 'push' || github.event_name == 'schedule')
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
DISCORD_EMBEDS: |
[
{
"title": "[${{ github.repository }}] End-To-End Tests Failed",
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"description": "An error occurred while running the end-to-end tests for ${{ github.repository }} ${{ env.VERSION }}",
"color": 12720135
}
]
release:
needs:
- build
- end-to-end-tests
runs-on: ubuntu-latest
environment:
name: Production
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_OSS_ROLE }}
aws-region: us-east-1
- name: Set version
shell: bash
run: echo "VERSION=$(cat version.json | jq -r '.version')" >> $GITHUB_ENV
- name: Download NuGets
uses: actions/download-artifact@v3
id: download-nugets
with:
name: nugets
- name: Download Layer Template
uses: actions/download-artifact@v3
id: download-layer-template
with:
name: layer-template
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
- name: Display .NET Info
run: dotnet --info
- name: Deploy to NuGet
run: dotnet nuget push '${{ steps.download-nugets.outputs.download-path }}/*.nupkg' -k ${FEED_TOKEN} -s ${FEED_URL} --skip-duplicate
env:
FEED_TOKEN: ${{ secrets.NUGET_TOKEN }}
FEED_URL: ${{ env.NUGET_FEED_URL }}
- name: Publish to SAR
run: |
set -eo pipefail
sam publish \
--template ${{ steps.download-layer-template.outputs.download-path }}/Layer.template.yml \
--region us-east-1 \
--semantic-version ${VERSION}
- uses: ncipollo/release-action@v1
with:
artifacts: "${{ steps.download-nugets.outputs.download-path }}/*.nupkg,${{ steps.download-nugets.outputs.download-path }}/*.snupkg"
bodyFile: ".github/releases/v${{ env.VERSION }}.md"
tag: v${{ env.VERSION }}
commit: ${{ github.sha }}
token: ${{ secrets.GH_TOKEN }}
prerelease: ${{ contains(env.VERSION, '-') }}
- name: Discord Failure Notification
uses: Ilshidur/action-discord@master
if: failure()
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
DISCORD_EMBEDS: |
[
{
"title": "[${{ github.repository }}] Release Failed",
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"description": "An error occurred while releasing ${{ github.repository }} ${{ env.VERSION }}",
"color": 12720135
}
]