diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 00000000000..be29974de12 --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,25 @@ +coverage: + status: + project: + default: + enabled: yes + target: auto # auto compares coverage to the previous base commit + # adjust accordingly based on how flaky your tests are + # this allows a 1% drop from the previous base commit coverage + threshold: 1% + patch: + default: + target: 25% # the required coverage value in each patch + +comment: + layout: "reach, diff, flags, files" + behavior: default + require_changes: false # if true: only post the comment if coverage changes + +codecov: + require_ci_to_pass: false + notify: + wait_for_ci: false + +# When modifying this file, please validate using +# curl -X POST --data-binary @codecov.yml https://codecov.io/validate \ No newline at end of file diff --git a/.github/workflows/smoke.yml b/.github/workflows/smoke.yml index c805ddcdf27..3c174931e0f 100644 --- a/.github/workflows/smoke.yml +++ b/.github/workflows/smoke.yml @@ -141,6 +141,26 @@ jobs: run: | make ut + nydus-unit-test-coverage: + runs-on: ubuntu-latest + env: + CARGO_TERM_COLOR: always + steps: + - uses: actions/checkout@v3 + - name: Rust Cache + uses: Swatinem/rust-cache@v2.2.0 + with: + cache-on-failure: true + - name: Install cargo-llvm-cov + uses: taiki-e/install-action@cargo-llvm-cov + - name: Generate code coverage + run: make coverage-codecov + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + files: codecov.json + fail_ci_if_error: true + nydus-cargo-deny: name: cargo-deny runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index 62c76736356..2e37e561c05 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ INSTALL_DIR_PREFIX ?= "/usr/local/bin" DOCKER ?= "true" CARGO ?= $(shell which cargo) +RUSTUP ?= $(shell which rustup) CARGO_BUILD_GEARS = -v ~/.ssh/id_rsa:/root/.ssh/id_rsa -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry SUDO = $(shell which sudo) CARGO_COMMON ?= @@ -111,6 +112,19 @@ install: release ut: .release_version 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 +# install test dependencies +pre-coverage: + ${CARGO} +stable install cargo-llvm-cov --locked + ${RUSTUP} component add llvm-tools-preview + +# print unit test coverage to console +coverage: pre-coverage + TEST_WORKDIR_PREFIX=$(TEST_WORKDIR_PREFIX) ${CARGO} llvm-cov --workspace $(EXCLUDE_PACKAGES) $(CARGO_COMMON) $(CARGO_BUILD_FLAGS) -- --skip integration --nocapture --test-threads=8 + +# write unit teset coverage to codecov.json, used for Github CI +coverage-codecov: + 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 + smoke-only: make -C smoke test @@ -214,4 +228,4 @@ docker-example: all-static-release @docker exec $$cid /run.sh @EXIT_CODE=$$? @docker rm -f $$cid - @exit $$EXIT_CODE + @exit $$EXIT_CODE \ No newline at end of file