grcov
grcov copied to clipboard
📈 GitHub Action for code coverage reporting with grcov
grcov Action
This GitHub Action collects and aggregates code coverage data with the grcov tool.
Example workflow
on: [push]
name: Code Coverage
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --no-fail-fast
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
- uses: actions-rs/[email protected]
Usage
-
As
grcovworks with coverage data generated by the unstable-Z profilefeature, you need to installnightlytoolchain, for example, with theactions-rs/toolchainAction:- uses: actions-rs/toolchain@v1 with: toolchain: nightly override: true -
It is strongly recommended to call
cargo cleancommand if any ofcargo check,cargo build,cargo testor other similar commands were executed already in this workspace.- uses: actions-rs/cargo@v1 with: command: clean -
Create a configuration file for
grcov, see config section for details. -
Execute the
cargo testcommand. It is required to addCARGO_INCREMENTAL,RUSTFLAGSandRUSTDOCFLAGSenvironment variables for this command, see grcov page for details.- uses: actions-rs/cargo@v1 with: command: test args: --all-features --no-fail-fast # Customize args for your own needs env: CARGO_INCREMENTAL: '0' RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'Note that
-Clink-dead-codeflag might be broken for macOS environments, see #63047 -
Add the
actions-rs@grcovAction to the workflow.- id: coverage uses: actions-rs/[email protected] -
After the successful execution,
actions-rs@grcovwill set an Action output calledreportwith an absolute path to the coverage report file.This file can be uploaded to any code coverage service, ex. with codecov or coveralls Actions help:
- name: Coveralls upload uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: ${{ steps.coverage.outputs.report }}
Inputs
config: Configuration file path (relative to repository root, default to.github/actions-rs/grcov.yml)
Outputs
report: Absolute path to the report file
Config
grcov execution can be tuned with the configuration file.
By default this Action tries to load it from the .github/actions-rs/grcov.yml path
(relative to the repository root directory); you can change file location with the config input, ex.
- uses: actions-rs/[email protected]
with:
config: configs/grcov.yml
If configuration file is missing, default values will be used by the grcov.
All possible keys in the config are optional and directly mapped
to the grcov flags and options.
Note that not all parameters can be changed via this file, see example below
for config file format and available options.
Example
branch: true
ignore-not-existing: true
llvm: true
filter: covered
output-type: lcov
output-path: ./lcov.info
prefix-dir: /home/user/build/
ignore:
- "/*"
- "C:/*"
- "../*"
path-mapping:
- "/path1"
- "/path2"
Notes
-
Coveralls Action is expecting
LCOVformat, do not use thecoverallsorcoveralls+output type for thegrcov.
Instead, set theoutput-typeconfig value tolcov. -
Generated report file is stored in the temporary directory by default, which might not be accessible by the Docker-based Actions, such as codecov.
Consider either mount it as a Docker volume or use theoutput-pathoption in the config to store report in the path accessible by container.