|
| 1 | +#!/usr/bin/env bash |
| 2 | +# README badges state a version and a suite count. Every value here is |
| 3 | +# recomputed from the tree: the manifests are the only source for the version, |
| 4 | +# the hooks directory is the only source for the suite count. A badge number |
| 5 | +# that cannot be recomputed from the tree does not belong on the README. |
| 6 | +# Rationale: DECISIONS.md D-43. |
| 7 | +set -u |
| 8 | +here="$(cd "$(dirname "$0")" && pwd)"; root="$here/.." |
| 9 | +readme="$root/README.md" |
| 10 | +plugin="$root/.claude-plugin/plugin.json" |
| 11 | +market="$root/.claude-plugin/marketplace.json" |
| 12 | + |
| 13 | +command -v jq >/dev/null || { echo "jq is required for this suite"; exit 1; } |
| 14 | + |
| 15 | +fails=0; checks=0 |
| 16 | +fail() { echo " FAIL: $1"; fails=$((fails+1)); } |
| 17 | + |
| 18 | +v_plugin="$(jq -r .version "$plugin")" |
| 19 | +v_market="$(jq -r '.plugins[0].version' "$market")" |
| 20 | + |
| 21 | +checks=$((checks+1)) |
| 22 | +[ "$v_plugin" = "$v_market" ] || fail "manifest versions disagree: plugin.json $v_plugin vs marketplace.json $v_market" |
| 23 | + |
| 24 | +n=0 |
| 25 | +for f in "$root"/hooks/test-*.sh; do [ -f "$f" ] && n=$((n+1)); done |
| 26 | + |
| 27 | +b_version="$(sed -n 's/.*img\.shields\.io\/badge\/version-\([0-9][0-9.]*\)-.*/\1/p' "$readme" | head -1)" |
| 28 | +b_suites="$(sed -n 's/.*img\.shields\.io\/badge\/tests-\([0-9][0-9]*\)%20suites.*/\1/p' "$readme" | head -1)" |
| 29 | + |
| 30 | +checks=$((checks+1)) |
| 31 | +[ "$b_version" = "$v_plugin" ] || fail "version badge says '${b_version:-none}', the manifests say $v_plugin" |
| 32 | +checks=$((checks+1)) |
| 33 | +grep -qF "alt=\"Version $v_plugin\"" "$readme" || fail "version badge alt text does not say $v_plugin" |
| 34 | +checks=$((checks+1)) |
| 35 | +[ "$b_suites" = "$n" ] || fail "tests badge says '${b_suites:-none}' suites, hooks/ holds $n" |
| 36 | +checks=$((checks+1)) |
| 37 | +grep -qF "alt=\"Tests: $n suites\"" "$readme" || fail "tests badge alt text does not say $n suites" |
| 38 | + |
| 39 | +echo |
| 40 | +if [ "$fails" -eq 0 ]; then |
| 41 | + echo "all checks pass ($checks)" |
| 42 | + exit 0 |
| 43 | +else |
| 44 | + echo "$fails of $checks badge check(s) failed: recompute the badge from the tree (manifest version, live suite count) instead of hand-editing the number." |
| 45 | + exit 1 |
| 46 | +fi |
0 commit comments