git hook
This commit is contained in:
1 parent
a6f35b375c
commit
b1613824ce
8 files changed
+200
-12
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
# Jenkins / 本地 CI 同款前端生产构建(与 deploy.sh、frontend/Dockerfile 一致)
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
FRONTEND_DIR="${ROOT_DIR}/frontend"
|
||||
|
||||
if [[ ! -f "${FRONTEND_DIR}/package.json" ]]; then
|
||||
echo "[ci-frontend-build] missing ${FRONTEND_DIR}/package.json"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "${FRONTEND_DIR}"
|
||||
echo "[ci-frontend-build] npm ci"
|
||||
npm ci
|
||||
echo "[ci-frontend-build] npm run build"
|
||||
npm run build
|
||||
echo "[ci-frontend-build] OK"
|
||||
@@ -9,13 +9,18 @@ if ! git -C "${ROOT_DIR}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HOOK_PATH="${ROOT_DIR}/.githooks/pre-commit"
|
||||
if [[ ! -f "${HOOK_PATH}" ]]; then
|
||||
echo "[hook-install] missing hook file: ${HOOK_PATH}"
|
||||
exit 1
|
||||
fi
|
||||
HOOKS_DIR="${ROOT_DIR}/.githooks"
|
||||
REQUIRED_HOOKS=(pre-commit pre-push _common.sh)
|
||||
|
||||
for hook_name in "${REQUIRED_HOOKS[@]}"; do
|
||||
hook_path="${HOOKS_DIR}/${hook_name}"
|
||||
if [[ ! -f "${hook_path}" ]]; then
|
||||
echo "[hook-install] missing hook file: ${hook_path}"
|
||||
exit 1
|
||||
fi
|
||||
chmod +x "${hook_path}"
|
||||
done
|
||||
|
||||
chmod +x "${HOOK_PATH}"
|
||||
if ! git -C "${ROOT_DIR}" config core.hooksPath .githooks; then
|
||||
echo "[hook-install] failed to set git config core.hooksPath."
|
||||
echo "[hook-install] please run manually in your local shell:"
|
||||
@@ -23,5 +28,9 @@ if ! git -C "${ROOT_DIR}" config core.hooksPath .githooks; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[hook-install] Installed pre-commit hook successfully."
|
||||
echo "[hook-install] Installed Git hooks successfully."
|
||||
echo "[hook-install] pre-commit: models 变更需带 migration;frontend 暂存时跑 vue-tsc"
|
||||
echo "[hook-install] pre-push: 推送含 frontend 变更时跑 npm run build"
|
||||
echo "[hook-install] core.hooksPath=$(git -C "${ROOT_DIR}" config --get core.hooksPath)"
|
||||
echo "[hook-install] 跳过前端检查: SKIP_FRONTEND_HOOKS=1"
|
||||
echo "[hook-install] 跳过全部 hook: SKIP_GIT_HOOKS=1 或 git commit/push --no-verify"
|
||||
Reference in new issue
Block a user