Skip to content

Check test coverage and generate reports for C/C++ projects using gcovr on GitHub Actions.

License

Notifications You must be signed in to change notification settings

threeal/gcovr-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Gcovr Action

Check test coverage and generate reports for C/C++ projects using gcovr on GitHub Actions.

Key Features

  • Check test coverage for C/C++ projects compiled with GCC and LLVM Clang.
  • Generate test coverage reports in HTML, Cobertura, and Coveralls formats.
  • Support file exclusion and fail if coverage is below a specific threshold.
  • Support sending reports directly to Coveralls.
  • Automatically install and cache the gcovr program on GitHub Actions.

Available Inputs

The following table lists all available inputs supported by this action. Please note that these inputs are optional.

Name Value Type Description
root Path Root directory of your source files. Defaults to the current directory. File names are reported relative to this directory.
gcov-executable Executable name with optional arguments Use a specific gcov executable. It must match the compiler you are using, e.g., llvm-cov gcov for LLVM Clang.
excludes One or more regular expression patterns 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 for the generated HTML report.
html-details true or false Enable to add annotated source code reports to the HTML report. Defaults to false.
html-theme String Override the default color theme for the HTML report.
html-title String Override the default title for the HTML report.
xml-out Path Output file for the generated Cobertura report.
coveralls-out Path Output file for the generated Coveralls report.
coveralls-send true or false Send the generated Coveralls report to its endpoint. Defaults to false.
github-token Token GitHub token for your project. Defaults to github.token. Required for successfully sending the Coveralls report to its endpoint.
working-directory Path The working directory where gcovr should be executed.

Example Usages

This example demonstrates how to use this action to check test coverage of a C/C++ project on GitHub Actions. By default, if no other inputs are given, this action will print the test coverage report to the log.

name: test
on:
  push:
jobs:
  test-project:
    runs-on: ubuntu-24.04
    steps:
      - name: Checkout Project
        uses: actions/[email protected]

      - name: Build Project
        uses: threeal/[email protected]

      - name: Test Project
        uses: threeal/[email protected]

      - name: Check Test Coverage
        uses: threeal/[email protected]

Specify Test Coverage Threshold

To specify the minimum required test coverage threshold, set the fail-under-line, fail-under-branch, and/or fail-under-function inputs with a number ranging from 0-100 indicating the percentage of the threshold. For example, the following will check and assert if the test line coverage is above 80%:

- name: Check Test Coverage
  uses: threeal/[email protected]
  with:
    fail-under-line: 80

Generate HTML Report

Specify the html-out input to generate the test coverage report in HTML format:

- name: Generate HTML Report
  uses: threeal/[email protected]
  with:
    html-out: coverage.html

Other options are also available to customize the generated HTML output:

- name: Generate HTML Report
  uses: threeal/[email protected]
  with:
    html-out: coverage.html
    html-details: true
    html-title: My Project Test Coverage Report
    html-theme: github.green

Generate Cobertura Report

Specify the xml-out input to generate the test coverage report in Cobertura format:

- name: Generate Cobertura Report
  uses: threeal/[email protected]
  with:
    xml-out: cobertura.xml

Generate Coveralls Report

Specify the coveralls-out input to generate the test coverage report in Coveralls format:

- name: Generate Coveralls Report
  uses: threeal/[email protected]
  with:
    coveralls-out: coveralls.json

Rather than outputting the report as a file, it can also be directly sent to Coveralls by setting the coveralls-send input to true:

- name: Send Coveralls Report
  uses: threeal/[email protected]
  with:
    coveralls-send: true

Using LLVM Clang

By default, gcovr works well with projects compiled using GCC. However, for projects compiled using LLVM Clang, the gcov-executable input must correctly specify the gcov program that works with that compiler. See this for more details.

- name: Check Test Coverage
  uses: threeal/[email protected]
  with:
    gcov-executable: llvm-cov gcov

License

This project is licensed under the terms of the MIT License.

Copyright © 2022-2024 Alfi Maulana