39 lines
1.2 KiB
Bash
Executable file
39 lines
1.2 KiB
Bash
Executable file
#!/bin/sh
|
|
# prepare-commit-msg: append build + test status to every commit message.
|
|
# Skipped for merge, squash, and rebase commits.
|
|
|
|
COMMIT_MSG_FILE="$1"
|
|
COMMIT_SOURCE="${2:-}"
|
|
|
|
case "$COMMIT_SOURCE" in
|
|
merge|squash) exit 0 ;;
|
|
esac
|
|
|
|
BUILD_STATUS="pass"
|
|
TEST_STATUS="pass"
|
|
TEST_DETAIL=""
|
|
|
|
BUILD_OUT=$(npm run build --silent 2>&1) || BUILD_STATUS="FAIL"
|
|
TEST_OUT=$(npm test --silent 2>&1) || TEST_STATUS="FAIL"
|
|
|
|
# Extract summary line from vitest output (e.g. "7 passed (1 file)")
|
|
# Strip ANSI escape codes so the footer is plain text
|
|
TEST_DETAIL=$(printf '%s\n' "$TEST_OUT" \
|
|
| grep -E "Tests.*passed|Tests.*failed" \
|
|
| tail -1 \
|
|
| sed 's/\x1b\[[0-9;]*m//g' \
|
|
| sed 's/^[[:space:]]*//' \
|
|
| sed 's/[[:space:]]*$//')
|
|
|
|
FOOTER="Build: ${BUILD_STATUS} | Tests: ${TEST_STATUS}${TEST_DETAIL:+ — ${TEST_DETAIL}}"
|
|
|
|
{
|
|
printf '\n---\n'
|
|
printf '%s\n' "$FOOTER"
|
|
} >> "$COMMIT_MSG_FILE"
|
|
|
|
# Also append to local log (gitignored, survives between pushes)
|
|
COMMIT_SUBJECT=$(head -1 "$COMMIT_MSG_FILE")
|
|
TIMESTAMP=$(./scripts/date-format.sh display-ts 2>/dev/null || date '+%d.%b.%Y %H:%M:%S' | tr '[:upper:]' '[:lower:]')
|
|
mkdir -p logs
|
|
printf '%s | %s | %s\n' "$TIMESTAMP" "$FOOTER" "$COMMIT_SUBJECT" >> logs/test-runs.log
|