From 77a498441f87abf0e825d93dfab313aeb2707654 Mon Sep 17 00:00:00 2001 From: Mauro Ezequiel Moltrasio Date: Mon, 1 Jun 2026 12:14:27 +0200 Subject: [PATCH 1/2] feat: add code coverage with cargo-llvm-cov and Codecov upload Add a coverage job to CI that instruments unit tests with cargo-llvm-cov, generates a Codecov-compatible JSON report, and uploads it via the codecov/codecov-action. A `make coverage` target is provided for local use. Assisted-by: Claude Code (claude-opus-4-6) --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++++++++++ .gitignore | 1 + CHANGELOG.md | 2 ++ Makefile | 6 +++++- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73b4f247..6eda3fb6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,6 +61,44 @@ jobs: run: cargo +${{ matrix.rust-version }} test + coverage: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + libbpf-dev \ + protobuf-compiler + + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-${{ runner.arch }}-cargo-coverage-${{ hashFiles('**/Cargo.lock') }} + + - name: Install cargo-llvm-cov + run: | + rustup component add llvm-tools-preview + cargo install cargo-llvm-cov + + - name: Generate coverage + run: make coverage + + - name: Upload to Codecov + uses: codecov/codecov-action@v5 + with: + files: codecov.json + token: ${{ secrets.CODECOV_TOKEN }} + format-check: runs-on: ubuntu-24.04 env: diff --git a/.gitignore b/.gitignore index dc478a1e..29fe02fc 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ internalapi/ results.xml logs/ THIRD_PARTY_LICENSES.html +codecov.json # clangd and compilation database .cache/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 86bcf5fe..76be7c95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ possible include a PR number for easier tracking. ## Next +* feat: add code coverage with cargo-llvm-cov and Codecov upload (#745) + ## 0.3.0 * ROX-34663: Migrate from ubi-minimal to ubi-micro (#653) diff --git a/Makefile b/Makefile index 55f58098..85fdd936 100644 --- a/Makefile +++ b/Makefile @@ -32,9 +32,13 @@ integration-tests: performance-tests: make -C performance-tests +coverage: + cargo llvm-cov --workspace --codecov --output-path codecov.json + clean: make -C tests clean rm -f THIRD_PARTY_LICENSES.html + rm -f codecov.json format-check: cargo fmt --check @@ -44,4 +48,4 @@ format: cargo fmt make -C fact-ebpf format -.PHONY: tag mock-server integration-tests image image-name licenses clean +.PHONY: tag mock-server integration-tests image image-name licenses coverage clean From 66cb2e43a0d82828a8a6476839740bc115e77d6a Mon Sep 17 00:00:00 2001 From: Mauro Ezequiel Moltrasio Date: Tue, 2 Jun 2026 10:56:29 +0200 Subject: [PATCH 2/2] Remove unneeded cargo-llvm-cov installation --- .github/workflows/ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6eda3fb6..e39b453b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,11 +85,6 @@ jobs: target/ key: ${{ runner.os }}-${{ runner.arch }}-cargo-coverage-${{ hashFiles('**/Cargo.lock') }} - - name: Install cargo-llvm-cov - run: | - rustup component add llvm-tools-preview - cargo install cargo-llvm-cov - - name: Generate coverage run: make coverage