diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 680b88a4..5ae011d0 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,6 +8,7 @@ on: env: CARGO_TERM_COLOR: always + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} jobs: skip_check: @@ -30,7 +31,12 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose + run: make test + - name: Upload coverage reports to Codecov + run: | + curl -o target/test_coverage/codecov -Os https://uploader.codecov.io/latest/linux/codecov + chmod +x target/test_coverage/codecov + ./target/test_coverage/codecov -t ${CODECOV_TOKEN} clippy_check: needs: [skip_check] diff --git a/Makefile b/Makefile index 26747673..828e6c66 100644 --- a/Makefile +++ b/Makefile @@ -8,4 +8,24 @@ build: cargo build maturin develop -.PHONY: precommit build +test: + # clean test coverage directory + rm -rf ./target/test_coverage + mkdir -p ./target/test_coverage + + # install dependencies + rustup component add llvm-tools-preview + curl -sL https://github.com/mozilla/grcov/releases/download/v0.8.10/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf - -C "./target/test_coverage" + chmod +x ./target/test_coverage/grcov + + # run tests + CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='target/test_coverage/profraw/cargo-test-%p-%m.profraw' cargo test --verbose + + # generate html coverage report + ./target/test_coverage/grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/test_coverage/html + + # generate lcov coverage report + ./target/test_coverage/grcov . --binary-path ./target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/test_coverage/tests.lcov + + +.PHONY: precommit build test