77name : Codecov
88
99jobs :
10- test :
11- name : Test
12- env :
13- RUSTFLAGS : -C instrument-coverage
10+ test-and-coverage :
1411 runs-on : ubuntu-latest
12+ env :
13+ CARGO_INCREMENTAL : 0
14+ RUSTFLAGS : " -C instrument-coverage"
15+ LLVM_PROFILE_FILE : " coverage-%p-%m.profraw"
16+
1517 steps :
16- - name : Checkout repository
17- uses : actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 # Version 4.2.2
18- - name : Add llvm-tools-preview component
19- run : rustup component add llvm-tools-preview
20- - name : Build required binaries
21- uses : actions-rs/cargo@9e120dd99b0fbad1c065f686657e914e76bd7b72 # Version 1.0.1
18+ # 1️⃣ Checkout the repo
19+ - name : Checkout code
20+ uses : actions/checkout@v4
21+
22+ # 2️⃣ Install Rust toolchain (nightly required for coverage)
23+ - name : Set up Rust
24+ uses : dtolnay/rust-toolchain@stable
2225 with :
23- command : build
24- args : --all-features
25- - uses : actions-rs/cargo@v1
26- continue-on-error : true
27- - name : Install cargo-binstall
28- run : cargo install cargo-binstall
29- - name : Run Grcov
30- run : |
31- rm -rf /tmp/cov;
32- cargo binstall -y grcov;
33- mkdir /tmp/cov;
34- grcov . --binary-path ./target/debug -s . -t lcov --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o /tmp/cov/tests.lcov;
35- - uses : codecov/codecov-action@v3
26+ toolchain : nightly
27+ components : llvm-tools-preview
28+
29+ # 3️⃣ Cache build artifacts for faster CI
30+ - name : Cache cargo build
31+ uses : actions/cache@v4
3632 with :
37- token : ${{ secrets.CODECOV_TOKEN }}
38- directory : /tmp/cov/
39- name : waku-bindings-codecov
40- fail_ci_if_error : true
33+ path : |
34+ ~/.cargo/registry
35+ ~/.cargo/git
36+ target
37+ key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
4138
39+ # 4️⃣ Build and test with coverage instrumentation
40+ - name : Run tests
41+ run : |
42+ cargo build --all-features
43+ cargo test --all-features
44+
45+ # 5️⃣ Install grcov
46+ - name : Install grcov
47+ run : cargo install grcov
48+
49+ # 6️⃣ Generate lcov report
50+ - name : Generate coverage report
51+ run : |
52+ mkdir -p coverage
53+ grcov . \
54+ --binary-path ./target/debug/ \
55+ -s . \
56+ -t lcov \
57+ --branch \
58+ --ignore-not-existing \
59+ --ignore '../*' \
60+ --ignore "/*" \
61+ -o coverage/tests.lcov
4262
63+ # 7️⃣ Upload to Codecov
64+ - name : Upload coverage to Codecov
65+ uses : codecov/codecov-action@v4
66+ with :
67+ token : ${{ secrets.CODECOV_TOKEN }} # only needed for private repos
68+ files : coverage/tests.lcov
69+ fail_ci_if_error : true
70+ flags : unittests
71+ name : rust-codecov
0 commit comments