Repository navigation
OPS-157454: Upload test coverage to Codacy from CI #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,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 SchemaMagic.Tests/SchemaMagic.Tests.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: >- | ||
| ./SchemaMagic.Tests/bin/Debug/net10.0/SchemaMagic.Tests | ||
| --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: SchemaMagic.Tests/bin/Debug/net10.0/TestResults/coverage.cobertura.xml | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 馃敶 HIGH RISK The path to the coverage report likely doesn't match the output of the run command. When running the executable from the root with '--coverage-output coverage.cobertura.xml', the Microsoft.Testing.Platform typically places results in a 'TestResults' folder in the current working directory. Update this path to 'TestResults/coverage.cobertura.xml' to resolve the 'MissingRequirements' error reported by Codacy. |
||
|
|
||
| - name: Upload coverage artifact | ||
| if: always() | ||
| continue-on-error: true | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: coverage | ||
| path: SchemaMagic.Tests/bin/Debug/net10.0/TestResults/coverage.cobertura.xml | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 馃敶 HIGH RISK Update the artifact path to match the actual output location, likely 'TestResults/coverage.cobertura.xml', to ensure the report is correctly archived. |
||
| retention-days: 7 | ||
|
|
||
| publish: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
|
|
@@ -61,4 +126,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 | ||
| run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
| Microsoft.Testing.Extensions.CodeCoverage settings. | ||
|
|
||
| The attribute exclusions are not optional if figures are to stay comparable across the estate: the | ||
| Microsoft collector includes generated code by default, where coverlet excluded it. Porting them is | ||
| worth several points of apparent coverage on a repository with generated clients. | ||
| --> | ||
| <Configuration> | ||
| <CodeCoverage> | ||
| <ModulePaths> | ||
| <Exclude> | ||
| <ModulePath>.*Test\.dll$</ModulePath> | ||
| <ModulePath>.*Tests\.dll$</ModulePath> | ||
| </Exclude> | ||
| </ModulePaths> | ||
| <Attributes> | ||
| <Exclude> | ||
| <Attribute>^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$</Attribute> | ||
| <Attribute>^System\.Runtime\.CompilerServices\.CompilerGeneratedAttribute$</Attribute> | ||
| <Attribute>^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$</Attribute> | ||
| <Attribute>^System\.ObsoleteAttribute$</Attribute> | ||
| </Exclude> | ||
| </Attributes> | ||
| <Sources> | ||
| <Exclude> | ||
| <Source>.*\\obj\\.*</Source> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 馃煛 MEDIUM RISK The regex for excluding the 'obj' directory uses literal backslashes ( |
||
| </Exclude> | ||
| </Sources> | ||
| <UseVerifiableInstrumentation>False</UseVerifiableInstrumentation> | ||
| <CollectFromChildProcesses>True</CollectFromChildProcesses> | ||
| </CodeCoverage> | ||
| </Configuration> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
馃煛 MEDIUM RISK
Suggestion: Move the installation directory configuration from the 'env' block to the 'with' block using the 'dotnet-install-dir' parameter to ensure the action installs .NET to the correct location on self-hosted runners.