feat(githooks): add post-commit hook for logging and script execution

This commit is contained in:
2026-06-24 16:23:13 +08:00
parent b489e50e3e
commit af033cc87d
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
set -u
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)"
SCRIPT_PATH="$REPO_ROOT/scripts/release/pre_release_web.sh"
LOG_FILE="$REPO_ROOT/logs/post-commit.log"
COMMIT_HASH="$(git rev-parse --short HEAD 2>/dev/null || echo unknown)"
mkdir -p "$(dirname "$LOG_FILE")"
{
echo ""
echo "=== post-commit @ $(date +%Y-%m-%dT%H:%M:%S%z) ==="
echo "repo: $REPO_ROOT"
echo "commit: $COMMIT_HASH"
echo "script: $SCRIPT_PATH"
echo ""
} >> "$LOG_FILE"
if [ ! -x "$SCRIPT_PATH" ]; then
{
echo "=== ERROR: script not executable or not found ==="
echo "path: $SCRIPT_PATH"
echo "=== post-commit EXIT_CODE=127 @ $(date +%Y-%m-%dT%H:%M:%S%z) ==="
} >> "$LOG_FILE"
exit 127
fi
"$SCRIPT_PATH" >> "$LOG_FILE" 2>&1
EXIT_CODE=$?
{
echo ""
echo "=== post-commit EXIT_CODE=$EXIT_CODE @ $(date +%Y-%m-%dT%H:%M:%S%z) ==="
} >> "$LOG_FILE"
exit "$EXIT_CODE"