Adding code coverage to tests in workflow (#75)
* Adding code coverage to tests in workflow This is using the pattern from the Aspire Community Toolkit which will publish coverage results to the GitHub Actions summary, as well as a comment on the PR (if the job was run by someone with permissions to write comments). Also added the GitHubActionsTestLogger so that it writes a nicer log out to the run. Fixes #11 * Feedback from code review * Slight change to structure * Bad indentation * Ensuring .NET SDK is installed * Disabling fail-fast so that jobs aren't terminated if one fails * Forgot to include coverlet.collector * Update Directory.Packages.props --------- Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
This commit is contained in:
parent
ed079b9711
commit
1f8ebee742
1 changed files with 251 additions and 140 deletions
71
.github/workflows/code-coverage.yml
vendored
Normal file
71
.github/workflows/code-coverage.yml
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
name: Code Coverage
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
publish-coverage:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: |
|
||||
9.0.x
|
||||
8.0.x
|
||||
|
||||
- name: Download test results
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: testresults-*
|
||||
|
||||
- name: Combine coverage reports
|
||||
uses: danielpalme/ReportGenerator-GitHub-Action@5.4.4
|
||||
with:
|
||||
reports: "**/*.cobertura.xml"
|
||||
targetdir: "${{ github.workspace }}/report"
|
||||
reporttypes: "HtmlSummary;Cobertura;MarkdownSummary;MarkdownSummaryGithub"
|
||||
verbosity: "Info"
|
||||
title: "Code Coverage"
|
||||
tag: "${{ github.run_number }}_${{ github.run_id }}"
|
||||
customSettings: ""
|
||||
toolpath: "reportgeneratortool"
|
||||
|
||||
- name: Upload combined coverage XML
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: coverage
|
||||
path: ${{ github.workspace }}/report
|
||||
retention-days: 7
|
||||
|
||||
- name: Publish code coverage report
|
||||
uses: irongut/CodeCoverageSummary@v1.3.0
|
||||
with:
|
||||
filename: "report/Cobertura.xml"
|
||||
badge: true
|
||||
fail_below_min: true
|
||||
format: markdown
|
||||
hide_branch_rate: false
|
||||
hide_complexity: false
|
||||
indicators: true
|
||||
output: both
|
||||
thresholds: "60 80"
|
||||
|
||||
- name: Upload combined coverage markdown
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: coverage-markdown
|
||||
path: ${{ github.workspace }}/code-coverage-results.md
|
||||
retention-days: 7
|
||||
|
||||
- name: Add Coverage PR Comment
|
||||
uses: marocchino/sticky-pull-request-comment@v2
|
||||
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
|
||||
with:
|
||||
recreate: true
|
||||
path: ${{ github.workspace }}/code-coverage-results.md
|
||||
|
||||
- name: Coverage on step summary
|
||||
if: always()
|
||||
run: cat "${{ github.workspace }}/report/SummaryGithub.md" >> $GITHUB_STEP_SUMMARY
|
||||
Loading…
Reference in a new issue