chore: automate versioning workflows #6
This file contains hidden or 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: CI | |
| on: | |
| push: | |
| branches: [main] | |
| paths-ignore: | |
| - "**/*.md" | |
| - "LICENSE" | |
| pull_request: | |
| branches: [main] | |
| paths-ignore: | |
| - "**/*.md" | |
| - "LICENSE" | |
| workflow_dispatch: | |
| concurrency: | |
| group: ci-${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| checks: write | |
| env: | |
| DOTNET_VERSION: 10.0.x | |
| SOLUTION_FILE: Yellowcake.slnx | |
| MIN_COVERAGE_PERCENT: 15 | |
| jobs: | |
| build-and-test: | |
| name: Build & Test (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| cache: true | |
| cache-dependency-path: | | |
| **/*.csproj | |
| **/packages.lock.json | |
| global.json | |
| - name: Restore | |
| run: dotnet restore ${{ env.SOLUTION_FILE }} --nologo | |
| - name: Compute CI version metadata | |
| id: version | |
| shell: bash | |
| run: | | |
| ci_version="0.0.${GITHUB_RUN_NUMBER}.${GITHUB_RUN_ATTEMPT}" | |
| semver="0.0.${GITHUB_RUN_NUMBER}" | |
| info="${semver}+ci.${GITHUB_RUN_NUMBER}.${GITHUB_RUN_ATTEMPT}.${GITHUB_SHA::7}" | |
| echo "assembly=${ci_version}" >> "$GITHUB_OUTPUT" | |
| echo "file=${ci_version}" >> "$GITHUB_OUTPUT" | |
| echo "semver=${semver}" >> "$GITHUB_OUTPUT" | |
| echo "info=${info}" >> "$GITHUB_OUTPUT" | |
| - name: Build | |
| run: dotnet build ${{ env.SOLUTION_FILE }} -c Release --no-restore --nologo -warnaserror /p:Version=${{ steps.version.outputs.semver }} /p:AssemblyVersion=${{ steps.version.outputs.assembly }} /p:FileVersion=${{ steps.version.outputs.file }} /p:InformationalVersion=${{ steps.version.outputs.info }} | |
| - name: Verify formatting | |
| if: runner.os == 'Linux' | |
| run: dotnet format ${{ env.SOLUTION_FILE }} --verify-no-changes --no-restore | |
| - name: Test with coverage | |
| run: dotnet test ${{ env.SOLUTION_FILE }} -c Release --no-build --nologo --logger "trx;LogFileName=test-results.trx" --collect "XPlat Code Coverage" --results-directory TestResults/${{ runner.os }} | |
| - name: Upload test artifacts | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results-${{ runner.os }} | |
| path: TestResults/${{ runner.os }} | |
| if-no-files-found: warn | |
| retention-days: 14 | |
| - name: Enforce minimum coverage | |
| if: runner.os == 'Linux' | |
| shell: pwsh | |
| run: | | |
| $coverageFile = Get-ChildItem -Path "TestResults/${{ runner.os }}" -Recurse -Filter "coverage.cobertura.xml" | Select-Object -First 1 | |
| if (-not $coverageFile) { | |
| throw "Coverage report not found under TestResults/${{ runner.os }}" | |
| } | |
| [xml]$coverageXml = Get-Content $coverageFile.FullName | |
| $lineRate = [double]$coverageXml.coverage.'line-rate' * 100 | |
| $minCoverage = [double]"${{ env.MIN_COVERAGE_PERCENT }}" | |
| Write-Host "Measured line coverage: $([math]::Round($lineRate, 2))%" | |
| Write-Host "Minimum required line coverage: $minCoverage%" | |
| if ($lineRate -lt $minCoverage) { | |
| throw "Coverage gate failed: $([math]::Round($lineRate, 2))% < $minCoverage%" | |
| } | |
| package-smoke: | |
| name: Package Smoke Check (Linux) | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| cache: true | |
| cache-dependency-path: | | |
| **/*.csproj | |
| **/packages.lock.json | |
| global.json | |
| - name: Restore | |
| run: dotnet restore ${{ env.SOLUTION_FILE }} --nologo | |
| - name: Compute CI version metadata | |
| id: version | |
| shell: bash | |
| run: | | |
| ci_version="0.0.${GITHUB_RUN_NUMBER}.${GITHUB_RUN_ATTEMPT}" | |
| semver="0.0.${GITHUB_RUN_NUMBER}" | |
| info="${semver}+ci.${GITHUB_RUN_NUMBER}.${GITHUB_RUN_ATTEMPT}.${GITHUB_SHA::7}" | |
| echo "assembly=${ci_version}" >> "$GITHUB_OUTPUT" | |
| echo "file=${ci_version}" >> "$GITHUB_OUTPUT" | |
| echo "semver=${semver}" >> "$GITHUB_OUTPUT" | |
| echo "info=${info}" >> "$GITHUB_OUTPUT" | |
| - name: Publish linux-x64 | |
| run: dotnet publish Yellowcake.csproj -c Release -r linux-x64 --self-contained true -p:ContinuousIntegrationBuild=true -p:PublishSingleFile=true -p:EnableCompressionInSingleFile=true --nologo -o publish/linux-x64 /p:Version=${{ steps.version.outputs.semver }} /p:AssemblyVersion=${{ steps.version.outputs.assembly }} /p:FileVersion=${{ steps.version.outputs.file }} /p:InformationalVersion=${{ steps.version.outputs.info }} | |
| - name: Smoke test executable exists | |
| run: test -f publish/linux-x64/Yellowcake |