-
Notifications
You must be signed in to change notification settings - Fork 2
310 lines (274 loc) · 9.96 KB
/
Copy pathcoverage.yml
File metadata and controls
310 lines (274 loc) · 9.96 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
name: Coverage
on:
push:
branches: ["main"]
paths:
- "crates/**"
- "xtask/**"
- "Cargo.toml"
- "Cargo.lock"
- ".github/workflows/coverage.yml"
- "codecov.yml"
pull_request:
types: [opened, synchronize, reopened, labeled]
branches: ["main"]
paths:
- "crates/**"
- "xtask/**"
- "Cargo.toml"
- "Cargo.lock"
- ".github/workflows/coverage.yml"
- "codecov.yml"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: coverage-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' && github.event.action == 'synchronize' }}
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: "0"
RUSTFLAGS: -C debuginfo=0
jobs:
coverage:
name: Codecov Coverage
runs-on: ubuntu-latest
timeout-minutes: 45
if: >-
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch' ||
contains(github.event.pull_request.labels.*.name, 'coverage') ||
contains(github.event.pull_request.labels.*.name, 'full-ci')
steps:
- uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: Fetch base ref
if: github.event_name == 'pull_request'
run: git fetch origin "${{ github.base_ref }}":"refs/remotes/origin/${{ github.base_ref }}" || true
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.92"
components: llvm-tools-preview
- name: Use larger target dir
run: echo "CARGO_TARGET_DIR=${RUNNER_TEMP}/target" >> "$GITHUB_ENV"
- uses: Swatinem/rust-cache@v2
with:
cache-directories: ${{ runner.temp }}/target
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Generate coverage route receipt
env:
LABELS_JSON: ${{ github.event_name == 'pull_request' && toJson(github.event.pull_request.labels) || '[]' }}
PUSH_BEFORE: ${{ github.event.before || '' }}
run: |
set -euo pipefail
mkdir -p target/ci
if [ "${{ github.event_name }}" = "pull_request" ]; then
base_ref="origin/${{ github.base_ref }}"
elif [ "${{ github.event_name }}" = "push" ] && [ -n "${PUSH_BEFORE}" ] && ! printf '%s' "${PUSH_BEFORE}" | grep -Eq '^0+$'; then
base_ref="${PUSH_BEFORE}"
elif git rev-parse --verify HEAD^ >/dev/null 2>&1; then
base_ref="HEAD^"
else
base_ref="HEAD"
fi
cargo xtask ci-plan \
--base "${base_ref}" \
--head HEAD \
--labels-json "${LABELS_JSON}" \
--lanes policy/ci-lane-whitelist.toml \
--risk-packs policy/ci-risk-packs.toml \
--no-budget-annotations \
--json-out target/ci/coverage-plan.json \
--route-json-out target/ci/proof-pack-route.json
- name: Verify coverage route receipts
if: always()
run: |
status=0
for receipt in target/ci/coverage-plan.json target/ci/proof-pack-route.json; do
if [ ! -s "$receipt" ]; then
echo "::error::Missing or empty coverage route receipt: $receipt"
status=1
fi
done
exit "$status"
- name: Upload coverage route receipts
if: always()
uses: actions/upload-artifact@v7
with:
name: coverage-route
path: |
target/ci/coverage-plan.json
target/ci/proof-pack-route.json
if-no-files-found: error
retention-days: 14
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov
- id: coverage_run
name: Generate coverage
env:
CI: true
run: |
set +e
mkdir -p target/coverage
cargo llvm-cov clean --workspace
clean_status=$?
test_status=skipped
json_status=skipped
lcov_status=skipped
text_status=skipped
if [ "${clean_status}" -eq 0 ]; then
cargo llvm-cov test \
--workspace \
--all-features \
--locked \
--no-report
test_status=$?
fi
if [ "${test_status}" = "0" ]; then
cargo llvm-cov report --json --output-path coverage.json
json_status=$?
cargo llvm-cov report --lcov --output-path lcov.info
lcov_status=$?
cargo llvm-cov report --text | tee coverage.txt
text_status=${PIPESTATUS[0]}
fi
overall_status=0
for status in "${clean_status}" "${test_status}" "${json_status}" "${lcov_status}" "${text_status}"; do
if [ "${status}" != "0" ]; then
overall_status=1
fi
done
{
echo "clean_status=${clean_status}"
echo "test_status=${test_status}"
echo "json_status=${json_status}"
echo "lcov_status=${lcov_status}"
echo "text_status=${text_status}"
echo "overall_status=${overall_status}"
} > target/coverage/status.env
export CLEAN_STATUS="${clean_status}"
export TEST_STATUS="${test_status}"
export JSON_STATUS="${json_status}"
export LCOV_STATUS="${lcov_status}"
export TEXT_STATUS="${text_status}"
export OVERALL_STATUS="${overall_status}"
python - <<'PY'
import json
import os
from pathlib import Path
def command(name, env_name):
raw = os.environ[env_name]
if raw == "skipped":
return {"name": name, "status": "skipped", "exit_code": None}
code = int(raw)
return {
"name": name,
"status": "success" if code == 0 else "failure",
"exit_code": code,
}
artifacts = []
for path, kind in [
("coverage.json", "json"),
("coverage.txt", "text"),
("lcov.info", "lcov"),
]:
item = Path(path)
exists = item.exists()
size = item.stat().st_size if exists else 0
artifacts.append(
{
"path": path,
"kind": kind,
"exists": exists,
"bytes": size,
"non_empty": exists and size > 0,
}
)
payload = {
"schema": "tokmd.coverage_workflow_status.v1",
"schema_version": 1,
"overall_status": "success"
if os.environ["OVERALL_STATUS"] == "0"
else "failure",
"commands": [
command("cargo llvm-cov clean --workspace", "CLEAN_STATUS"),
command("cargo llvm-cov test", "TEST_STATUS"),
command("cargo llvm-cov report --json", "JSON_STATUS"),
command("cargo llvm-cov report --lcov", "LCOV_STATUS"),
command("cargo llvm-cov report --text", "TEXT_STATUS"),
],
"artifacts": artifacts,
}
out = Path("target/coverage/coverage-status.json")
out.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
PY
{
echo "## Coverage"
echo ""
echo "| Command | Exit |"
echo "| --- | ---: |"
echo "| llvm-cov clean | ${clean_status} |"
echo "| llvm-cov test | ${test_status} |"
echo "| report json | ${json_status} |"
echo "| report lcov | ${lcov_status} |"
echo "| report text | ${text_status} |"
echo ""
echo "Status receipt: \`target/coverage/coverage-status.json\`"
} >> "$GITHUB_STEP_SUMMARY"
echo "overall_status=${overall_status}" >> "$GITHUB_OUTPUT"
- name: Validate coverage output
if: steps.coverage_run.outputs.overall_status == '0'
run: |
set -euo pipefail
test -s coverage.json
test -s lcov.info
test -s coverage.txt
- name: Generate coverage receipt
if: steps.coverage_run.outputs.overall_status == '0'
run: |
cargo xtask coverage-receipt \
--coverage-json coverage.json \
--coverage-text coverage.txt \
--lcov lcov.info \
--output target/coverage/coverage-receipt.json
- name: Detect Codecov token
id: codecov-token
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
if [ -n "${CODECOV_TOKEN:-}" ]; then
echo "present=true" >> "$GITHUB_OUTPUT"
else
echo "present=false" >> "$GITHUB_OUTPUT"
fi
- name: Upload coverage to Codecov
if: ${{ steps.coverage_run.outputs.overall_status == '0' && steps.codecov-token.outputs.present == 'true' }}
uses: codecov/codecov-action@v6
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
flags: rust
name: tokmd-rust
fail_ci_if_error: ${{ github.event_name == 'push' }}
- name: Upload coverage artifacts
if: always()
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: |
coverage.json
coverage.txt
lcov.info
target/coverage/status.env
target/coverage/coverage-status.json
target/coverage/coverage-receipt.json
retention-days: 14
- name: Fail on coverage command failure
if: always() && steps.coverage_run.outputs.overall_status == '1'
run: |
echo "::error::Coverage command failed; see target/coverage/coverage-status.json in the coverage-report artifact."
exit 1