The "consider bumping" hint pointed to `coverage/floor.txt`, but the floor moved to `pubspec.yaml`'s `coverage_floor:` key when the gate was first folded together. Updates the message to match the actual source. Co-Authored-By: Claude <noreply@anthropic.com>
51 lines
1.7 KiB
Bash
Executable File
51 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Coverage gate — fails if total line coverage drops below the
|
|
# `coverage_floor:` value in pubspec.yaml. Driven by D-66.
|
|
#
|
|
# Reads coverage/lcov.info (generated by `flutter test --coverage`,
|
|
# which `ci/test.sh` runs as part of the fast suite). Parses the
|
|
# total LF/LH counts and compares the integer percentage against
|
|
# the floor. The floor only ratchets up — bumping it requires an
|
|
# explicit edit to pubspec.yaml committed alongside the test
|
|
# additions that earned the bump.
|
|
#
|
|
# Self-contained parser (awk) — does not depend on `lcov` being
|
|
# installed on the dev machine.
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
LCOV=coverage/lcov.info
|
|
|
|
if [[ ! -f "$LCOV" ]]; then
|
|
echo "==> coverage gate: $LCOV missing — run \`make test\` first (it writes lcov)" >&2
|
|
exit 2
|
|
fi
|
|
|
|
floor=$(awk -F: '/^coverage_floor:/ {gsub(/ /,"",$2); print $2; exit}' pubspec.yaml)
|
|
if [[ -z "$floor" ]]; then
|
|
echo "==> coverage gate: pubspec.yaml is missing coverage_floor: — see D-66" >&2
|
|
exit 2
|
|
fi
|
|
read measured measured_int < <(
|
|
awk -F: '
|
|
/^LF:/ { lf += $2 }
|
|
/^LH:/ { lh += $2 }
|
|
END {
|
|
pct = (lh / lf) * 100
|
|
printf "%.2f %d\n", pct, int(pct)
|
|
}
|
|
' "$LCOV"
|
|
)
|
|
|
|
if (( measured_int < floor )); then
|
|
echo "==> coverage gate FAIL: ${measured}% < floor ${floor}%"
|
|
echo " Add tests, or — if the drop is intentional — explain in the commit and lower the floor explicitly."
|
|
exit 1
|
|
fi
|
|
|
|
if (( measured_int > floor )); then
|
|
echo "==> coverage gate OK: ${measured}% (floor ${floor}%) — ${measured_int}% available; consider bumping pubspec.yaml coverage_floor: to ${measured_int}"
|
|
else
|
|
echo "==> coverage gate OK: ${measured}% (floor ${floor}%)"
|
|
fi
|