增加本地推送前代码检查钩子

This commit is contained in:
yml2213
2026-08-31 12:41:07 +08:00
parent cfabfa8f65
commit 1ee7d17712
3 changed files with 48 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
push_lines="$(cat)"
has_updates=0
has_deletions=0
while read -r local_ref local_sha remote_ref remote_sha; do
[ -z "${local_ref}" ] && continue
if [ "$local_sha" = "0000000000000000000000000000000000000000" ]; then
has_deletions=1
else
has_updates=1
fi
done <<< "$push_lines"
if [ "$has_updates" = "0" ] && [ "$has_deletions" = "1" ]; then
echo "[pre-push] 分支删除推送,跳过本地检查"
exit 0
fi
if [ "${SKIP_CHECKS:-0}" = "1" ]; then
echo "[pre-push] SKIP_CHECKS=1,跳过本地检查"
exit 0
fi
echo "[pre-push] 运行本地代码门禁..."
bash scripts/check.sh
echo "[pre-push] 本地检查通过"
+12
View File
@@ -50,6 +50,18 @@ npm run dev
`./scripts/deploy-prod.sh` 在构建镜像前会自动调用 `check.sh`(本地有 `go``npm` 时)。检查未通过会中止部署;确需跳过用 `--skip-check`(不推荐)。`check.sh` 也支持 `--skip-backend``--skip-frontend``--skip-tests` 做局部调试。 `./scripts/deploy-prod.sh` 在构建镜像前会自动调用 `check.sh`(本地有 `go``npm` 时)。检查未通过会中止部署;确需跳过用 `--skip-check`(不推荐)。`check.sh` 也支持 `--skip-backend``--skip-frontend``--skip-tests` 做局部调试。
需要在本地推送前自动执行同一套检查时,启用 Git hook:
```bash
bash scripts/install-git-hooks.sh
```
启用后,`git push` 会执行 `scripts/check.sh`;仅临时跳过时使用:
```bash
SKIP_CHECKS=1 git push
```
## 开发态短信与实名 ## 开发态短信与实名
- 后端日志使用单行可读文本。开发环境同时输出控制台和 `backend/logs/app-YYYY-MM-DD.log`,生产示例只输出文件以避免重复存储;可通过 `LOG_LEVEL=debug|info|warn|error` 调整级别。 - 后端日志使用单行可读文本。开发环境同时输出控制台和 `backend/logs/app-YYYY-MM-DD.log`,生产示例只输出文件以避免重复存储;可通过 `LOG_LEVEL=debug|info|warn|error` 调整级别。
+6
View File
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
git -C "$ROOT_DIR" config core.hooksPath .githooks
echo "已启用 .githooks(推送前执行 scripts/check.shSKIP_CHECKS=1 可跳过)"