-
Notifications
You must be signed in to change notification settings - Fork 55
90 lines (73 loc) · 2.91 KB
/
coverage-report.yml
File metadata and controls
90 lines (73 loc) · 2.91 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Test Coverage Report
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov
- name: Generate coverage report
run: |
cargo llvm-cov --workspace --lib --bins --tests --all-features --lcov --output-path lcov.info
cargo llvm-cov --workspace --lib --bins --tests --all-features --html
- name: Coverage threshold check
run: |
COVERAGE=$(cargo llvm-cov --workspace --lib --bins --tests --all-features --json | jq -r '.data[0].totals.percent_covered')
echo "📊 Current Coverage: ${COVERAGE}%"
# Set minimum coverage threshold
THRESHOLD=80
if (( $(echo "$COVERAGE >= $THRESHOLD" | bc -l) )); then
echo "✅ Coverage threshold met: ${COVERAGE}% >= ${THRESHOLD}%"
echo "coverage=${COVERAGE}" >> $GITHUB_OUTPUT
else
echo "❌ Coverage threshold NOT met: ${COVERAGE}% < ${THRESHOLD}%"
echo "coverage=${COVERAGE}" >> $GITHUB_OUTPUT
exit 1
fi
id: coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: lcov.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- name: Upload coverage artifacts
uses: actions/upload-artifact@v3
with:
name: coverage-report-${{ github.sha }}
path: target/llvm-cov/html/
retention-days: 30
- name: Coverage comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const coverage = '${{ steps.coverage.outputs.coverage }}';
const threshold = 80;
const comment = `## 📊 Test Coverage Report
**Current Coverage:** ${coverage}%
**Required Threshold:** ${threshold}%
**Status:** ${coverage >= threshold ? '✅ PASS' : '❌ FAIL'}
${coverage >= threshold ?
'Great job! The test coverage meets the minimum requirements.' :
'Test coverage is below the minimum threshold. Please add more tests to improve coverage.'}
---
*This comment was automatically generated by the coverage check workflow.*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});