From 3bc9ba90aae65917a4385915dd8349c582dbe1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Cuadrado=20Juan?= Date: Thu, 15 Feb 2024 16:48:27 +0100 Subject: [PATCH] ci: Add codecov support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: VĂ­ctor Cuadrado Juan --- .github/workflows/ci.yml | 36 +++++++++++++++++++++++++++ .gitignore | 3 +++ Makefile | 17 +++++++++++++ coverage/integration-tests/.gitignore | 4 +++ coverage/unit-tests/.gitignore | 4 +++ 5 files changed, 64 insertions(+) create mode 100644 coverage/integration-tests/.gitignore create mode 100644 coverage/unit-tests/.gitignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d0ab436..b59ff032 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,3 +84,39 @@ jobs: with: command: clippy args: -- -D warnings + + coverage: + name: coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 # v4.0.0 + - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7 + with: + profile: minimal + toolchain: stable + override: true + - uses: taiki-e/install-action@5794068c211bc8f5f4514b7c3f03d6adbe66f1b7 # v2.26.18 + with: + tool: cargo-tarpaulin + - name: Generate unit-tests coverage + run: make coverage-unit-tests + - name: Upload unit-tests coverage to Codecov + uses: codecov/codecov-action@e0b68c6749509c5f83f984dd99a76a1c1a231044 # v4.0.1 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} + with: + name: unit-tests + directory: coverage/unit-tests + flags: unit-tests + verbose: true + - name: Generate integration-tests coverage + run: make coverage-integration-tests + - name: Upload unit-tests coverage to Codecov + uses: codecov/codecov-action@e0b68c6749509c5f83f984dd99a76a1c1a231044 # v4.0.1 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} + with: + name: integration-tests + directory: coverage/integration-tests + flags: integration-tests + verbose: true diff --git a/.gitignore b/.gitignore index 316b96e1..0a0b41c5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ bom-cargo.json /bin /registry + +# coverage instrumentation: +*.profraw diff --git a/Makefile b/Makefile index 72bb9e43..57ba28ce 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,23 @@ unit-tests: fmt lint integration-tests: fmt lint cargo test --test '*' +.PHONY: coverage +coverage: coverage-unit-tests coverage-integration-tests + +.PHONY: coverage-unit-tests +coverage-unit-tests: + # integration-tests with llvm need +nightly. Hence, enable +nightly on + # unit-tests, and use --skip-clean to not recompile on CI if not needed + cargo tarpaulin --verbose --skip-clean --engine=llvm \ + --all-features --lib --bin --follow-exec \ + --out xml --out html --output-dir coverage/unit-tests + +.PHONY: coverage-integration-tests +coverage-integration-tests: + cargo tarpaulin --verbose --skip-clean --engine=llvm \ + --all-features --test integration_test --follow-exec \ + --out xml --out html --output-dir coverage/integration-tests + .PHONY: clean clean: cargo clean diff --git a/coverage/integration-tests/.gitignore b/coverage/integration-tests/.gitignore new file mode 100644 index 00000000..5e7d2734 --- /dev/null +++ b/coverage/integration-tests/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/coverage/unit-tests/.gitignore b/coverage/unit-tests/.gitignore new file mode 100644 index 00000000..5e7d2734 --- /dev/null +++ b/coverage/unit-tests/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore