Skip to content

Commit 6b3bd8f

Browse files
authored
ci(coverage): add code coverage (#721)
* try coverage * up * only report on x86_64-unknown-linux-musl * up * up * up * Update .github/workflows/ci.yml Signed-off-by: Yuwei Ba <[email protected]> * Update .github/workflows/ci.yml Signed-off-by: Yuwei Ba <[email protected]> * Update .github/workflows/ci.yml Signed-off-by: Yuwei Ba <[email protected]> --------- Signed-off-by: Yuwei Ba <[email protected]> Signed-off-by: Yuwei Ba <[email protected]>
1 parent 5d166c0 commit 6b3bd8f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ jobs:
4444
# Linux x86 gnu
4545
- os: ubuntu-latest
4646
target: x86_64-unknown-linux-gnu
47-
tool: cross
47+
tool: cargo # report code coverage
4848
extra-args: -F "plus"
49+
coverage: true
4950
- os: ubuntu-latest
5051
target: i686-unknown-linux-gnu
5152
tool: cross
@@ -283,13 +284,16 @@ jobs:
283284
env:
284285
CLASH_DOCKER_TEST: "true"
285286

286-
- name: Cargo test (docker test on linux, non BSD)
287+
- name: Install cargo-llvm-cov
288+
uses: taiki-e/install-action@cargo-llvm-cov
289+
290+
- name: Cargo test and coverage (docker test on linux, non BSD)
287291
uses: clechasseur/rs-cargo@v3
288292
if: ${{ startsWith(matrix.os, 'ubuntu') && !contains(matrix.target, 'freebsd') }}
289293
with:
290294
tool: ${{ matrix.tool }}
291-
command: test
292-
args: --workspace --exclude clash_ffi --target ${{ matrix.target }} ${{ matrix.extra-args }}
295+
command: ${{ matrix.coverage && 'llvm-cov' || 'test' }}
296+
args: --workspace --exclude clash_ffi --target ${{ matrix.target }} ${{ matrix.extra-args }} ${{ matrix.coverage && '--codecov --output-path codecov.json' || '' }}
293297
env:
294298
CROSS_CONTAINER_OPTS: "--network host"
295299
CLASH_DOCKER_TEST: "true"
@@ -305,6 +309,14 @@ jobs:
305309
env:
306310
RUSTFLAGS: ${{ matrix.rustflags || '--cfg tokio_unstable' }}
307311

312+
- name: Upload coverage to Codecov
313+
uses: codecov/codecov-action@v5
314+
if: ${{ !cancelled() && matrix.coverage }}
315+
with:
316+
token: ${{ secrets.CODECOV_TOKEN }}
317+
files: codecov.json
318+
fail_ci_if_error: true
319+
308320
- name: Cargo build
309321
uses: clechasseur/rs-cargo@v3
310322
with:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ shell.nix
2525

2626
# macOS
2727
.DS_Store
28+
29+
codecov.json

0 commit comments

Comments
 (0)