name: Code Coverage
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
coverage:
name: Generate LLVM code coverage
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
LLVM_PROFILE_FILE: "coverage-%p-%m.profraw"
RUSTFLAGS: "-C instrument-coverage -C link-dead-code"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust nightly
uses: dtolnay/rust-toolchain@nightly
with:
components: llvm-tools-preview
- name: Install grcov
run: cargo install grcov
- name: Install rustfilt (for demangling)
run: cargo install rustfilt
- name: Build and run tests with coverage instrumentation
run: |
cargo test --verbose
- name: Generate coverage report
run: |
mkdir -p coverage
grcov . \
--binary-path ./target/debug/ \
-s . \
-t lcov \
--branch \
--keep-only "src/**" \
-o ./coverage/lcov.info
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v5
with:
files: ./coverage/lcov.info
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Generate HTML report
run: |
grcov . \
--binary-path ./target/debug/ \
-s . \
-t html \
--branch \
--keep-only "src/**" \
-o ./coverage/html
- name: Upload HTML report artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: ./coverage/html/