Publish test results with the dorny/test-reporter GitHub action #4
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous Integration & Delivery | |
on: | |
push: | |
branches: [ develop, main, bugfix/*, feature/* ] | |
pull_request: | |
branches: [ develop, main ] | |
workflow_dispatch: | |
inputs: | |
publish_nuget_package: | |
description: Publish a new NuGet package? | |
required: false | |
type: boolean | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} | |
cancel-in-progress: true | |
env: | |
DOTNET_CLI_TELEMETRY_OPTOUT: true | |
DOTNET_NOLOGO: true | |
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | |
DOTNET_USE_POLLING_FILE_WATCHER: true | |
NUGET_XMLDOC_MODE: skip | |
TZ: CET # https://stackoverflow.com/q/53510011 | |
jobs: | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ ubuntu-22.04, windows-2022 ] | |
runs-on: ${{ matrix.os }} | |
permissions: | |
checks: write | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
lfs: true | |
- name: Cache NuGet Packages | |
uses: actions/cache@v3 | |
with: | |
key: ${{ matrix.os }}-nuget-${{ hashFiles('Directory.Build.props') }} | |
path: ~/.nuget/packages | |
- name: Free Disk Space | |
run: Remove-Item -Recurse -Force '/usr/local/lib/android' -ErrorAction SilentlyContinue # TODO: Split module tests across multiple runners (the Docker images require too much disk space) | |
shell: pwsh | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
- name: Restore .NET Tools | |
run: dotnet tool restore | |
- name: Restore NuGet Packages | |
run: dotnet cake --target=Restore-NuGet-Packages | |
- name: Run Build | |
run: dotnet cake --target=Build | |
- name: Run Tests | |
run: dotnet cake --target=Tests --test-filter=${{ startsWith(matrix.os, 'ubuntu') && 'FullyQualifiedName~Testcontainers' || 'DockerPlatform=Windows' }} | |
- name: Upload Test And Coverage Results | |
uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: ${{ matrix.os }} | |
path: test-results | |
- name: Publish Test Results | |
uses: dorny/test-reporter@v1 | |
if: always() | |
with: | |
name: Test Results (${{ matrix.os }}) | |
path: test-results/*.trx | |
reporter: dotnet-trx | |
publish: | |
if: ${{ contains(fromJson('["develop", "main"]'), github.ref_name) }} | |
needs: build | |
environment: production | |
runs-on: windows-2022 # It looks like the Linux runner cannot sign the NuGet using a PFX file. | |
permissions: | |
contents: write | |
pull-requests: read | |
env: | |
CODE_SIGNING_CERTIFICATE_BASE64: ${{ secrets.CODE_SIGNING_CERTIFICATE_BASE64 }} | |
CODE_SIGNING_CERTIFICATE_PASSWORD: ${{ secrets.CODE_SIGNING_CERTIFICATE_PASSWORD }} | |
FEED_SOURCE: https://api.nuget.org/v3/index.json | |
FEED_API_KEY: ${{ secrets.FEED_API_KEY }} | |
SONARCLOUD_URL: https://sonarcloud.io | |
SONARCLOUD_ORGANIZATION: testcontainers | |
SONARCLOUD_KEY: testcontainers_testcontainers-dotnet | |
SONARCLOUD_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} | |
PUBLISH_NUGET_PACKAGE: ${{ inputs.publish_nuget_package }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
lfs: true | |
fetch-depth: 0 | |
- name: Download Test And Coverage Results (ubuntu-22.04) | |
uses: actions/download-artifact@v3 | |
with: | |
name: ubuntu-22.04 | |
path: test-results | |
- name: Download Test And Coverage Results (windows-2022) | |
uses: actions/download-artifact@v3 | |
with: | |
name: windows-2022 | |
path: test-results | |
- name: Fix Absolute Code Coverage Paths | |
run: Get-ChildItem -Path 'test-results' -Filter *.xml -Recurse | Select-Object -ExpandProperty FullName | % { (Get-Content -LiteralPath $_) -Replace 'fullPath="[A-Za-z0-9:\-\/\\]+(src|tests)', 'fullPath="${{ github.workspace }}/$1' | Set-Content -LiteralPath $_ } | |
shell: pwsh | |
- name: Decode Code Signing Certificate | |
run: echo $CODE_SIGNING_CERTIFICATE_BASE64 | base64 --decode > code-signing-certificate.pfx | |
shell: bash | |
- name: Cache NuGet Packages | |
uses: actions/cache@v3 | |
with: | |
key: windows-2022-nuget-${{ hashFiles('Directory.Build.props') }} | |
path: ~/.nuget/packages | |
- name: Setup Java | |
uses: actions/setup-java@v3 | |
with: | |
distribution: temurin | |
java-version: 17 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
- name: Restore .NET Tools | |
run: dotnet tool restore | |
- name: Restore NuGet Packages | |
run: dotnet cake --target=Restore-NuGet-Packages | |
- name: Run Sonar Analysis | |
run: dotnet cake --target=Sonar-Begin | |
- name: Run Build | |
run: dotnet cake --target=Build | |
- name: Upload Sonar Results | |
run: dotnet cake --target=Sonar-End | |
- name: Publish NuGet Package | |
run: dotnet cake --target=Publish | |
- uses: release-drafter/release-drafter@65c5fb495d1e69aa8c08a3317bc44ff8aabe9772 | |
with: | |
version: ${{ env.semVer }} # Cake sets the semVer environment variable | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |