-
Notifications
You must be signed in to change notification settings - Fork 0
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
GitHub Actions: Publish Code Coverage Summary to Pull Requests | josh-ops #11
Comments
Note that the irongut/codecoveragesummary only works on linux builds. |
@ardalis that is a great point, because it is a Docker action. I have definitely been preferring non-Docker actions over Docker because they're typically a little faster, and of course run on non-linux machines (and do not require Docker configured on self-hosted machines!). Perhaps try the 5monkeys/cobertura-action action as an alternative; this is a node-based action so it will run on Windows/Mac. Here's an example of this in practice. |
Thanks, I'm fine with using an ubuntu agent for most of my repos, I just added the comment to save others some time. Cheers. |
FYI when I run this: I get: 0s |
@ardalis thanks for the build link! Ahh - it looks like you have multiple unit test projects so it's creating two
I believe you would want to use the ReportGenerator action to combine the cobertura files and then upload the combined code coverage result. You might have to play with it a bit, but something like this: - name: Test
run: dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage" --logger trx --results-directory coverage
- name: Copy Coverage To Predictable Location
run: cp coverage/*/coverage.cobertura.xml coverage/coverage.cobertura.xml
- name: ReportGenerator
uses: danielpalme/[email protected]
with:
reports: 'coverage/*/coverage.cobertura.xml' # REQUIRED # The coverage reports that should be parsed (separated by semicolon). Globbing is supported.
targetdir: 'coveragereport' # REQUIRED # The directory where the generated report should be saved.
reporttypes: 'HtmlInline;Cobertura' # The output formats and scope (separated by semicolon)
- name: Code Coverage Summary Report
uses: irongut/[email protected]
with:
filename: coveragereport/coverage.cobertura.xml # double check path with targetdir parameter above
badge: true
format: 'markdown'
output: 'both' Let me know how that works! |
The While the report generator syntax is easy to figure out, which way would be best to add it to PR/Job summary? |
@dozer75 oh you're right! I totally missed changing those variables when translating that to a run command. Here's what it should be: - name: Create code coverage report
run: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:coverage/*/coverage.cobertura.xml -targetdir:CodeCoverage -reporttypes:'Cobertura' In this post, the Now to generate a markdown report and upload to the GitHub job summary, this is what you would use: - name: Create code coverage report
run: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:coverage/*/coverage.cobertura.xml -targetdir:CodeCoverage -reporttypes:'MarkdownSummaryGithub,Cobertura'
- name: Write to Job Summary
run: cat CodeCoverage/SummaryGithub.md >> $GITHUB_STEP_SUMMARY Adding in The ReportGenerator site is really helpful for creating the command 😄 This is a comparison between using the irongut/CodeCoverageSummary action (top) and reportgenerator (bottom): ![]() You can see the entire build workflow here. If you wanted to post this as a PR comment instead of the job summary, then simply use the marocchino/sticky-pull-request-comment action as shown in the post 😄. Hope this helps! I updated the post to reflect all of this, and simplified a few other areas as well (like removing the |
Thanks! :) |
GitHub Actions: Publish Code Coverage Summary to Pull Requests | josh-ops
Using GitHub Actions to add a code coverage summary report comment to a pull request
https://josh-ops.com/posts/github-code-coverage/
The text was updated successfully, but these errors were encountered: