Skip to content

Commit c258dc7

Browse files
hyperpolymathclaude
andcommitted
feat(rust-ci-reusable): real owned coverage gate (llvm-cov + ratcheted floor)
The coverage job was opt-in tarpaulin -> external codecov with NO enforced threshold (just an upload), so 'covered' claims were unbacked estate-wide. Now, when enable_coverage is set, it: - measures line coverage with cargo-llvm-cov (accurate, no external service); - enforces a caller-supplied coverage_floor (new input, default 0 = report-only) and FAILS the job below it — a gate we OWN on our own runner; - reports the % to the job summary. Ratchet model: set coverage_floor at the repo's honest baseline and raise it toward target over time; never lower it. First consumer: hybrid-automation-router (floor 84). This is the banked 'reusable tests for all repos' coverage gate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c4d2410 commit c258dc7

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

.github/workflows/rust-ci-reusable.yml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ on:
6565
required: false
6666
default: false
6767
enable_coverage:
68-
description: Run `cargo tarpaulin` + upload to codecov (slow; off by default)
68+
description: Measure line coverage with cargo-llvm-cov and enforce `coverage_floor` (off by default)
6969
type: boolean
7070
required: false
7171
default: false
72+
coverage_floor:
73+
description: Minimum line-coverage percent when enable_coverage is set; ratchet upward, never lower.
74+
type: string
75+
required: false
76+
default: "0"
7277
clippy_args:
7378
description: Args appended to `cargo clippy`
7479
type: string
@@ -254,8 +259,8 @@ jobs:
254259
run: cargo audit
255260

256261
coverage:
257-
timeout-minutes: 20
258-
name: Coverage (tarpaulin + codecov)
262+
timeout-minutes: 25
263+
name: llvm-cov line coverage
259264
runs-on: ${{ inputs.runs-on }}
260265
needs: detect
261266
if: ${{ inputs.enable_coverage && needs.detect.outputs.has_cargo == 'true' }}
@@ -264,6 +269,9 @@ jobs:
264269
defaults:
265270
run:
266271
working-directory: ${{ inputs.working_directory }}
272+
env:
273+
# Ratcheted line-coverage floor (from the caller). Raise toward target; never lower.
274+
FLOOR: ${{ inputs.coverage_floor }}
267275
steps:
268276
- name: Checkout repository
269277
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
@@ -276,14 +284,25 @@ jobs:
276284
uses: dtolnay/rust-toolchain@67ef31d5b988238dd797d409d6f9574278e20537 # stable
277285
with:
278286
toolchain: stable
287+
components: llvm-tools-preview
279288

280-
- name: Install tarpaulin
281-
run: cargo install cargo-tarpaulin --locked
289+
- name: Install cargo-llvm-cov
290+
run: cargo install cargo-llvm-cov --locked
282291

283-
- name: Generate coverage
284-
run: cargo tarpaulin --out Xml
292+
- name: Measure line coverage
293+
id: cov
294+
# Self-contained: no external coverage service. Own the gate on our runner.
295+
run: |
296+
set -euo pipefail
297+
cargo llvm-cov --workspace --locked --json --output-path cov.json
298+
PCT=$(jq -r '.data[0].totals.lines.percent' cov.json)
299+
printf '### Line coverage: %.2f%% (floor %s%%)\n' "$PCT" "$FLOOR" >> "$GITHUB_STEP_SUMMARY"
300+
echo "pct=$PCT" >> "$GITHUB_OUTPUT"
285301
286-
- name: Upload to codecov
287-
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
288-
with:
289-
files: cobertura.xml
302+
- name: Enforce ratchet floor
303+
run: |
304+
set -euo pipefail
305+
awk -v p="${{ steps.cov.outputs.pct }}" -v f="$FLOOR" 'BEGIN {
306+
if (p + 0 < f + 0) { printf "FAIL: line coverage %.2f%% is below floor %s%%\n", p, f; exit 1 }
307+
printf "OK: line coverage %.2f%% >= floor %s%%\n", p, f
308+
}'

0 commit comments

Comments
 (0)