#!/usr/bin/env bash set -euo pipefail badge_file="badges/tests.json" write_badge() { local status="$1" color="$2" mkdir -p badges cat > "$badge_file" <&1); then echo "$output" test_count=$(grep -oP '\d+(?= passed)' <<< "$output" | tail -1) else echo "$output" write_badge "failing" "red" echo "Tests failed — commit blocked." exit 1 fi echo "Running demo tape tests..." if tape_output=$(./demo/test-tapes.sh 2>&1); then echo "$tape_output" tape_count=$(grep -oP '\d+(?= passed)' <<< "$tape_output" | tail -1) else echo "$tape_output" write_badge "failing" "red" echo "Demo tape tests failed — commit blocked." exit 1 fi total_count=$(( ${test_count:-0} + ${tape_count:-0} )) write_badge "${total_count} passed" "brightgreen"