chore(cursor): run frontend CI before gh pr create

Add scripts/verify_frontend_pr.sh and a beforeShellExecution hook that
blocks PR creation when frontend test, type-check, or build fails.
main
wizardchen 2026-07-31 11:51:18 +08:00 committed by lyingbug
parent a1a07a52eb
commit 5443b3814c
4 changed files with 86 additions and 0 deletions

11
.cursor/hooks.json 100644
View File

@ -0,0 +1,11 @@
{
"version": 1,
"hooks": {
"beforeShellExecution": [
{
"command": ".cursor/hooks/pre-pr-create.sh",
"matcher": "gh pr create"
}
]
}
}

View File

@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
cd "$ROOT"
input="$(cat)"
command="$(
INPUT="$input" node -e 'const j=JSON.parse(process.env.INPUT||"{}"); process.stdout.write(j.command||"")'
)"
if [[ "$command" != *"gh pr create"* ]]; then
echo '{ "permission": "allow" }'
exit 0
fi
resolve_base_ref() {
local ref
for ref in "${WEKNORA_PR_BASE:-github_public/main}" github_public/main origin/main main; do
if git rev-parse --verify "$ref" >/dev/null 2>&1; then
echo "$ref"
return 0
fi
done
echo "HEAD"
}
base_ref="$(resolve_base_ref)"
needs_frontend=false
if git diff --name-only "${base_ref}...HEAD" 2>/dev/null | grep -q '^frontend/'; then
needs_frontend=true
fi
if git diff --name-only | grep -q '^frontend/' || git diff --name-only --cached | grep -q '^frontend/'; then
needs_frontend=true
fi
if [[ "$needs_frontend" != true ]]; then
echo '{ "permission": "allow" }'
exit 0
fi
if ! "$ROOT/scripts/verify_frontend_pr.sh"; then
cat <<'EOF'
{
"permission": "deny",
"user_message": "Frontend CI 未通过(npm test / type-check / build)。请先修复后再创建 PR。",
"agent_message": "Run `scripts/verify_frontend_pr.sh` (or `cd frontend && npm test && npm run type-check && npm run build`) and fix failures before `gh pr create`."
}
EOF
exit 2
fi
echo '{ "permission": "allow" }'
exit 0

4
.gitignore vendored
View File

@ -4,6 +4,10 @@
!.env.example
!.gitignore
!.github/
!.cursor/
!.cursor/hooks.json
!.cursor/hooks/
!.cursor/hooks/**
# 敏感文件
*.pem

View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT/frontend"
echo "[verify_frontend_pr] npm test"
npm test
echo "[verify_frontend_pr] npm run type-check"
npm run type-check
echo "[verify_frontend_pr] npm run build"
npm run build
echo "[verify_frontend_pr] OK"