Peach: Local-first video metadata scraper and media manager.
feat(release): Release 页正文取自 CHANGELOG.md 对应那一节,缺节不发
longmeidaoc8403a878721
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 8bba9f8ca..59af6ea2f 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -65,6 +65,8 @@ jobs:Copy-Item docs/TESTING_DESKTOP.md dist/Peach/开始使用.mdCompress-Archive -Path dist/Peach -DestinationPath 'release/Peach-${{ steps.version.outputs.version }}-windows-x64.zip'Copy-Item scripts/smoke_desktop.py release/smoke_desktop.py+ python scripts/changelog.py --notes '${{ steps.version.outputs.version }}' --to release/RELEASE_NOTES.md+ if ($LASTEXITCODE -ne 0) { throw 'CHANGELOG.md 缺这一版的一节,不发没有说明的版本' }- uses: actions/upload-artifact@v7with:name: desktop-candidate@@ -108,4 +110,4 @@ jobs:run: |cd releasesha256sum *.zip > SHA256SUMS.txt- gh release create "$GITHUB_REF_NAME" *.zip SHA256SUMS.txt --verify-tag --prerelease --title "Peach $VERSION · Windows 测试版" --notes 'Windows x64 独立测试包。完整解压后双击 Peach.exe,选择媒体文件夹即可开始。本机使用;无需 Python、Git 或 Node。FFmpeg 需另装,未安装时不提供转码与缩略图。配置和日志入口见程序内「配置 Peach」。macOS 请按 README 使用源码安装。'+ gh release create "$GITHUB_REF_NAME" *.zip SHA256SUMS.txt --verify-tag --prerelease --title "Peach $VERSION · Windows 测试版" --notes-file RELEASE_NOTES.mddiff --git a/docs/adr/0012-version-and-update-boundary.md b/docs/adr/0012-version-and-update-boundary.mdindex 980737f15..c19e3dde1 100644--- a/docs/adr/0012-version-and-update-boundary.md+++ b/docs/adr/0012-version-and-update-boundary.md@@ -71,6 +71,9 @@ patch,功能与修复被记成同一档,一天之内从 0.7.24 走到 0.7.27入口。同一个版本号下会有很多个构建,只比版本号证明不了二进制换掉了。- 发布必须带变更日志。`CHANGELOG.md` 按 Keep a Changelog 1.1.0 维护,`--bump --apply` 把未发布节定版成新版本号并落盘、不提交;`--apply` 打标签前要求这一节存在。+- Release 页的正文就是那一节加一段安装提示,由工作流在标签提交上用 `changelog.py --notes`+ 生成;缺那一节就不发,不拿固定文案顶替。使用者只读 Release 页,日志写在仓库里而+ 没送到那里,等于没写。- 整条发布链上只留一个需要人判断的点:那一节的措辞对不对。`--bump --apply` 把它原样带在输出里,确认之后 `--ship --apply` 一次做完提交、推送、等 Test 转绿、打标签。判据仍由脚本挡——不在 master、缺那一节、标签被占、工作区夹带别的改动都拒绝,Test 没绿绝不打标签——@@ -83,8 +86,8 @@ patch,功能与修复被记成同一档,一天之内从 0.7.24 走到 0.7.27由 GitHub 预发布标记、README 的 pre-1.0 与托盘的更新通道表达,不写进版本号。- 已发的 tag 与已占用的版本号一律不动:SemVer 第 2 条要求版本号只增,第 3 条要求已发布的内容不可再改。`0.28`–`0.29` 这些没有制品的号码就此空掉,下一次发布从当前 `__version__`- 往上推。`CHANGELOG.md` 补记的是已有制品的那几个版本,不重编号、不改 tag、不改已发布的- Release 说明。+ 往上推。`CHANGELOG.md` 补记的是已有制品的那几个版本,不重编号、不改 tag、不换制品;+ 已发布 Release 的正文可以补成 `CHANGELOG.md` 对应那一节,说明文字不是发布物的一部分。## 1.0 门槛(2026-09-07)diff --git a/scripts/changelog.py b/scripts/changelog.pyindex 4cb2c6758..741868c3f 100644--- a/scripts/changelog.py+++ b/scripts/changelog.py@@ -14,6 +14,7 @@ Semantic Versioning 2.0.0(https://semver.org/lang/zh-CN/spec/v2.0.0.html):python scripts/changelog.py # 起草未发布区间python scripts/changelog.py --range v0.16.0..v0.27.1 # 起草任意区间python scripts/changelog.py --release 0.30.0 --apply # 把未发布节定版为 0.30.0+ python scripts/changelog.py --notes 0.30.0 --to NOTES.md # 生成这一版的 Release 正文"""from __future__ import annotations@@ -36,6 +37,12 @@ CHANGELOG = "CHANGELOG.md"#: 未发布节的标题。Keep a Changelog 要求它常驻,让人随时知道主线上攒了什么。UNRELEASED = "未发布"+#: Release 页正文里跟在变更日志后面的安装提示。每一版都一样,所以只写在这里一处,+#: 工作流不再自己抄一份。+INSTALL_NOTE = ("Windows x64 独立测试包。完整解压后双击 Peach.exe,选择媒体文件夹即可开始。"+ "本机使用;无需 Python、Git 或 Node。FFmpeg 需另装,未安装时不提供转码与"+ "缩略图。配置和日志入口见程序内「配置 Peach」。macOS 请按 README 使用源码安装。")+#: Conventional Commits 的主题形状:`type(scope)!: 描述`。SUBJECT = re.compile(r"^(?P<type>[a-z]+)(?:\((?P<scope>[^)]*)\))?(?P<bang>!)?:\s*(?P<text>.+)$")@@ -220,6 +227,18 @@ def section_of(document: str, version: str) -> str:return found["body"].strip("\n") if found else ""+def notes(document: str, version: str) -> str:+ """Release 页的正文:这一版在 `CHANGELOG.md` 里的那一节,后面跟安装提示。++ 使用者在 GitHub 上读到的就是这段,所以那一节缺了不能静默发一段固定文案顶上,+ 直接拒绝,让发布链停在这里。+ """+ section = section_of(document, version)+ if not section:+ raise version_bump.VersionError(f"{CHANGELOG} 里没有 {version} 这一节,Release 正文无从生成")+ return f"{section}\n\n{INSTALL_NOTE}\n"++def promote(document: str, version: str, *, date: str, repo: str, previous: str | None,fallback: str = "") -> str:"""把未发布节定版成 `version` 一节,并在它上面留一个空的未发布节。@@ -268,8 +287,17 @@ def main(argv=None) -> int:parser.add_argument("--range", dest="spec", help="提交区间,默认上一个版本标签到 HEAD")parser.add_argument("--release", help=f"把{UNRELEASED}节定版成这个版本号")parser.add_argument("--apply", action="store_true", help=f"写进 {CHANGELOG}")+ parser.add_argument("--notes", metavar="VERSION", help="输出这一版的 Release 正文")+ parser.add_argument("--to", metavar="PATH", help="把 --notes 的正文以 UTF-8 写进这个文件")args = parser.parse_args(argv)try:+ if args.notes:+ text = notes((ROOT / CHANGELOG).read_text(encoding="utf-8"), args.notes)+ if args.to:+ Path(args.to).write_bytes(text.encode("utf-8"))+ else:+ print(text, end="")+ return 0spec = args.spec or version_bump.release_range(ROOT)if not args.apply:heading = args.release or UNRELEASEDdiff --git a/tests/test_changelog.py b/tests/test_changelog.pyindex d5289aa23..4708d0320 100644--- a/tests/test_changelog.py+++ b/tests/test_changelog.py@@ -167,6 +167,26 @@ class SectionTests(unittest.TestCase):self.assertEqual(changelog.section_of(DOCUMENT, "0.28.0"), "")+class NotesTests(unittest.TestCase):+ """Release 页正文:那一节原文加安装提示,缺那一节就拒绝。"""++ def test_the_notes_are_the_section_followed_by_the_install_note(self):+ self.assertEqual(changelog.notes(DOCUMENT, "0.27.1"),+ f"第四个预发布。\n\n{changelog.INSTALL_NOTE}\n")++ def test_a_version_without_a_section_cannot_be_released(self):+ with self.assertRaisesRegex(VersionError, "0.28.0"):+ changelog.notes(DOCUMENT, "0.28.0")++ def test_the_release_workflow_reads_the_notes_it_does_not_inline_them(self):+ """固定文案只活在 `INSTALL_NOTE` 一处;工作流在标签提交上生成文件再交给 gh。"""+ workflow = (Path(changelog.ROOT) / ".github/workflows/release.yml").read_text(encoding="utf-8")+ self.assertIn("scripts/changelog.py --notes", workflow)+ self.assertIn("--to release/RELEASE_NOTES.md", workflow)+ self.assertIn("--notes-file RELEASE_NOTES.md", workflow)+ self.assertNotIn("--notes 'Windows", workflow)++class DueTests(unittest.TestCase):"""该不该发下一版。判据只看使用者那一侧,不看集成了多少次。"""