Skip to content

Latest commit

 

History

History
94 lines (66 loc) · 3.9 KB

README.md

File metadata and controls

94 lines (66 loc) · 3.9 KB

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}}
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
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"

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).