PavanMudigonda / jacoco-reporter

GitHub Action to Publish JaCoCo Format Code Coverage XML and attach it to the Workflow Run as a Check Run. Also can enforce Coverage Quality Gate.
https://linkedin.com/in/PavanMudigonda
MIT License
76 stars 7 forks source link
actions coverage github-actions quality test testing

JaCoCo Code Coverage Reporter v5.0

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.

Note:-

Just one request. If you are using my Github Action, please STAR ⭐ it.

Samples

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/jacoco-reporter@v5.0
        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 Jacocoo report to workflow run summary
        run: |
          echo "| Outcome | Value |" >> $GITHUB_STEP_SUMMARY
          echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY
          echo "| Code Coverage % | ${{ steps.jacoco_reporter.outputs.coverage_percentage }} |" >> $GITHUB_STEP_SUMMARY
          echo "| :heavy_check_mark: Number of Lines Covered | ${{ steps.jacoco_reporter.outputs.covered_lines }} |" >> $GITHUB_STEP_SUMMARY
          echo "| :x: Number of Lines Missed | ${{ steps.jacoco_reporter.outputs.missed_lines }} |" >> $GITHUB_STEP_SUMMARY
          echo "| Total Number of Lines | ${{ steps.jacoco_reporter.outputs.total_lines }} |" >> $GITHUB_STEP_SUMMARY

      # uploads the coverage-report.md artifact  # Optional
     - name: Upload Code Coverage Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: code-coverage-report-markdown
          path: */coverage-results.md 
          retention-days: 1  

Inputs

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 false Input the GITHUB TOKEN Or Personal Access Token you would like to use. Defaults to the auto generated token. 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

Outputs

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

Important Notes:-

Sample Screenshot (Full Coverage Report): publish_only_summary: false

image

Sample Screenshot (Summary Coverage Report): publish_only_summary: true

image

Sample Build Summary Screenshot

image

Sample PR Check Screenshot: only one Code Coverage Check Appears.

image

Sample Gradle Build Repo

https://github.com/PavanMudigonda/jacoco-playground

Sample Gradle Github Actions workflow

https://github.com/PavanMudigonda/jacoco-playground/blob/main/.github/workflows/coverage.yml

Sample Maven Build Repo

https://github.com/PavanMudigonda/java-maven-playground/

Sample Maven Github Actions workflow

https://github.com/PavanMudigonda/java-maven-playground/blob/master/.github/workflows/ci.yml

Sample Ant Build Repo

Sample Ant Github Actions workflow

PowerShell GitHub Action

This Action is implemented as a PowerShell GitHub Action.

Please checkout my Lines of Code Reporter

https://github.com/PavanMudigonda/lines-of-code-reporter/