Skip to content

Commit dbab386

Browse files
committed
Compute coverage in CI
fixes #5
1 parent 022ab6b commit dbab386

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

.github/workflows/ci.yml

+49
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,55 @@ jobs:
9090

9191
- run: cargo check ${{ matrix.RUST.FLAGS }}
9292

93+
coverage:
94+
runs-on: ubuntu-latest
95+
steps:
96+
- uses: actions/checkout@v3
97+
with:
98+
persist-credentials: false
99+
100+
- uses: dtolnay/rust-toolchain@1ce4a7352a1efe5dede2e52c75512b34256e4f44
101+
with:
102+
toolchain: nightly
103+
components: llvm-tools-preview
104+
105+
- run: sudo apt-get install -y lcov
106+
107+
- uses: actions/cache@v3
108+
id: cargo-cache
109+
with:
110+
path: |
111+
~/.cargo/bin/
112+
~/.cargo/registry/index/
113+
~/.cargo/registry/cache/
114+
~/.cargo/git/db/
115+
target/
116+
key: ${{ runner.os }}-cargo-4-${{ hashFiles('**/Cargo.toml') }}
117+
118+
- run: cargo install cargo-binutils
119+
if: steps.cargo-cache.outputs.cache-hit != 'true'
120+
121+
- run: cargo test
122+
env:
123+
RUSTFLAGS: "-Cinstrument-coverage"
124+
LLVM_PROFILE_FILE: "rust-cov/cov-%m-%p.profraw"
125+
126+
- run: |
127+
set -xe
128+
cargo profdata -- merge -sparse rust-cov/*.profraw -o cargo-test-rust-cov.profdata
129+
cargo cov -- export \
130+
$(env RUSTFLAGS="-Cinstrument-coverage" cargo test --tests --no-run --message-format=json | jq -r "select(.profile.test == true) | .filenames[]") \
131+
-instr-profile=cargo-test-rust-cov.profdata \
132+
--ignore-filename-regex='/.cargo/registry' \
133+
--ignore-filename-regex='/rustc/' \
134+
--ignore-filename-regex='/.rustup/toolchains/' --format=lcov > cargo-test.lcov
135+
136+
genhtml cargo-test.lcov -o coverage-html
137+
- uses: actions/[email protected]
138+
with:
139+
name: coverage-html
140+
path: coverage-html
141+
93142
fuzz:
94143
runs-on: ubuntu-latest
95144
strategy:

0 commit comments

Comments
 (0)