systab/.githooks/pre-commit
Matthias Johnson be47247da7
Some checks failed
CI / shellcheck (push) Failing after 2s
Fix test cleanup destroying user jobs, consolidate code
- Test cleanup now only removes jobs it created (tracked via
  test_job_ids array) instead of nuking all systab_* units.
  Fixes bug where running tests would delete real user jobs.
- Fix extract_id subshell issue: array appends in $() don't
  propagate to parent, so use _extracted_id variable instead.
- Merge disable_job_by_id/enable_job_by_id into toggle_job_by_id.
- Update usage text: -D/-E/-L/-S now show <id|name> consistently.
- Fix pre-commit hook sed regex that only captured last digit of
  multi-digit numbers; replaced with grep -oP.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 21:55:09 -07:00

37 lines
747 B
Bash
Executable file

#!/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" <<EOF
{
"schemaVersion": 1,
"label": "tests",
"message": "$status",
"color": "$color"
}
EOF
git add "$badge_file"
}
echo "Running ShellCheck..."
if ! shellcheck systab; then
write_badge "failing" "red"
echo "ShellCheck failed — commit blocked."
exit 1
fi
echo "Running tests..."
if output=$(./test.sh 2>&1); then
echo "$output"
count=$(grep -oP '\d+ passed' <<< "$output" | tail -1)
write_badge "${count:-passing}" "brightgreen"
else
echo "$output"
write_badge "failing" "red"
echo "Tests failed — commit blocked."
exit 1
fi