Generate code coverage reports for a C++ project on GitHub Actions using gcovr.
- Generate code coverage reports using gcovr.
- Generate and send reports in Coveralls API format.
- Auto detect and install required dependencies.
- Support coverage report on GCC and LLVM Clang.
- Support files exclusion and fail if coverage is below a specific thresold.
For more information, see action.yml and GitHub Actions guide.
Name | Value Type | Description |
---|---|---|
root |
Path | Root directory of your source files. Defaults to current directory. File names are reported relative to this directory. |
gcov-executable |
Executable name with optional arguments | Use a particular gcov executable. Must match the compiler you are using, e.g. llvm-cov gcov for LLVM Clang. See this. |
excludes |
One or more regular expression | Exclude source files that match these filters. |
fail-under-line |
0 - 100 | Fail if the total line coverage is less than this value. |
fail-under-branch |
0 - 100 | Fail if the total branch coverage is less than this value. |
fail-under-function |
0 - 100 | Fail if the total function coverage is less than this value. |
html-out |
Path | Output file of the generated HTML coverage report. |
html-theme |
green , blue , github.blue , github.green , github.dark-green , github.dark-blue |
Override the default color theme for the HTML report. |
xml-out |
Path | Output file of the generated XML coverage report. |
coveralls-out |
Path | Output file of the generated Coveralls API coverage report. |
coveralls-send |
true or false |
Send the generated Coveralls API coverage report to it's endpoint. Defaults to false . |
github-token |
Token | GitHub token of your project. Defaults to github.token . Required for sending Coveralls API coverage report successfully. |
working-directory |
Path | Working directory where gcovr should be executed from. |
Note: All inputs are optional.
name: test
on:
push:
jobs:
test-coverage:
runs-on: ubuntu-22.04
steps:
- name: Check out this repository
uses: actions/[email protected]
- name: Build and test this project
run: |
cmake . -B build
cmake --build build
ctest --test-dir build
- name: Generate a code coverage report
uses: threeal/[email protected]
- name: Generate a code coverage report
uses: threeal/[email protected]
with:
excludes: |
include/internal/*
src/internal/*
- name: Generate a html code coverage report
uses: threeal/gcovr-action@xml-out
with:
html-out: coverage.html
- name: Generate a html code coverage report
uses: threeal/gcovr-action@xml-out
with:
html-out: coverage.html
html-theme: github.green
- name: Generate a code coverage report
uses: threeal/gcovr-action@xml-out
with:
xml-out: coverage.xml
- name: Build and test this project
run: |
cmake . -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
cmake --build build
ctest --test-dir build
- name: Generate a code coverage report
uses: threeal/[email protected]
with:
gcov-executable: llvm-cov gcov
- name: Generate and send a code coverage report to Coveralls
uses: threeal/[email protected]
with:
coveralls-send: true
github-token: ${{ secrets.GITHUB_TOKEN }}
Note that working-directory
and root
will almost always be used together, in which case root
is evaluated relative to the specified working directory. In other words it is passed directly through as an argument to gcovr
.
- name: Generate a code coverage report
uses: threeal/[email protected]
with:
working-directory: build
root: ../
This project is licensed under the terms of the MIT License.
Copyright © 2022-2024 Alfi Maulana