GitHub Action to Publish JaCoCo Format Code Coverage XML and attach it to the Workflow Run as a Check Run. You can even set threshold coverage percentage and fail the action.
- The scope of this project is limited to Report and Quality Gate. Any ideas are welcome.
- I wrote this action as opensource during my vacation time.
- This actions is used by hundreds of repos in my organization and many other prviate org repos.
This Action allows you to specify your JaCoCo Code Coverage XML Path, and then generate a markdown report from the test results and then it attaches it to the Workflow Run as a Check Run. You can even set threshold coverage percentage and fail the action.
Here's a quick example of how to use this action in your own GitHub Workflows.
jobs:
test:
runs-on: ubuntu-latest
steps:
# generates coverage-report.md and publishes as checkrun
- name: JaCoCo Code Coverage Report
id: jacoco_reporter
uses: PavanMudigonda/[email protected]
with:
coverage_results_path: jacoco-report/test.xml
coverage_report_name: Coverage
coverage_report_title: JaCoCo
github_token: ${{ secrets.GITHUB_TOKEN }}
skip_check_run: false
minimum_coverage: 80
fail_below_threshold: false
publish_only_summary: false
# Publish Coverage Job Summary # Optional
- name: Add Coverage Job Summary
run: echo "${{ steps.jacoco_reporter.outputs.coverageSummary }}" >> $GITHUB_STEP_SUMMARY
# uploads the coverage-report.md artifact # Optional
- name: Upload Code Coverage Artifacts
uses: actions/upload-artifact@v2
with:
name: code-coverage-report-markdown
path: */coverage-results.md
retention-days: 1
This Action defines the following formal inputs.
Name | Req | Description |
---|---|---|
coverage_results_path |
true | Path to the JaCoCo Code Coverage XML format file which will be used to generate a report. |
coverage_report_name |
false | The name of the code coverage report object that will be attached to the Workflow Run. Defaults to the name COVERAGE_RESULTS_<datetime> where <datetime> is in the form yyyyMMdd_hhmmss . |
coverage_report_title |
false | The title of the code coverage report that will be embedded in the report itself, which defaults to the same as the coverage_report_name input. |
github_token |
true | Input the GITHUB TOKEN Or Personal Access Token you would like to use. Recommended to use GitHub auto generated token ${{ secrets.GITHUB_TOKEN }} |
minimum_coverage |
false | Input the minimum code coverage recommended. |
fail_below_threshold |
false | Set True to fail the action and False to let it pass. |
skip_check_run |
false | If true, will skip attaching the Coverage Result report to the Workflow Run using a Check Run. Useful if your report has 65k characters that is not accepted by Github REST and GraphQL APIs |
publish_only_summary |
false | If true, will publish only a summary table of the Coverage Result report to the Workflow Run using a Check Run. Useful if your full coverage report has 65k characters that is not accepted by Github REST and GraphQL APIs |
This Action defines the following formal outputs.
Name | Description |
---|---|
coverage_percentage |
Coverage Percentage. Rounded to two decimals. |
coveragePercentage |
Coverage Percentage. Rounded to two decimals. |
coveragePercentageString |
Coverage Percentage. Rounded to two decimals with % symbol attached. |
covered_lines |
Total Covered Lines |
missed_lines |
Total missed Lines |
total_lines |
Total Code Lines |
coverageSummary |
code coverage summary data mardown variable. Use this variable to append to $GITHUB_STEP_SUMMARY to publish summary. |
- When action is run in a pull request by dependabot or a forked repo (e.g. when bumping up a version in a pull request) this step will fail with the default github token ${{ secrets.GITHUB_TOKEN }} due to a lack of permissions. Resolution: on consumer side of workflow please add below
Possible fix
The workflow needs check: write
permissions.
permissions:
checks: write
- Or Alternatively use Personal Authorization Token from GitHub.
https://github.com/PavanMudigonda/jacoco-playground
https://github.com/PavanMudigonda/jacoco-playground/blob/main/.github/workflows/coverage.yml
https://github.com/PavanMudigonda/java-maven-playground/
https://github.com/PavanMudigonda/java-maven-playground/blob/master/.github/workflows/ci.yml
This Action is implemented as a PowerShell GitHub Action.