Giter VIP home page Giter VIP logo

jacoco-report's Introduction

jacoco-report

Tests

A Github action that publishes the JaCoCo report as a comment in the Pull Request with customizable pass percentage for modified modules, files and the overall project. You can view the coverage of just the changed files in your pull request.

Usage

Pre-requisites

Create a workflow .yml file in your repositories .github/workflows directory. An example workflow is available below. For more information, reference the GitHub Help Documentation for Creating a workflow file.

Inputs

  • paths - [required] Comma separated paths of the generated jacoco xml files (supports wildcard glob pattern)
  • base-sha - [optional {default: automatic detection}] Override commit base-sha instead of using automatic detection. Must be set along with head-sha
  • head-sha - [optional {default: automatic detection}] Override commit head-sha instead of using automatic detection. Must be set along with base-sha
  • pr-number - [optional {default: automatic detection}] Override pr number for issue posting
  • token - [optional {default: github.token }] Github personal token to add commits to Pull Request
  • min-coverage-overall - [optional {default: 80%}] The minimum code coverage that is required to pass for overall project
  • min-coverage-changed-files - [optional {default: 80%}] The minimum code coverage that is required to pass for changed files
  • update-comment - [optional {default: false}] If true, updates the previous coverage report comment instead of creating new one. Requires title to work properly
  • title - [optional] Title for the Pull Request comment
  • skip-if-no-changes - [optional {default: false}] If true, comment won't be added if there is no coverage information present for the files changed
  • pass-emoji - [optional {default: ✔️}] Emoji to use for pass status shown when 'coverage >= min coverage' (should be a Github supported emoji).
  • fail-emoji - [optional {default: ❌}] Emoji to use for fail status shown when 'coverage < min coverage' (should be a Github supported emoji).
  • continue-on-error - [optional {default: true}] If true, then do not fail the action on error, but log a warning
  • summary-mode - [optional {default: false}] If true, report the result to workflow summary
  • debug-mode - [optional {default: false}] If true, run the action in debug mode and get debug logs printed in console

Outputs

  • coverage-overall - The overall coverage of the project
  • coverage-changed-files - The total coverage of all changed files

Example Workflow

name: Measure coverage

on:
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - uses: actions/checkout@v4
      - name: Set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: Run Coverage
        run: |
          chmod +x gradlew
          ./gradlew testCoverage

      - name: Add coverage to PR
        id: jacoco
        uses: mroctopus/jacoco-report@v2
        with:
          paths: |
            ${{ github.workspace }}/**/build/reports/jacoco/prodNormalDebugCoverage/prodNormalDebugCoverage.xml,
            ${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml
          min-coverage-overall: 40
          min-coverage-changed-files: 60

single module screenshot


multi-module screenshot

Example Project

For a working project refer to jacoco-playgound. Check out the PR's in the project to get an idea on how the report is shown on a pull request comment. For multi module gradle project, refer jacoco-android-playground

Example Cases

  1. If you want to fail your workflow when the minimum coverage is not met

    You can write an additional step that uses the Outputs for the jacoco-report action and fail the workflow. Refer sample pull request and its workflow

    - name: Fail PR if overall coverage is less than 80%
      if: ${{ steps.jacoco.outputs.coverage-overall < 80.0 }}
      uses: actions/github-script@v6
      with:
        script: |
          core.setFailed('Overall coverage is less than 80%!')
  2. If you don't want to add the coverage comment everytime you push a commit to a pull request, but update the existing coverage comment instead

    Set the update-comment input to true and also set a title input. Refer sample pull request and its workflow

    - name: Jacoco Report to PR
      id: jacoco
      uses: mroctopus/jacoco-report@v2
      with:
        paths: ${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml
        min-coverage-overall: 40
        min-coverage-changed-files: 60
        title: Code Coverage
        update-comment: true
  3. If you have a multi-module project like android, with multiple modules each with its own jacoco report

    Set the paths input with wildcard glob pattern (as shown in the Example workflow). This will pick all the files matching the pattern. Ensure your pattern matches only one report per module, since for the same module, you could have debugCoverage.xml and releaseCoverage.xml. Refer sample pull request and its workflow

    - name: Jacoco Report to PR
      id: jacoco
      uses: mroctopus/jacoco-report@v2
      with:
        paths: |
          ${{ github.workspace }}/**/build/reports/jacoco/**/prodNormalDebugCoverage.xml,
          ${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml
        min-coverage-overall: 40
        min-coverage-changed-files: 60
  4. When you need to customize the pass/fail emojis or the style of title in the comment

    Set the pass-emoji and fail-emoji to a valid emoji supported in Github. You can add # to choose the style of title from H1 to H6. If you don't choose, the default is H3. Refer sample pull request and its workflow

    - name: Jacoco Report to PR
      id: jacoco
      uses: mroctopus/jacoco-report@v2
      with:
        paths: ${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml
        min-coverage-overall: 40
        min-coverage-changed-files: 60
        title: '# :lobster: Coverage Report'
        pass-emoji: ':green_circle:'
        fail-emoji: ':red_circle:'

Contributing

We welcome contributions, and if you're interested, have a look at the CONTRIBUTING document.

License

The scripts and documentation in this project are released under the MIT License

jacoco-report's People

Contributors

thsaravana avatar mroctopus avatar chris-v avatar mavotto avatar georgespalding avatar imbyungjun avatar sammcj avatar tfij avatar vadgyik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.