GitHub Action
Code Coverage Annotations
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.
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 |
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"
- 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
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
.
- 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 setSimpleCov::Formatter::LcovFormatter.config.report_with_single_file
totrue
and provide the path to the output file usingCOVERAGE_FILE_PATH
as described above.
First, you'll need to have a reasonably modern version of
node
handy, ideally 16 or newer. Older versions will change the format ofpackage-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.
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"
This project was originally based on https://github.com/shravan097/codecoverage (which is unmaintained).