-
Notifications
You must be signed in to change notification settings - Fork 1
129 lines (115 loc) · 4.09 KB
/
Copy pathcoverage.yml
File metadata and controls
129 lines (115 loc) · 4.09 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
name: Code Coverage
"on":
pull_request:
# schedule:
# - cron: '0 0 * * 1' # Weekly on Monday
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
coverage:
name: Generate Coverage Report
runs-on: ubuntu-latest
environment: copilot
timeout-minutes: 30
steps:
- name: Checkout code
# yamllint disable-line rule:line-length
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Rust with caching
uses: ./.github/actions/setup-rust-cached
with:
toolchain: stable
components: llvm-tools-preview
cache-key: coverage
- name: Install cargo-llvm-cov
# yamllint disable-line rule:line-length
uses: ./.github/actions/install-cargo-tool
with:
tool: cargo-llvm-cov@0.6.14
- name: Generate coverage
run: |
cargo llvm-cov --all-features --workspace \
--lcov --output-path lcov.info
cargo llvm-cov --all-features --workspace \
--html --output-dir coverage-html
cargo llvm-cov --all-features --workspace \
--json --output-path coverage.json
- name: Parse coverage percentage
id: coverage
run: |
COVERAGE=$(cargo llvm-cov \
--all-features --workspace --summary-only \
| grep -oP 'TOTAL\s+\d+\.\d+%' \
| grep -oP '\d+\.\d+' || echo "0")
echo "percentage=$COVERAGE" >> "$GITHUB_OUTPUT"
echo "Coverage: ${COVERAGE}%"
- name: Generate coverage report
env:
PERCENTAGE: ${{ steps.coverage.outputs.percentage }}
run: |
echo "# Code Coverage Report" > coverage-report.md
echo "" >> coverage-report.md
echo "**Overall Coverage:** ${PERCENTAGE}%" \
>> coverage-report.md
echo "" >> coverage-report.md
echo "## Summary" >> coverage-report.md
echo "" >> coverage-report.md
echo "\`\`\`" >> coverage-report.md
cargo llvm-cov --all-features --workspace \
--summary-only >> coverage-report.md
echo "\`\`\`" >> coverage-report.md
echo "" >> coverage-report.md
echo "Full HTML report available in CI artifacts." \
>> coverage-report.md
- name: Upload coverage to Codecov
# yamllint disable-line rule:line-length
uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad # v5.1.2
with:
files: lcov.info
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage artifacts
# yamllint disable-line rule:line-length
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: coverage-report
path: |
coverage-report.md
coverage-html/
lcov.info
coverage.json
retention-days: 30
- name: Comment PR with coverage
if: github.event_name == 'pull_request'
# yamllint disable-line rule:line-length
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const fs = require('fs');
const report = fs.readFileSync(
'coverage-report.md', 'utf8'
);
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: report
});
- name: Check coverage threshold
env:
COVERAGE: ${{ steps.coverage.outputs.percentage }}
run: |
THRESHOLD=80
if (( $(echo "$COVERAGE < $THRESHOLD" \
| bc -l) )); then
echo "Coverage ${COVERAGE}% is below ${THRESHOLD}%"
echo "Consider adding more tests."
else
echo "Coverage ${COVERAGE}% meets ${THRESHOLD}%"
fi