Skip to content

Commit a49f440

Browse files
committed
action: add unit test coverage check workflow
1. Introduce `make coverage` to print coverage in console. 2. Github CI use `make coverage-codecov` to get coverage info. Signed-off-by: Qinqi Qu <[email protected]>
1 parent 8671b0a commit a49f440

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

.github/codecov.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
enabled: yes
6+
target: auto # auto compares coverage to the previous base commit
7+
# adjust accordingly based on how flaky your tests are
8+
# this allows a 1% drop from the previous base commit coverage
9+
threshold: 1%
10+
patch:
11+
default:
12+
target: 25% # the required coverage value in each patch
13+
14+
comment:
15+
layout: "reach, diff, flags, files"
16+
behavior: default
17+
require_changes: false # if true: only post the comment if coverage changes
18+
19+
codecov:
20+
require_ci_to_pass: false
21+
notify:
22+
wait_for_ci: false
23+
24+
# When modifying this file, please validate using
25+
# curl -X POST --data-binary @codecov.yml https://codecov.io/validate

.github/workflows/smoke.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ jobs:
141141
run: |
142142
make ut
143143
144+
nydus-unit-test-coverage:
145+
runs-on: ubuntu-latest
146+
env:
147+
CARGO_TERM_COLOR: always
148+
steps:
149+
- uses: actions/checkout@v3
150+
- name: Rust Cache
151+
uses: Swatinem/[email protected]
152+
with:
153+
cache-on-failure: true
154+
- name: Install cargo-llvm-cov
155+
uses: taiki-e/install-action@cargo-llvm-cov
156+
- name: Generate code coverage
157+
run: make coverage-codecov
158+
- name: Upload coverage to Codecov
159+
uses: codecov/codecov-action@v3
160+
with:
161+
files: codecov.json
162+
fail_ci_if_error: true
163+
144164
nydus-cargo-deny:
145165
name: cargo-deny
146166
runs-on: ubuntu-latest

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ INSTALL_DIR_PREFIX ?= "/usr/local/bin"
1515
DOCKER ?= "true"
1616

1717
CARGO ?= $(shell which cargo)
18+
RUSTUP ?= $(shell which rustup)
1819
CARGO_BUILD_GEARS = -v ~/.ssh/id_rsa:/root/.ssh/id_rsa -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry
1920
SUDO = $(shell which sudo)
2021
CARGO_COMMON ?=
@@ -111,6 +112,19 @@ install: release
111112
ut: .release_version
112113
TEST_WORKDIR_PREFIX=$(TEST_WORKDIR_PREFIX) RUST_BACKTRACE=1 ${CARGO} test --workspace $(EXCLUDE_PACKAGES) $(CARGO_COMMON) $(CARGO_BUILD_FLAGS) -- --skip integration --nocapture --test-threads=8
113114

115+
# install test dependencies
116+
pre-coverage:
117+
${CARGO} +stable install cargo-llvm-cov --locked
118+
${RUSTUP} component add llvm-tools-preview
119+
120+
# print unit test coverage to console
121+
coverage: pre-coverage
122+
TEST_WORKDIR_PREFIX=$(TEST_WORKDIR_PREFIX) ${CARGO} llvm-cov --workspace $(EXCLUDE_PACKAGES) $(CARGO_COMMON) $(CARGO_BUILD_FLAGS) -- --skip integration --nocapture --test-threads=8
123+
124+
# write unit teset coverage to codecov.json, used for Github CI
125+
coverage-codecov:
126+
TEST_WORKDIR_PREFIX=$(TEST_WORKDIR_PREFIX) ${CARGO} llvm-cov --codecov --output-path codecov.json --workspace $(EXCLUDE_PACKAGES) $(CARGO_COMMON) $(CARGO_BUILD_FLAGS) -- --skip integration --nocapture --test-threads=8
127+
114128
smoke-only:
115129
make -C smoke test
116130

@@ -214,4 +228,4 @@ docker-example: all-static-release
214228
@docker exec $$cid /run.sh
215229
@EXIT_CODE=$$?
216230
@docker rm -f $$cid
217-
@exit $$EXIT_CODE
231+
@exit $$EXIT_CODE

0 commit comments

Comments
 (0)