From 83ef29e0a008a30602bf77b7f60d567d355a400f Mon Sep 17 00:00:00 2001 From: David Bond Date: Sun, 27 Sep 2026 22:12:18 +0100 Subject: [PATCH] OPS-157454: Upload test coverage to Codacy from CI Adds a coverage job that runs the test project as a Microsoft.Testing.Platform executable with Microsoft.Testing.Extensions.CodeCoverage and uploads the Cobertura report to Codacy, on the self-hosted pdl-public runners. Excluded tests: none - every test is offline (132 tests, 1 explicitly skipped). Local line coverage (clean Linux container, no user secrets): 73.2% Co-Authored-By: Claude Opus 5.5 (1M context) --- .github/workflows/ci.yml | 67 ++++++++++++++++++- .../PanoramicData.SheetMagic.Test.csproj | 1 + coverage.config | 33 +++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 coverage.config diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e118710..7da249b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,71 @@ jobs: name: packages path: ./artifacts/*.nupkg + # Collects line coverage and publishes it to Codacy. Runs on the self-hosted + # pdl-public scale set rather than a GitHub-hosted runner. + # pdl-public is the hardened scale set that may serve a public repository: a + # fork pull request is untrusted code, so it has no dind, no privileged + # container, no hostPath and nothing shared between jobs. + coverage: + runs-on: [pdl-public] + + env: + DOTNET_NOLOGO: 1 + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + # The actions-runner image does not offer the Node version several of these + # actions request by default; without this they fail before their first step. + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true + + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + fetch-depth: 0 # Nerdbank.GitVersioning needs the full history. + + - name: Setup .NET + uses: actions/setup-dotnet@v6 + env: + # The runner user cannot write /usr/share/dotnet, the default install location. + DOTNET_INSTALL_DIR: ${{ runner.temp }}/dotnet + with: + dotnet-version: 10.0.x + + - name: Build tests + run: dotnet build PanoramicData.SheetMagic.Test/PanoramicData.SheetMagic.Test.csproj --configuration Debug + + # The test project is a Microsoft.Testing.Platform application + # (UseMicrosoftTestingPlatformRunner), so coverage is collected by running the + # test executable directly with Microsoft.Testing.Extensions.CodeCoverage rather + # than through `dotnet test`. On Linux the executable has no .exe extension. + # coverage.config ports coverlet's generated-code exclusions so figures stay + # comparable across the estate. + - name: Run tests with coverage + run: >- + ./PanoramicData.SheetMagic.Test/bin/Debug/net10.0/PanoramicData.SheetMagic.Test + --coverage + --coverage-settings coverage.config + --coverage-output-format cobertura + --coverage-output coverage.cobertura.xml + + # continue-on-error: a Codacy outage must not turn a passing test run red. The + # trade-off is that an expired or missing project token fails silently, so + # check the step log for "Coverage received successfully". + - name: Upload coverage to Codacy + continue-on-error: true + uses: codacy/codacy-coverage-reporter-action@v1 + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + coverage-reports: PanoramicData.SheetMagic.Test/bin/Debug/net10.0/TestResults/coverage.cobertura.xml + + - name: Upload coverage artifact + if: always() + continue-on-error: true + uses: actions/upload-artifact@v7 + with: + name: coverage + path: PanoramicData.SheetMagic.Test/bin/Debug/net10.0/TestResults/coverage.cobertura.xml + retention-days: 7 + publish: needs: build runs-on: ubuntu-latest @@ -64,4 +129,4 @@ jobs: user: david_n_m_bond - name: Push to NuGet - run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate \ No newline at end of file + run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate diff --git a/PanoramicData.SheetMagic.Test/PanoramicData.SheetMagic.Test.csproj b/PanoramicData.SheetMagic.Test/PanoramicData.SheetMagic.Test.csproj index d5c53a1..c196a95 100644 --- a/PanoramicData.SheetMagic.Test/PanoramicData.SheetMagic.Test.csproj +++ b/PanoramicData.SheetMagic.Test/PanoramicData.SheetMagic.Test.csproj @@ -3,6 +3,7 @@ Exe net10.0 + true latest enable false diff --git a/coverage.config b/coverage.config new file mode 100644 index 0000000..cf54802 --- /dev/null +++ b/coverage.config @@ -0,0 +1,33 @@ + + + + + + + .*Test\.dll$ + .*Tests\.dll$ + + + + + ^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$ + ^System\.Runtime\.CompilerServices\.CompilerGeneratedAttribute$ + ^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$ + ^System\.ObsoleteAttribute$ + + + + + .*\\obj\\.* + + + False + True + +