Upload C++ Coverage to Codecov

Codecov (by Sentry) is a coverage reporting service that integrates with GitHub, GitLab, and Bitbucket. It visualizes code coverage, tracks trends over time, and provides coverage feedback directly on pull requests.

covdbg exports both LCOV and Cobertura XML, and Codecov supports each natively. Generate one from your coverage run and upload it.

Either works. Pick Cobertura, available from covdbg 1.5.0, if you are replacing a tool that already produced Cobertura, because then the collector is the only thing in your pipeline that changes and your coverage history stays comparable. Pick LCOV for a new setup, or if other tools in your pipeline already read it. Every example below uses LCOV; swap --format LCOV for --format COBERTURA and the .lcov file name for .xml to use Cobertura instead.

Set source_root in .covdbg.yaml before you upload. The Cobertura export then names files relative to it, so Codecov matches src/main.cpp against your repository instead of an absolute path from the build agent.

Prerequisites

  1. Create an account at codecov.io
  2. Add your repository to Codecov
  3. Copy your upload token and add it as a repository secret named CODECOV_TOKEN

Basic Usage

For simple projects where all code is exercised through tests, you only need to run tests and upload.

Step 1: Run Tests with Coverage

- name: Run tests with coverage
  run: covdbg --propagate-exit-code --output coverage.covdb --config .covdbg.yaml tests.exe

--propagate-exit-code fails the step when the tests fail. covdbg has written the database by then, so the steps after it carry if: always(): the coverage of a failing run still reaches Codecov, and the job still fails.

Step 2: Convert to LCOV

- name: Convert to LCOV
  if: always()
  run: covdbg convert --input coverage.covdb --format LCOV --output coverage.lcov

Step 3: Upload to Codecov

- name: Upload coverage to Codecov
  if: always()
  uses: codecov/codecov-action@v5
  with:
    files: coverage.lcov
  env:
    CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Advanced Usage

For projects with static libraries, multiple binaries, or code that isn't directly executed by tests, you'll want to include uncovered lines in your report. The analyze command extracts all coverable lines from binaries, ensuring code that was never executed still appears as uncovered (rather than being omitted entirely).

Step 1: Run Tests with Coverage

- name: Run tests with coverage
  run: covdbg --propagate-exit-code --output tests.covdb --config .covdbg.yaml tests.exe

Step 2: Analyze Binaries for Uncovered Code

Extract symbol information from your application binaries. This captures all coverable lines, including code in static libraries that tests may not exercise:

- name: Analyze binaries
  if: always()
  run: |
    covdbg analyze --input app.exe --output app.covdb --config .covdbg.yaml
    covdbg analyze --input app-ui.exe --output app-ui.covdb --config .covdbg.yaml

Step 3: Merge Coverage Databases

Combine the test coverage with the symbol databases:

- name: Merge coverage databases
  if: always()
  run: covdbg merge --input tests.covdb --input app.covdb --input app-ui.covdb --output merged.covdb

Step 4: Convert to LCOV

- name: Convert to LCOV
  if: always()
  run: covdbg convert --input merged.covdb --format LCOV --output coverage.lcov

Step 5: Upload to Codecov

- name: Upload coverage to Codecov
  if: always()
  uses: codecov/codecov-action@v5
  with:
    files: coverage.lcov
  env:
    CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

What You Get

Once configured, Codecov provides coverage feedback on every pull request, tracks how coverage changes over time, and offers a dashboard to explore coverage at the file and line level. Visit codecov.io to configure thresholds, notifications, and other project settings.