build(migration): pre-commit拦截migration 多head问题
This commit is contained in:
1 parent
4fa5ab4929
commit
ac67b07107
5 files changed
+263
-3
No files matched your search
+6
-2
@@ -14,7 +14,7 @@
|
||||
|
||||
| 层级 | 时机 | 谁生效 | 检查内容 |
|
||||
|------|------|--------|----------|
|
||||
| **pre-commit** | `git commit` | 已安装 Hook 的本机 | models 须带 migration;暂存 `frontend/` 时跑 `vue-tsc` |
|
||||
| **pre-commit** | `git commit` | 已安装 Hook 的本机 | models 须带 migration;migration 须单 head;暂存 `frontend/` 时跑 `vue-tsc` |
|
||||
| **commit-msg** | `git commit` | 已安装 Hook 的本机 | 提交信息须符合 [COMMIT_CONVENTION](./convention/COMMIT_CONVENTION.md)(commitlint) |
|
||||
| **pre-push** | `git push` | 已安装 Hook 的本机 | 本次推送含 `frontend/` 变更时跑 `npm run build` |
|
||||
| **Jenkins CI** | push 触发流水线 | 全员(不装 Hook 也跑) | `npm ci && npm run build`(`scripts/ci_frontend_build.sh`) |
|
||||
@@ -72,7 +72,7 @@ chmod +x scripts/install_git_hooks.sh
|
||||
|
||||
```text
|
||||
[hook-install] Installed Git hooks successfully.
|
||||
[hook-install] pre-commit: models 变更需带 migration;frontend 暂存时跑 vue-tsc
|
||||
[hook-install] pre-commit: models 变更需带 migration;migration 须单 head;frontend 暂存时跑 vue-tsc
|
||||
[hook-install] commit-msg: 校验提交信息格式(Conventional Commits)
|
||||
[hook-install] pre-push: 推送含 frontend 变更时跑 npm run build
|
||||
[hook-install] core.hooksPath=.githooks
|
||||
@@ -132,9 +132,12 @@ npm install
|
||||
| 条件 | 行为 |
|
||||
|------|------|
|
||||
| 暂存了 `backend/app/models.py`,但未暂存 `backend/migrations/versions/*.py` | **拒绝 commit** |
|
||||
| 暂存了 `backend/migrations/versions/*.py` | 运行 `scripts/check_migration_heads.py`:Alembic **必须仅 1 个 head**;新增 migration 的 `down_revision` 须指向已存在的 revision |
|
||||
| 暂存路径含 `frontend/` | 运行 `npx vue-tsc -b`(需已有 `node_modules`) |
|
||||
| 未暂存 `frontend/` | 不跑前端检查 |
|
||||
|
||||
多 head 时 hook 会提示执行 `flask --app manage.py db merge heads` 后再提交。
|
||||
|
||||
`SKIP_FRONTEND_HOOKS` **不能**跳过 models/migration 检查,也**不能**跳过 commit-msg 校验。
|
||||
|
||||
### 5.2 commit-msg
|
||||
@@ -243,6 +246,7 @@ git push --no-verify
|
||||
| `package.json` | 根目录 tooling 依赖(commitlint) |
|
||||
| `scripts/install_git_hooks.sh` | 一键安装 |
|
||||
| `scripts/ci_frontend_build.sh` | Jenkins / 本地 CI 同款 build |
|
||||
| `scripts/check_migration_heads.py` | 离线校验 Alembic 仅 1 个 head(pre-commit 调用) |
|
||||
| `Jenkinsfile` | `Frontend Build (CI)` 阶段 |
|
||||
| `docs/新人环境搭建与配置文档.md` | 新人环境 §4.2 简要说明 |
|
||||
|
||||
|
||||
Reference in new issue
Block a user