Home

Awesome

Codacy Coverage Reporter GitHub Action

Codacy Badge

This GitHub Action uploads coverage reports to Codacy on all commits and pull requests, letting you track code coverage on the Codacy UI. After setting it up, you can optionally enable status checks on pull requests to avoid adding untested code or decreasing coverage.

Coverage metrics displayed on Codacy

Codacy is an automated code review tool that makes it easy to ensure your team is writing high-quality code by analyzing more than 40 programming languages such as PHP, JavaScript, Python, Java, and Ruby. Codacy allows you to define your own quality rules, code patterns and quality settings you'd like to enforce to prevent issues on your codebase.

Learn more about Codacy Coverage
Why do you need to measure code coverage?

<br/>

<a href="https://www.codacy.com" target="_blank"><img src="images/codacy-logo.svg" alt="Codacy" width="400"/></a>

<br/>

Uploading coverage to Codacy

Before setting up Codacy Coverage Reporter GitHub Action you must have tests and use tools to generate coverage reports for the source code files in your repository.

To upload coverage to Codacy using the GitHub Action using default settings:

  1. Set up an API token to allow the GitHub Action to authenticate on Codacy:

    ⚠️ Never write API tokens to your configuration files and keep your API tokens well protected, as they grant owner permissions to your projects on Codacy.

  2. Generate a supported code coverage report on each push to your repository.

  3. Add the following to a file .github/workflows/codacy-coverage-reporter.yaml in your repository, where PATH_TO_REPORT is the path to the coverage report:

    name: Codacy Coverage Reporter
    
    on: ["push"]
    
    jobs:
      codacy-coverage-reporter:
        runs-on: ubuntu-latest
        name: codacy-coverage-reporter
        steps:
          - uses: actions/checkout@v2
          - name: Run codacy-coverage-reporter
            uses: codacy/codacy-coverage-reporter-action@v1.3.0
            with:
              project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
              # or
              # api-token: ${{ secrets.CODACY_API_TOKEN }}
              coverage-reports: <PATH_TO_REPORT>
              # or a comma-separated list for multiple reports
              # coverage-reports: <PATH_TO_REPORT>, <PATH_TO_REPORT>
    
  4. Optionally, to add coverage results to GitHub status checks, configure a quality gate for coverage and enable sending status checks on Codacy.

Parameters

The Codacy GitHub Action is a wrapper for running the Codacy Coverage Reporter CLI and supports the following subset of parameters available for the command report:

ParameterDescriptionRecommended value
project-tokenProject API token${{ secrets.CODACY_PROJECT_TOKEN }}
api-tokenAccount API token, an alternative to project-token when setting up multiple repositories${{ secrets.CODACY_API_TOKEN }}
coverage-reportsOptional path or glob pattern to the coverage report relative to the repository root, or a comma-separated list for multiple reports''
languageOptionally associate a language with your coverage report(s)''
force-coverage-parserOptionally force using a specific coverage report parser''
coverage-reporter-versionOptionally force using a specific coverage reporter version''