From be5723ec4b0069649208ab5b9a6ffd0e380282d4 Mon Sep 17 00:00:00 2001 From: David Bond Date: Sun, 27 Sep 2026 22:17:57 +0100 Subject: [PATCH] OPS-157454: Upload test coverage to Codacy from CI Adds a coverage job to CI that runs the offline tests with Microsoft.Testing.Extensions.CodeCoverage and uploads the Cobertura report to Codacy, on the pdl-public runner. Excluded from CI (need credentials or a live service): nothing; all 92 tests run offline, so no filter is applied. Local line coverage with the CI filter, in a clean Linux container: 60.4%. Also sets UseMicrosoftTestingPlatformRunner in the test project, without which the xunit v3 test executable rejects --coverage. The figure includes the Demo assembly (18.0%); the library itself is at 89.9%. Co-Authored-By: Claude Opus 5.5 (1M context) --- .github/workflows/ci.yml | 62 +++++++++++++++++++ .../PanoramicData.ChartMagic.Test.csproj | 1 + coverage.config | 33 ++++++++++ 3 files changed, 96 insertions(+) create mode 100644 coverage.config diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e118710..df9f4fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,68 @@ jobs: name: packages path: ./artifacts/*.nupkg + # Test coverage, uploaded to Codacy (OPS-157454). + # pdl-public, never a GitHub-hosted runner and never pdl-prod-cluster: this repository is public, + # so a fork pull request is untrusted code, and pdl-public is the hardened scale set that may run + # it (no dind, no privileged container, no hostPath, 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 runs. + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true + + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 # avoid shallow clone so nbgv can do its work. + + - name: Setup .NET + uses: actions/setup-dotnet@v6 + # The runner user cannot write /usr/share/dotnet, so install the SDK somewhere it can. + env: + DOTNET_INSTALL_DIR: ${{ runner.temp }}/dotnet + with: + dotnet-version: 10.0.x + + - name: Build tests + run: dotnet build PanoramicData.ChartMagic.Test/PanoramicData.ChartMagic.Test.csproj --configuration Debug + + # The test project is a Microsoft.Testing.Platform application, so coverage is collected by + # running the test executable directly (Microsoft.Testing.Extensions.CodeCoverage) rather than + # through `dotnet test`. On Linux the executable has no .exe extension. + # + # Every test in this repository runs offline with no credentials, so no filter is applied. + - name: Run tests with coverage + run: >- + ./PanoramicData.ChartMagic.Test/bin/Debug/net10.0/PanoramicData.ChartMagic.Test + --coverage + --coverage-settings "$GITHUB_WORKSPACE/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 log for + # "Coverage received successfully" when in doubt. + - 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.ChartMagic.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.ChartMagic.Test/bin/Debug/net10.0/TestResults/coverage.cobertura.xml + retention-days: 7 + publish: needs: build runs-on: ubuntu-latest diff --git a/PanoramicData.ChartMagic.Test/PanoramicData.ChartMagic.Test.csproj b/PanoramicData.ChartMagic.Test/PanoramicData.ChartMagic.Test.csproj index ccc39eb..19dbadf 100644 --- a/PanoramicData.ChartMagic.Test/PanoramicData.ChartMagic.Test.csproj +++ b/PanoramicData.ChartMagic.Test/PanoramicData.ChartMagic.Test.csproj @@ -2,6 +2,7 @@ net10.0 + true false latest latest-recommended 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 + +