chore: 新增签名凭据 pre-commit 拦截钩子,防止 signingConfigs 入库

This commit is contained in:
AndyChen1024
2026-09-11 17:26:33 +08:00
parent a25eab2d61
commit a0e0758b6b
3 changed files with 61 additions and 2 deletions

32
scripts/git-hooks/pre-commit Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# 拦截提交包含签名凭据的 build-profile.json5。
# Block commits that add signing credentials to build-profile.json5.
# 详见 docs/build-deploy.md 的「签名管理」章节。
set -u
FILE="build-profile.json5"
# 仅当本次提交要改动 build-profile.json5 时才检查
if git diff --cached --quiet -- "$FILE"; then
exit 0
fi
# 读取暂存区版本,检测签名敏感字段
if git show ":$FILE" | grep -qE '"(keyPassword|storePassword|certpath|storeFile|keyAlias|signAlg)"'; then
cat >&2 <<'EOF'
❌ 已拦截提交:build-profile.json5 中含签名凭据(keyPassword / storePassword / certpath / …)。
signingConfigs 必须保持为空 [] 才能提交。
处理办法:
- 若只是本地 DevEco 自动签名产生的:先取消暂存,再还原为空
git reset HEAD build-profile.json5
git checkout -- build-profile.json5
- 确需本地跑真机:保持该改动「未提交」即可,不要 git add 它。
如确实要临时绕过(不建议):git commit --no-verify
详见 docs/build-deploy.md 的「签名管理」章节。
EOF
exit 1
fi
exit 0