-
Notifications
You must be signed in to change notification settings - Fork 36
73 lines (60 loc) · 2.07 KB
/
test-coverage.yml
File metadata and controls
73 lines (60 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Test Coverage Check
on:
pull_request:
branches: [ main, master ]
push:
branches: [ main, master ]
env:
CARGO_TERM_COLOR: always
jobs:
test-coverage:
name: Test Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install cargo-tarpaulin
run: cargo install cargo-tarpaulin --version 0.27.0
- name: Run tests with coverage
run: cargo tarpaulin --workspace --all-targets --out Xml --output-dir target/coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: target/coverage/cobertura.xml
flags: unittests
name: utility-drip-contracts
fail_ci_if_error: false
- name: Check coverage threshold
run: |
cargo tarpaulin --workspace --all-targets --out Json --output-dir target/coverage
COVERAGE=$(cat target/coverage/tarpaulin.json | jq -r '.files | map(.coverage) | add / .files | length * 100')
echo "Current coverage: $COVERAGE%"
THRESHOLD=85
if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then
echo "❌ Coverage $COVERAGE% is below threshold $THRESHOLD%"
exit 1
else
echo "✅ Coverage $COVERAGE% meets threshold $THRESHOLD%"
fi
- name: Generate HTML coverage report
run: cargo tarpaulin --workspace --all-targets --out Html --output-dir target/coverage
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: target/coverage/tarpaulin.html
retention-days: 30