Skip to content

Code Coverage Annotations

Actions

About

Annotate your pull requests to show where test coverage is missing
v1.4.0
Latest
Star (4)

Coverage Status

Build Status

Code Coverage Annotation

Reviewing test coverage information for a whole repository can be overwhelming and hard to take action on. It's much more useful to catch gaps in coverage as they're introduced to a repo, right in the context of pull requests!

All processing is done within Github Actions, no data is sent to an external server.

Sample PR Annotation

Screen Shot 2022-06-26 at 7 11 21 PM

Inputs

Key Required Default Description
GITHUB_TOKEN yes - Github Token generated by Github Action workflow. You can pass this in as ${{secrets.GITHUB_TOKEN}}
GITHUB_BASE_URL no https://api.github.com Base URL for GitHub API. Required for GitHub Enterprise Server or Cloud.
COVERAGE_FILE_PATH yes - Location of coverage file that was generated
COVERAGE_FORMAT no lcov Format of coverage file. May be lcov, clover, or go
FAIL_ON_UNCOVERED_LINES no false Fail the workflow and the check run if any line added in the pull request is not covered by tests
DEBUG no - Log debugging information. Comma-separated list of possible values coverage, pr_lines_added

Usage

Add the action to your workflow file like so, replacing the file path and coverage format with values appropriate for your repo:

- name: Code Coverage Annotation
  uses: ggilder/codecoverage@v1
  with:
    GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
    COVERAGE_FILE_PATH: "./coverage/lcov.info"
    COVERAGE_FORMAT: "lcov"

Blocking pull requests that introduce coverage gaps

By default the action only reports. Set FAIL_ON_UNCOVERED_LINES to fail the step and mark the Annotate check run as failed whenever a line added by the pull request is not covered by tests:

- name: Code Coverage Annotation
  uses: ggilder/codecoverage@v1
  with:
    GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
    COVERAGE_FILE_PATH: "./coverage/lcov.info"
    FAIL_ON_UNCOVERED_LINES: "true"

With the flag enabled, annotations are posted at failure level instead of warning. To actually prevent merging, add the Annotate check run to your branch protection rules as a required status check.

Usage with GitHub Enterprise Server or Cloud

You need to the GITHUB_BASE_URL input to point to your API endpoint to use this action with GitHub Enterprise Server or Cloud. For example:

with:
  GITHUB_BASE_URL: https://github.acme-inc.com/api/v3 # for GitHub Enterprise Server

or

with:
  GITHUB_BASE_URL: https://api.acme-inc.ghe.com # for GitHub Enterprise Cloud

Golang Workflow Example

- name: Run tests with coverage
  run: go test -v ./... -coverprofile coverage.out

- name: Code Coverage Annotation
  uses: ggilder/codecoverage@v1
  with:
    GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
    COVERAGE_FILE_PATH: coverage.out
    COVERAGE_FORMAT: go

Javascript/Typescript

Set up npm run test:cov in your package.json scripts to run jest --coverage, which will output Lcov formatted information to coverage/lcov.info.

Other languages

  • Java/Groovy can use Clover format
  • PHPUnit will output Clover with the --coverage-clover flag
  • C++: GCC Gcov can output Lcov format; this blog post may help you get started.
  • Ruby: Simplecov can output Lcov format when you add the simplecov-lcov gem to your Gemfile. Make sure to set SimpleCov::Formatter::LcovFormatter.config.report_with_single_file to true and provide the path to the output file using COVERAGE_FILE_PATH as described above.

Contributing

First, you'll need to have a reasonably modern version of node handy, ideally 16 or newer. Older versions will change the format of package-lock.json.

Install the dependencies:

$ npm install

Run formatting and linting, build the typescript and package it for distribution, and run tests:

$ npm run all

Make sure you commit the dist/ folder or CI will fail.

Validate

You can validate the action while developing by referencing ./ in a workflow in your repo (see test.yml)

uses: ./
with:
  GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
  COVERAGE_FILE_PATH: "./coverage/lcov.info"

Acknowledgements

This project was originally based on https://github.com/shravan097/codecoverage (which is unmaintained).

Code Coverage Annotations is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Annotate your pull requests to show where test coverage is missing
v1.4.0
Latest

Code Coverage Annotations is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.