-
-
Notifications
You must be signed in to change notification settings - Fork 1k
chore: Add workflow to generate code coverage report #3022
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
timcassell
merged 1 commit into
dotnet:master
from
filzrev:chore-add-codecoverage-report-workflow
Feb 27, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| name: generate-coverage-report | ||
| run-name: Generate coverage coverage report ${{ github.event.head_commit.message }} | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| skip_integration_tests: | ||
| type: boolean | ||
| description: Set `true` to skip integration tests. | ||
| default: true | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.inputs.skip_integration_tests }}-${{ github.head_ref || github.ref || github.run_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| collect-coverage: | ||
| runs-on: ${{ matrix.os }} | ||
| defaults: | ||
| run: | ||
| shell: pwsh | ||
| strategy: | ||
| matrix: | ||
| # Note: ARM64 on linux/macos are not supported. | ||
| # https://github.com/microsoft/codecoverage/blob/main/docs/supported-os.md | ||
| os: [windows-latest, ubuntu-latest, macos-15-intel, windows-11-arm] | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| # Ensure DOTNET_ROOT environment variable set on macos-15-intel | ||
| - uses: actions/setup-dotnet@v5 | ||
| with: | ||
| dotnet-version: | | ||
| 8.x | ||
|
|
||
| - name: Install dotnet-coverage | ||
| run: dotnet tool install --global dotnet-coverage | ||
|
|
||
| - name: Run task 'build' | ||
| run: dotnet build BenchmarkDotNet.slnx -c Release | ||
|
|
||
| - name: Start dotnet-coverage with background server mode | ||
| run: dotnet coverage collect --session-id bdn_coverage --settings tests/CodeCoverage.config --server-mode --background | ||
|
|
||
| - name: Collect Code Coverage | ||
| run: | | ||
| dotnet coverage connect bdn_coverage "dotnet test tests/BenchmarkDotNet.Tests -c Release --no-build --framework net8.0" | ||
| dotnet coverage connect bdn_coverage "dotnet test tests/BenchmarkDotNet.Analyzers.Tests -c Release --no-build --framework net8.0" | ||
|
|
||
| - name: Collect Code Coverage for BenchmarkDotNet.IntegrationTests | ||
| if: ${{ github.event.inputs.skip_integration_tests == 'false'}} | ||
| run: | | ||
| dotnet coverage connect bdn_coverage 'dotnet test tests/BenchmarkDotNet.IntegrationTests -c Release --no-build --framework net8.0 --filter "(FullyQualifiedName!~DotMemoryTests) & (FullyQualifiedName!~DotTraceTests) & (FullyQualifiedName!~WasmIsSupported) & (FullyQualifiedName!~WasmSupportsInProcessDiagnosers)"' | ||
|
|
||
| - name: Shutdown dotnet-coverage server. | ||
| run: dotnet coverage shutdown bdn_coverage --timeout 60000 | ||
|
|
||
| - name: Upload coverage artifact | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: coverage-${{ matrix.os }} | ||
| path: "**/*.cobertura.xml" | ||
|
|
||
| collect-coverage-netfx: | ||
| runs-on: windows-latest | ||
| defaults: | ||
| run: | ||
| shell: pwsh | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - name: Install dotnet-coverage | ||
| run: dotnet tool install --global dotnet-coverage | ||
|
|
||
| - name: Run task 'build' | ||
| run: dotnet build BenchmarkDotNet.slnx -c Release | ||
|
|
||
| - name: Start dotnet-coverage with background server mode | ||
| run: dotnet coverage collect --session-id bdn_coverage --settings tests/CodeCoverage.config --server-mode --background | ||
|
|
||
| - name: Collect Code Coverage | ||
| run: | | ||
| dotnet coverage connect bdn_coverage "dotnet test tests/BenchmarkDotNet.Tests -c Release --no-build --framework net462" | ||
| dotnet coverage connect bdn_coverage "dotnet test tests/BenchmarkDotNet.Analyzers.Tests -c Release --no-build --framework net462" | ||
|
|
||
| - name: Collect Code Coverage for BenchmarkDotNet.IntegrationTests | ||
| if: ${{ github.event.inputs.skip_integration_tests == 'false'}} | ||
| run: | | ||
| dotnet coverage connect bdn_coverage 'dotnet test tests/BenchmarkDotNet.IntegrationTests -c Release --no-build --framework net462 --filter "(FullyQualifiedName!~DotMemoryTests) & (FullyQualifiedName!~DotTraceTests) & (FullyQualifiedName!~WasmIsSupported) & (FullyQualifiedName!~WasmSupportsInProcessDiagnosers)"' | ||
|
|
||
| - name: Shutdown dotnet-coverage server. | ||
| run: dotnet coverage shutdown bdn_coverage --timeout 60000 | ||
|
|
||
| - name: Upload coverage artifact | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: coverage-windows-netfx | ||
| path: "**/*.cobertura.xml" | ||
|
|
||
| generate-coverage-report: | ||
| needs: [collect-coverage, collect-coverage-netfx] | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| shell: pwsh | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - uses: actions/download-artifact@v6 | ||
| with: | ||
| path: coverage | ||
|
|
||
| - name: Upload raw coverage data | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: coverage | ||
| path: coverage | ||
|
|
||
| - name: Rewrite file path map to absolute path | ||
| run: | | ||
| $baseSourcePath = Get-Location | ||
| $files = [IO.Directory]::GetFiles("coverage", "coverage.cobertura.xml", [IO.SearchOption]::AllDirectories) | ||
| foreach($file in $files) | ||
| { | ||
| $content = [IO.File]::ReadAllText($file).Replace("/_/", [Environment]::CurrentDirectory + '/') | ||
| [IO.File]::WriteAllText($file, $content) | ||
| } | ||
|
|
||
| - name: Install ReportGenerator as global tool | ||
| run: dotnet tool install --global dotnet-reportgenerator-globaltool | ||
|
|
||
| - name: Geterate reports | ||
| run: | | ||
| reportgenerator ` | ||
| -reports:"coverage/**/coverage.cobertura.xml" ` | ||
| -targetdir:"coverage_report/reports" ` | ||
| -reporttypes:"Html;MarkdownSummaryGithub" | ||
|
|
||
| - name: Create index.html | ||
| run: | | ||
| $html = @" | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta http-equiv="refresh" content="0; url=reports/index.html"> | ||
| <title>Redirect</title> | ||
| </head> | ||
| <body> | ||
| <p>If you are not redirected automatically, <a href="reports/index.html">click here</a>.</p> | ||
| </body> | ||
| </html> | ||
| "@ | ||
| [IO.File]::WriteAllText("coverage_report/index.html", $html) | ||
|
|
||
| - name: Write coverage summary | ||
| run: | | ||
| $markdown = Get-Content coverage_report/reports/SummaryGithub.md -Raw | ||
| Write-Output $markdown >> $env:GITHUB_STEP_SUMMARY | ||
|
|
||
| - name: Upload HTML report files | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: coverage_report | ||
| path: coverage_report | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Configuration> | ||
| <!-- Available Options: https://github.com/microsoft/codecoverage/blob/main/docs/configuration.md --> | ||
| <CoverageFileName>coverage.cobertura.xml</CoverageFileName> | ||
| <Format>cobertura</Format> | ||
| <IncludeTestAssembly>false</IncludeTestAssembly> | ||
| <DeterministicReport>true</DeterministicReport> | ||
| <CollectFromChildProcesses>true</CollectFromChildProcesses> | ||
| <CodeCoverage> | ||
| <ModulePaths> | ||
| <Include> | ||
| <ModulePath>.*BenchmarkDotNet\.dll$</ModulePath> | ||
| <ModulePath>.*BenchmarkDotNet.*\.dll$</ModulePath> | ||
| </Include> | ||
| <Exclude> | ||
| <!-- Exclude third party DLLs --> | ||
| <ModulePath>.*Argon\.dll$</ModulePath> | ||
| <ModulePath>.*DiffEngine\.dll$</ModulePath> | ||
| <ModulePath>.*EmptyFiles\.dll$</ModulePath> | ||
| <ModulePath>.*Microsoft\.CodeAnalysis\.Analyzer\.Testing\.dll$</ModulePath> | ||
| <ModulePath>.*Microsoft\.CodeAnalysis\.CSharp\.Analyzer\.Testing\.dll$</ModulePath> | ||
| <ModulePath>.*Verify\.dll$</ModulePath> | ||
| <ModulePath>.*Verify\.Xunit\.dll$</ModulePath> | ||
|
|
||
| <!-- Exclude test DLLs --> | ||
| <ModulePath>.*BenchmarkDotNet\.Analyzers\.Tests\.dll$</ModulePath> | ||
| <ModulePath>.*BenchmarkDotNet\.Tests\.dll$</ModulePath> | ||
| <ModulePath>.*BenchmarkDotNet\.IntegrationTests\.dll$</ModulePath> | ||
|
|
||
| <!-- Exclude auto generated project DLLs --> | ||
| <ModulePath>.*IntegrationTests.*\.dll$</ModulePath> | ||
| <ModulePath>.*Dry.*\.dll$</ModulePath> | ||
| <ModulePath>.*FSharp.Core\.dll$</ModulePath> | ||
| </Exclude> | ||
| </ModulePaths> | ||
| <Attributes> | ||
| <Exclude> | ||
| <Attribute>^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$</Attribute> | ||
| </Exclude> | ||
| </Attributes> | ||
| <Sources> | ||
| <Exclude> | ||
| <Source>.*\\[^\\]*\CodeAnnotations\.cs</Source> | ||
| <Source>.*\\[^\\]*\.g\.cs</Source> | ||
| <Source>.*\\[^\\]*\.notcs</Source> | ||
| </Exclude> | ||
| </Sources> | ||
| <!-- Disable following settings. Because C++ code is not contained (See: https://github.com/microsoft/codecoverage/blob/main/README.md#get-started)--> | ||
| <EnableStaticNativeInstrumentation>False</EnableStaticNativeInstrumentation> | ||
| <EnableDynamicNativeInstrumentation>False</EnableDynamicNativeInstrumentation> | ||
| </CodeCoverage> | ||
| </Configuration> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.