From 1f94774a648a7229d49fdbca79bdb260e83198a7 Mon Sep 17 00:00:00 2001 From: Adam Lock Date: Sun, 21 Jul 2024 13:38:03 +0100 Subject: [PATCH] ci: Implement coverage tests #337 --- .github/workflows/ci_code_coverage.yml | 39 ++++++++++++++++++++++++++ .github/workflows/main.yml | 3 ++ 2 files changed, 42 insertions(+) create mode 100644 .github/workflows/ci_code_coverage.yml diff --git a/.github/workflows/ci_code_coverage.yml b/.github/workflows/ci_code_coverage.yml new file mode 100644 index 000000000..278f20cbf --- /dev/null +++ b/.github/workflows/ci_code_coverage.yml @@ -0,0 +1,39 @@ +name: Determine code coverage +'on': + workflow_call: null +jobs: + cov: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Test with profiling data + run: cargo test + env: + CARGO_INCREMENTAL: 0 + LLVM_PROFILE_FILE: 'cargo-test-%p-%m.profraw' + RUSTFLAGS: '-Cinstrument-coverage' + + - name: Install grcov fast + uses: SierraSoftworks/setup-grcov@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + version: latest + + - name: Add llvm-tools-preview + run: rustup component add llvm-tools-preview + + - name: Create lcov output dir + run: | + mkdir target/coverage + + - name: Generate lcov from profiling data + run: grcov . --binary-path ./target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '**/generated/**/*' --ignore '**/integration/**/*' --ignore '**/tests/**/*' --ignore '../*' --ignore "/*" -o target/coverage/tests.lcov + + - name: Upload lcov to codecov.io + uses: codecov/codecov-action@v4 + with: + files: target/coverage/*.lcov + + - name: Wipe stray profiling files + run: find . -type f -name "*.profraw" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 72f3a191a..c03b24759 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,5 +34,8 @@ jobs: - name: Run tests run: cargo test --features test-vendored-openssl --verbose + code-coverage: + uses: ./.github/workflows/ci_code_coverage.yml + verify-code-formatting: uses: ./.github/workflows/ci_format_code.yml