a22db0874f
.githooks/pre-commit 在原有(红线/SQL/codegen-drift)基础上增挂三道 ds-flow 闸,
条件触发、秒级:
- 原型校验(check-ds):动了 design/prototype/ 才跑
- 跨端同源(check-l1-sync):动了 prototype/ 或 web/{website,usercenter}/ 才跑
- Flutter 颜色单源(check_ds_code --changed):动了 client/lib/*.dart 才跑(只扫改动)
install-hooks.sh 说明同步更新。启用仍是每台机一次性 `bash ci/install-hooks.sh`
(不代跑,改本机 git config;CLAUDE.md 治理章节已注明)。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
52 lines
1.9 KiB
Bash
Executable File
52 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# .githooks/pre-commit — 闸 3:提交前本地把关(复用 CI 同款检查的快子集)。
|
|
#
|
|
# 启用:bash ci/install-hooks.sh (设 git core.hooksPath=.githooks)
|
|
# 设计:成功静默、失败才打详情;只放秒级检查。flutter/go test 较慢,留给 CI(闸 4)。
|
|
#
|
|
# 跑:红线词扫描 + 可移植 SQL 扫描 + codegen 漂移检查。
|
|
set -euo pipefail
|
|
|
|
ROOT="$(git rev-parse --show-toplevel)"
|
|
cd "$ROOT"
|
|
|
|
# run_check <名称> <命令...> —— 成功静默,失败打输出并中止提交。
|
|
run_check() {
|
|
local name="$1"
|
|
shift
|
|
local out
|
|
if ! out="$("$@" 2>&1)"; then
|
|
echo "[pre-commit] ✗ ${name} 未通过:" >&2
|
|
echo "${out}" >&2
|
|
echo "[pre-commit] 提交已中止。修复后重试,或临时 --no-verify 跳过(不推荐)。" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
run_check "红线词扫描" bash ci/scan-redline.sh
|
|
run_check "可移植 SQL 扫描" bash ci/scan-portable-sql.sh
|
|
|
|
if command -v node >/dev/null 2>&1; then
|
|
run_check "codegen 漂移检查" bash ci/check-codegen-drift.sh
|
|
|
|
# ── ds-flow 闸(条件触发,秒级)──
|
|
staged="$(git diff --cached --name-only --diff-filter=ACM)"
|
|
|
|
# 原型校验:仅在动了 design/prototype/ 时跑(轻量,扫整个原型)。
|
|
if printf '%s\n' "$staged" | grep -q '^design/prototype/'; then
|
|
run_check "原型校验(check-ds)" node design/prototype/tools/check-ds.mjs
|
|
fi
|
|
|
|
# 跨端同源:动了原型 token/图标 或 web token 时跑(防漂移)。
|
|
if printf '%s\n' "$staged" | grep -qE '^(design/prototype/|web/(website|usercenter)/)'; then
|
|
run_check "跨端同源(check-l1-sync)" node tools/check-l1-sync.mjs
|
|
fi
|
|
|
|
# Flutter 颜色单源:只扫本次改动的 dart(--changed,快),动了 client/lib 才有意义。
|
|
if printf '%s\n' "$staged" | grep -q '^client/lib/.*\.dart$'; then
|
|
run_check "Flutter 颜色单源(check_ds_code)" bash -c 'cd client && node tool/check_ds_code.mjs --changed'
|
|
fi
|
|
fi
|
|
|
|
echo "[pre-commit] ✓ 本地闸通过(完整测试见 CI)"
|