fix(deploy): --backend-only/--all 不该连带跳过"改动范围"的计算

真机验证时发现:显式指定 --backend-only 会直接 return,没算 git diff,
于是 DIFF_KNOWN 一直是 false —— "无 migrations 改动就自动跳过备份"的判断随之失效,
一次只想重建后端的部署照样会跑 pg_dump + 传 OSS(生产上约 12 分钟)。

修复:拆成两步
- compute_changed_files:只回答"自上次成功部署以来改了什么"(CHANGED_FILES / DIFF_KNOWN /
  ENV_CHANGED / LAST_DEPLOYED_SHA),在任何分支下都先算;
- detect_changed_services:只决定"重建哪一端",显式参数(--all/--backend-only/--web-only/
  --reset-db)只覆盖重建范围,不覆盖改动范围。
- print_plan 改用 LAST_DEPLOYED_SHA,不再重复读状态文件。

补一条顺序守卫用例:compute_changed_files 必须在 detect_changed_services 之前调用。
This commit is contained in:
yml2213
2026-10-03 16:42:55 +08:00
parent 9b6aa8e2fd
commit ccbcb7cbae
2 changed files with 62 additions and 44 deletions
@@ -132,5 +132,12 @@ test(
assert.ok(source.includes('DIFF_KNOWN'), '缺少"改动范围是否已知"的判定')
assert.ok(source.includes('migrations_changed'), '缺少 migrations 改动判定')
assert.ok(source.includes('--backup 可强制'), '缺少强制备份的提示')
// --backend-only/--all 这类参数只能覆盖"重建哪一端",不能顺手把"改了什么"一起跳过:
// 否则 DIFF_KNOWN 永远是 false,无 schema 变更也会去跑 pg_dump + 传 OSS(生产 ~12 分钟)。
const computeIndex = source.indexOf('compute_changed_files\n')
const detectIndex = source.indexOf('detect_changed_services\n')
assert.ok(computeIndex > 0 && detectIndex > 0, '找不到改动计算/重建判定的调用')
assert.ok(computeIndex < detectIndex, '必须先算改动范围,再决定重建范围')
},
)