ci: exclude dependency sources and summarize coverage output
Rust CI tiny-wb failed CI.
Gitea/tiny-wb/pipeline/head There was a failure building this commit Details

This commit is contained in:
Dandaedre 2026-10-05 01:02:50 +02:00
parent fe5933e9fd
commit 820742048a
4 changed files with 45 additions and 21 deletions

View File

@ -5,5 +5,6 @@ rustflags = ["-Clink-arg=-fuse-ld=lld"]
incompatible-rust-versions = "fallback"
[alias]
# Registry source paths can differ from the inferred Cargo home on CI workers.
# Measured across library and application code; do not exclude production sources.
coverage = "llvm-cov --locked --all-targets --all-features --json --summary-only --fail-under-lines 85 --output-path coverage/summary.json"
coverage = "llvm-cov --locked --all-targets --all-features --ignore-filename-regex /registry/src/ --json --summary-only --fail-under-lines 85 --output-path coverage/summary.json"

View File

@ -166,7 +166,7 @@ cargo coverage
The exact alias is tracked in `.cargo/config.toml` and expands to:
```console
cargo llvm-cov --locked --all-targets --all-features --json --summary-only --fail-under-lines 85 --output-path coverage/summary.json
cargo llvm-cov --locked --all-targets --all-features --ignore-filename-regex /registry/src/ --json --summary-only --fail-under-lines 85 --output-path coverage/summary.json
```
The enforced line-coverage floor is **85%**, measured across the library and
@ -183,18 +183,23 @@ and deletes the summary, including on failure. Jenkins then creates the current
build's test and coverage markers only after unit/integration tests, Rustdoc tests, and the coverage test run succeed.
The release smoke test remains a nonfatal diagnostic.
The collector removes any stale summary before running Cargo and prints the
measured percentage before deleting the current report. On a failed Cargo run,
it also prints per-file line counts and percentages, ordered by coverage, and
preserves Cargo's exit status. Missing or invalid summaries fail with an explicit
diagnostic. A failed run never renders a successful coverage badge.
The collector removes any stale summary before running Cargo and displays only
`Final line coverage: 90.87%` on success. Compiler and test output is saved to
ignored `coverage/coverage.log` in the workspace; failures print a short error
pointing to that log and preserve Cargo's exit status. Missing or invalid
summaries fail explicitly. No per-file coverage listing is printed, and failed
runs never render a successful coverage badge.
The supplied FreeBSD Jenkins log for revision `e47feea` shows passing tests and
a coverage report followed by exit 1, without a reported percentage.
The pinned `cargo-llvm-cov` 0.6.16 can return that status silently when its line
coverage floor is missed. The deleted report prevents confirming the measured
value from that log; rerun CI with the collector diagnostics before changing
tests or investigating platform instrumentation. The 85% floor remains enforced.
The FreeBSD Jenkins report supplied on 2026-10-05 included 932 crates.io
source files alongside tiny-wb's 14 source files: 12,243/144,250 covered lines
(**8.49%**) overall, versus 1,852/2,038 (**90.87%**) for tiny-wb alone.
Dependency sources under `/root/.cargo/registry/src/` escaped the pinned tool's
default Cargo-home-based filter. The log does not establish why that default
filter missed these paths. The alias explicitly filters
`/registry/src/` paths so dependency caches are excluded regardless of their
home directory. All tiny-wb production sources and the **85%** floor remain
unchanged. This corrects report scope, not test coverage. A real FreeBSD Jenkins
rerun remains necessary to verify the corrected report on that worker.
At checkout, CI recreates ignored `coverage/` to remove stale workspace state.
In `post { cleanup { ... } }`, it uses only current-build markers to choose test

View File

@ -2,28 +2,28 @@
set -eu
mkdir -p coverage
summary=coverage/summary.json
log=coverage/coverage.log
trap 'rm -f "$summary"' 0
trap 'exit 1' HUP INT TERM
# Alias and honest initial floor live in .cargo/config.toml.
rm -f "$summary"
coverage_status=0
cargo coverage || coverage_status=$?
cargo coverage >"$log" 2>&1 || coverage_status=$?
# cargo-llvm-cov 0.6.16 can fail the floor silently after writing its report.
# Print the measurement before cleanup, but never mask a failed Cargo run.
if [ ! -s "$summary" ]; then
echo "ERROR: cargo coverage produced no summary (exit $coverage_status)." >&2
echo "ERROR: cargo coverage produced no summary (exit $coverage_status); see coverage/coverage.log." >&2
[ "$coverage_status" -ne 0 ] || coverage_status=1
exit "$coverage_status"
fi
if ! percentage=$(jq -er '.data | if type == "array" and length == 1 then .[0].totals.lines.percent else error("expected one overall total") end | select(type == "number" and . >= 0 and . <= 100)' "$summary"); then
echo "ERROR: cargo coverage produced an invalid line-coverage summary (exit $coverage_status)." >&2
echo "ERROR: cargo coverage produced an invalid line-coverage summary (exit $coverage_status); see coverage/coverage.log." >&2
[ "$coverage_status" -ne 0 ] || coverage_status=1
exit "$coverage_status"
fi
echo "Measured overall line coverage: $percentage% (required floor: see cargo coverage in .cargo/config.toml)."
LC_ALL=C awk -v percentage="$percentage" 'BEGIN { printf "Final line coverage: %.2f%%\n", percentage }'
if [ "$coverage_status" -ne 0 ]; then
echo "ERROR: cargo coverage failed (exit $coverage_status); check the measurement against --fail-under-lines and the preceding compiler/test diagnostics." >&2
jq -r '.data[0].files // [] | sort_by(.summary.lines.percent)[] | " \(.filename): \(.summary.lines.covered)/\(.summary.lines.count) lines (\(.summary.lines.percent)%)"' "$summary" >&2 || :
echo "ERROR: cargo coverage failed (exit $coverage_status); check the measurement against --fail-under-lines and coverage/coverage.log." >&2
exit "$coverage_status"
fi
scripts/ci-coverage-badges.sh coverage --value "$percentage"

View File

@ -2,6 +2,7 @@
"""Isolated renderer/publication contract checks; no public assets are touched."""
import os
import json
import re
from pathlib import Path
import stat
import shlex
@ -162,6 +163,8 @@ with tempfile.TemporaryDirectory() as directory:
# Exercise the collector with real jq and rendering, but no Rust rebuild.
cargo.write_text('''#!/bin/sh
[ "$*" = coverage ] || exit 99
echo "fake compiler output"
echo "fake test output" >&2
if [ -n "$FAKE_COVERAGE_REPORT" ]; then
printf '%s\\n' "$FAKE_COVERAGE_REPORT" > coverage/summary.json
fi
@ -179,10 +182,13 @@ exit "$FAKE_COVERAGE_STATUS"
before = Path('coverage/coverage.svg').read_bytes()
result = run(str(REPO/'scripts/collect-coverage.sh'), ok=status == 0)
assert result.returncode == status
assert f'{percentage}%' in result.stdout.decode()
assert result.stdout.decode() == f'Final line coverage: {percentage:.2f}%\n'
assert 'fake compiler output' in Path('coverage/coverage.log').read_text()
assert 'fake test output' in Path('coverage/coverage.log').read_text()
if status:
assert '--fail-under-lines' in result.stderr.decode()
assert 'src/example.rs: 80/100 lines (80%)' in result.stderr.decode()
assert 'src/example.rs' not in result.stderr.decode()
assert 'coverage/coverage.log' in result.stderr.decode()
assert Path('coverage/coverage.svg').read_bytes() == before
else:
assert ET.parse('coverage/coverage.svg').getroot().attrib['aria-label'] == f'coverage: {percentage:.0f}%'
@ -211,6 +217,18 @@ exit "$FAKE_COVERAGE_STATUS"
run(*args, 'test', ok=False)
assert not list(destination.glob('.*.svg.*'))
# Keep the alias's dependency filter portable across cache roots without
# excluding any production module (including low-coverage startup/scan code).
alias = next(line for line in (REPO/'.cargo/config.toml').read_text().splitlines()
if line.startswith('coverage = '))
arguments = shlex.split(alias.split('"', 1)[1].rsplit('"', 1)[0])
pattern = arguments[arguments.index('--ignore-filename-regex') + 1]
assert arguments[arguments.index('--fail-under-lines') + 1] == '85'
for cache in ('/root/.cargo', '/home/user/.cargo', '/custom/cargo-cache'):
assert re.search(pattern, cache + '/registry/src/index.crates.io-123/serde-1.0/src/lib.rs')
for source in (REPO/'src').rglob('*.rs'):
assert not re.search(pattern, str(source))
readme = (REPO/'README.md').read_text()
for name in ('version', 'test', 'coverage'):
assert readme.count(f'https://assets.dandaedre.com/coverage/idle-org/tiny-wb/main/{name}.svg') == 1