feat(release): 抬档门禁(破坏性 ⇒ 0.x 抬次 / ≥1.0.0 抬主)+ 1.0.0 前置(稳定契约承诺)

原来预检只"打印破坏性条数",抬哪一档靠人自觉 ⇒ 改成硬门禁:

- **抬档门禁**:破坏性条数取自**目标提交里候选版本那一段**(发版事实看提交,不看工作区)。
  `0.x` 阶段有破坏性 ⇒ 必须抬**次版本**(或主版本),只抬修订 ⇒ 阻断并报出该抬到哪一档;
  `≥1.0.0` 之后有破坏性 ⇒ 必须抬**主版本**,抬次/修订都阻断。
  另加"候选号必须大于上一个正式版本"(版本只增不减)。
- **1.0.0 前置**:上一版本是 `0.x` 时,候选 `1.0.0` = 对外承诺契约稳定 ⇒ 必须先有写实的
  《稳定契约承诺》(覆盖 接口 / 数据模型 / 配置 / CLI 输出与退出码,不留 `待填`/`TODO`/`TBD`),
  **且候选发布记录里链接它**,缺任一条 ⇒ 阻断;`1.x → 2.0.0` 不重复要求。
- 预检新增"版本走向"事实行(上一版本 → 候选 / 抬哪一档 / 破坏性 N 条 ⇒ 要求哪一档 ✅⛔);
  `docs/RELEASE_RUNBOOK.md` 新增"抬哪一档"对照表与《稳定契约承诺》段(故意留占位)。

验证:release_preflight --self-test 32 分支全过(含新增 9 条);反向夹具新增 §24 六条真实临时仓库用例
(0.x 只抬修订 ⇒ 阻断、0.x 抬次 ⇒ 放行、≥1.0.0 抬次 ⇒ 阻断、1.0.0 留占位 ⇒ 阻断、写实+链接 ⇒ 放行、
写实但没链接 ⇒ 仍阻断)⇒ 夹具 91/0;make verify 15/15。
于是 0.1.0 之后的第一个提交(本提交)开发号 = 0.1.1。
This commit is contained in:
t
2026-10-13 17:13:44 +08:00
parent 6de5d52363
commit 950c1b429b
3 changed files with 259 additions and 2 deletions
+99 -1
View File
@@ -805,5 +805,103 @@ else
no "预检留下了 tag:$(git tag -l 'v*' | tr '\n' ' ')"
fi
echo
echo "§24 抬档门禁(破坏性 ⇒ 0.x 抬次 / ≥1.0.0 抬主)与 1.0.0 前置(《稳定契约承诺》)"
cat >/tmp/kg_bump_lib.py <<'LIB'
import os, pathlib, shutil, subprocess, tempfile
def mk(prev, cand, breaking_in_changed, stab_section=None, link_in_record=False):
"""造临时仓库:CHANGELOG 顶部 = 候选版本,下面留上一版本;docs 里有/没有承诺段。"""
d = pathlib.Path(tempfile.mkdtemp(prefix="kg-bump-"))
(d / "scripts").mkdir()
for n in ("check_changelog.py", "release_preflight.py", "version.py"):
(d / "scripts" / n).write_text(pathlib.Path("scripts", n).read_text(encoding="utf-8"),
encoding="utf-8")
(d / "docs").mkdir()
doc = "# 发布运行手册\n"
if stab_section:
doc += "\n## 稳定契约承诺(占位)\n\n" + stab_section + "\n"
(d / "docs" / "RELEASE_RUNBOOK.md").write_text(doc, encoding="utf-8")
(d / ".gitea").mkdir()
(d / ".gitea" / "required-contexts.txt").write_text("build / build (push)\n", encoding="utf-8")
changed = ("\n### Changed\n\n- **破坏性**:接口下线,升级见 "
"[发布文档](docs/RELEASE_RUNBOOK.md)\n") if breaking_in_changed else ""
added = "- 新东西" + ("(稳定契约承诺见 [本文](docs/RELEASE_RUNBOOK.md))" if link_in_record else "")
(d / "CHANGELOG.md").write_text(
f"# Changelog\n\n## [{cand}] - 2026-10-13\n\n### Added\n\n{added}\n{changed}"
f"\n## [{prev}] - 2026-09-01\n\n### Fixed\n\n- 旧\n", encoding="utf-8")
(d / "no-hooks").mkdir()
env = {**os.environ, "GIT_AUTHOR_NAME": "f", "GIT_AUTHOR_EMAIL": "f@f",
"GIT_COMMITTER_NAME": "f", "GIT_COMMITTER_EMAIL": "f@f",
"GIT_CONFIG_COUNT": "1", "GIT_CONFIG_KEY_0": "core.hooksPath",
"GIT_CONFIG_VALUE_0": str(d / "no-hooks")}
for a in (["init", "-q", "-b", "main"], ["add", "-A"], ["commit", "-q", "-m", "chore: 夹具"]):
subprocess.run(["git", *a], cwd=d, env=env, check=True, capture_output=True)
return d
def pre(prev, cand, breaking, *args, **kw):
d = mk(prev, cand, breaking, **kw)
try:
r = subprocess.run(["python3", "scripts/release_preflight.py", "--version", cand, "--no-api"],
cwd=d, capture_output=True, text=True)
return r.stdout + r.stderr
finally:
shutil.rmtree(d, ignore_errors=True)
LIB
FULL="冻结 /api/v1;变更提前一个次版本通知。|表结构兼容窗口 2 个大版本。|配置项冻结,弃用先警告一个小版本。|0/1/2 语义固定。"
pycheck "破坏性 + 0.x 只抬修订(0.1.0→0.1.3)⇒ 阻断,并给出抬档结论" <<'PY'
import kg_bump_lib as L # noqa
out = L.pre("0.1.0", "0.1.3", True)
good = "必须抬**次版本**" in out and "⛔ 抬档不够" in out
print(("✅ " if good else "❌ ") + "版本走向行:" + next((l.strip() for l in out.splitlines()
if "版本走向" in l), "(没有这行)"))
raise SystemExit(0 if good else 1)
PY
pycheck "破坏性 + 0.x 抬次(0.1.0→0.2.0)⇒ 该条不拦(✅ 抬档够)" <<'PY'
import kg_bump_lib as L # noqa
out = L.pre("0.1.0", "0.2.0", True)
good = "必须抬**次版本**" not in out and "✅ 抬档够" in out
print(("✅ " if good else "❌ ") + next((l.strip() for l in out.splitlines() if "版本走向" in l), ""))
raise SystemExit(0 if good else 1)
PY
pycheck "破坏性 + ≥1.0.0 只抬次(1.2.3→1.3.0)⇒ 阻断(必须抬主)" <<'PY'
import kg_bump_lib as L # noqa
out = L.pre("1.2.3", "1.3.0", True)
good = "必须抬**主版本**" in out
print(("✅ " if good else "❌ ") + next((l.strip() for l in out.splitlines() if "版本走向" in l), ""))
raise SystemExit(0 if good else 1)
PY
pycheck "首发 1.0.0 但《稳定契约承诺》留占位 ⇒ 阻断(报出占位与缺项)" <<'PY'
import kg_bump_lib as L # noqa
out = L.pre("0.9.3", "1.0.0", False,
stab_section="- **接口**(待填)\n- **数据模型**(待填)\n")
good = "稳定契约承诺" in out and "占位" in out and "没覆盖「配置」" in out
print(("✅ " if good else "❌ ") + next((l.strip() for l in out.splitlines() if "1.0.0 前置" in l), ""))
raise SystemExit(0 if good else 1)
PY
pycheck "1.0.0 + 承诺段写实 + 发布记录里链接 ⇒ 该条不拦" <<'PY'
import kg_bump_lib as L # noqa
sec = ("- **接口**:冻结 /api/v1;变更提前一个次版本通知。\n"
"- **数据模型**:表结构兼容窗口 2 个大版本。\n"
"- **配置**:配置项冻结,弃用先警告一个小版本。\n"
"- **CLI 输出与退出码**:0/1/2 语义固定。\n")
out = L.pre("0.9.3", "1.0.0", False, stab_section=sec, link_in_record=True)
good = "候选进入 1.0.0" not in out and "✅ 已写实" in out
print(("✅ " if good else "❌ ") + next((l.strip() for l in out.splitlines() if "1.0.0 前置" in l), ""))
raise SystemExit(0 if good else 1)
PY
pycheck "1.0.0 + 承诺段写实但发布记录里**没链接** ⇒ 仍阻断" <<'PY'
import kg_bump_lib as L # noqa
sec = ("- **接口**:冻结 /api/v1。\n- **数据模型**:兼容 2 个大版本。\n"
"- **配置**:配置项冻结。\n- **CLI 输出与退出码**:0/1/2 固定。\n")
out = L.pre("0.9.3", "1.0.0", False, stab_section=sec, link_in_record=False)
good = "候选进入 1.0.0" in out and "没有链接" in out
print(("✅ " if good else "❌ ") + next((l.strip() for l in out.splitlines() if "1.0.0 前置" in l), ""))
raise SystemExit(0 if good else 1)
PY
printf '\n\033[1m════ 反向验收汇总 ════\033[0m\n ✅ 通过 %d | ❌ 失败 %d\n' "$pass" "$fail"
[ "$fail" -eq 0 ] || exit 1
[ "$fail" -eq 0 ] || exit 1