Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

feat(release): 更新日志条目限一句话,Release 标题只写标签并附完整变更链接

longmeidao9c563eca8ecf
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index d80e057d0..c7157c6f4 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -428,13 +428,12 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
- VERSION: ${{ github.ref_name }}
run: |
cd release
tail -n +4 ../macos-candidates/scripts/MACOS_DOWNLOADS.md >> RELEASE_NOTES.md
files=(./*.zip ./*-setup.exe ./*.dmg SHA256SUMS.txt)
if [ -f SHA256SUMS.txt.sig ]; then files+=(SHA256SUMS.txt.sig); fi
- gh release create "$GITHUB_REF_NAME" "${files[@]}" --verify-tag --prerelease --title "Peach ${VERSION#v} · Windows / macOS 测试版" --notes-file RELEASE_NOTES.md
+ gh release create "$GITHUB_REF_NAME" "${files[@]}" --verify-tag --prerelease --title "$GITHUB_REF_NAME" --notes-file RELEASE_NOTES.md
# Sparkle 更新源(ADR-0130):Release 公开之后才写 appcast,下载地址指向同一 Release 的 DMG。
# 私钥只在这一个仅标签运行的作业里经标准输入交给官方工具;仓库变量未开启时整个作业跳过。
diff --git a/scripts/changelog.py b/scripts/changelog.py
index 9f55a8e7c..a00c260c0 100644
--- a/scripts/changelog.py
+++ b/scripts/changelog.py
@@ -86,6 +86,9 @@ DUE_ENTRIES = 10
#: 这个清单是封闭的:`tests/test_changelog.py` 拒绝清单外的标签,免得各写一套近义词。
AREAS = ("界面", "播放", "馆藏", "采集", "复核", "关注", "配置", "更新", "桌面", "账本")
+#: 定版条目标签之后的字数上限。条目给使用者扫读:一句话说清在哪儿变了什么,原因和实现细节留在提交与 PR。
+ENTRY_LIMIT = 80
+
#: scope 到区域标签的映射,只收没有歧义的。`web` 故意不映射——它占了近八成提交,
#: 机械挂上「界面」等于给每条都贴同一个标签,标签就不再有区分力,留给人按条目内容定。
AREA_BY_SCOPE = {
@@ -230,29 +233,44 @@ def section_of(document: str, version: str) -> str:
def require_labeled_entries(document: str, version: str) -> None:
- """定版条目必须使用封闭的中文区域标签,不能把提交 scope 直接发给使用者。"""
- section = section_of(document, version)
+ """定版条目必须使用封闭的中文区域标签,不能把提交 scope 直接发给使用者;
+ 全部已发布版本的条目都不超过 `ENTRY_LIMIT` 字,改旧版本时也守住。"""
allowed = "|".join(re.escape(area) for area in AREAS)
labeled = re.compile(rf"^- \*\*(?:{allowed})\*\*:")
- invalid = [line for line in section.splitlines()
- if line.startswith("- ") and labeled.match(line) is None]
+ entries = [line for line in section_of(document, version).splitlines() if line.startswith("- ")]
+ invalid = [line for line in entries if labeled.match(line) is None]
if invalid:
preview = ";".join(invalid[:3])
remainder = f"(另有 {len(invalid) - 3} 条)" if len(invalid) > 3 else ""
raise version_bump.VersionError(
f"{CHANGELOG} 的 {version} 一节还有未归类条目:{preview}{remainder}")
+ # 按读到的字数算:标签与链接地址不算,链接只计显示的文字。
+ label = re.compile(r"^- (?:\*\*[^*]+\*\*:)?")
+ long = [(released, line)
+ for released in re.findall(r"^## \[(\d+\.\d+\.\d+)\]", document, re.M)
+ for line in section_of(document, released).splitlines()
+ if line.startswith("- ")
+ and len(re.sub(r"\[([^\]]*)\]\([^)]*\)", r"\1", label.sub("", line))) > ENTRY_LIMIT]
+ if long:
+ preview = ";".join(f"{released}:{line[:40]}…" for released, line in long[:3])
+ remainder = f"(另有 {len(long) - 3} 条)" if len(long) > 3 else ""
+ raise version_bump.VersionError(
+ f"{CHANGELOG} 有条目超过 {ENTRY_LIMIT} 字,改成一句话:{preview}{remainder}")
def notes(document: str, version: str) -> str:
- """Release 页的正文:这一版在 `CHANGELOG.md` 里的那一节,后面跟安装提示。
+ """Release 页的正文:这一版在 `CHANGELOG.md` 里的那一节、到上一版的完整变更链接,后面跟安装提示。
- 使用者在 GitHub 上读到的就是这段,所以那一节缺了不能静默发一段固定文案顶上,
+ 使用者在 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"
+ link = re.search(rf"^\[{re.escape(version)}\]:\s*(\S+)\s*$", document, re.M)
+ if link is None:
+ raise version_bump.VersionError(f"{CHANGELOG} 底部缺少 `[{version}]:` 链接,Release 正文无从附上完整变更")
+ return f"{section}\n\n[Full Changelog / 完整变更]({link[1]})\n\n{INSTALL_NOTE}\n"
def promote(document: str, version: str, *, date: str, repo: str, previous: str | None,
diff --git a/scripts/publish_gitlab_release.py b/scripts/publish_gitlab_release.py
index f7f789edf..74f71564b 100644
--- a/scripts/publish_gitlab_release.py
+++ b/scripts/publish_gitlab_release.py
@@ -111,7 +111,7 @@ def publish(root: Path = Path('release')) -> None:
raise ValueError("缺少发行说明")
command = [os.environ.get("PEACH_GLAB", "glab"), "release", "create", tag,
"--repo", os.environ["CI_PROJECT_URL"], "--ref", sha,
- "--name", f"Peach {tag[1:]} · Windows / macOS 测试版",
+ "--name", tag,
"--notes-file", str(notes), "--no-close-milestone"]
backend = os.environ.get("PEACH_DOWNLOAD_BACKEND", "gitgud")
if backend in {"r2", "both"}:
diff --git a/tests/test_changelog.py b/tests/test_changelog.py
index 862de4ad9..e92f0a513 100644
--- a/tests/test_changelog.py
+++ b/tests/test_changelog.py
@@ -177,18 +177,43 @@ class SectionTests(unittest.TestCase):
labeled = raw.replace("web:", "**界面**:")
changelog.require_labeled_entries(labeled, "0.8.0")
+ def test_a_release_refuses_an_entry_longer_than_one_sentence(self):
+ """条目给使用者扫读:标签之后超过上限就拒绝定版,正好到上限的照常通过。"""
+ head = "## [0.8.0] - 2026-09-19\n\n### 修复\n\n- **界面**:"
+ changelog.require_labeled_entries(head + "字" * changelog.ENTRY_LIMIT + "\n", "0.8.0")
+ with self.assertRaisesRegex(VersionError, f"超过 {changelog.ENTRY_LIMIT} 字"):
+ changelog.require_labeled_entries(head + "字" * (changelog.ENTRY_LIMIT + 1) + "\n", "0.8.0")
+ # 链接地址读者看不到,只计显示的文字。
+ linked = "字" * (changelog.ENTRY_LIMIT - 2) + "[说明](docs/DOCKER.md#一键更新可选-watchtower)"
+ changelog.require_labeled_entries(head + linked + "\n", "0.8.0")
+
+ def test_an_overlong_entry_in_an_older_release_also_blocks_the_release(self):
+ """旧版本改写时也守住上限:任一已发布版本有超长条目,新版本就不能定版;旧版本没有标签也照样按字数算。"""
+ current = "## [0.8.0] - 2026-09-19\n\n### 修复\n\n- **界面**:修好一处界面。\n\n"
+ older = "## [0.7.0] - 2026-09-01\n\n### 修复\n\n- " + "字" * (changelog.ENTRY_LIMIT + 1) + "\n"
+ with self.assertRaisesRegex(VersionError, "0.7.0:"):
+ changelog.require_labeled_entries(current + older, "0.8.0")
+ changelog.require_labeled_entries(current + older.replace("字", "", 1), "0.8.0")
+
class NotesTests(unittest.TestCase):
- """Release 页正文:那一节原文加安装提示,缺那一节就拒绝。"""
+ """Release 页正文:那一节原文、到上一版的完整变更链接、安装提示;缺那一节或链接就拒绝。"""
- def test_the_notes_are_the_section_followed_by_the_install_note(self):
+ def test_the_notes_are_the_section_its_full_changelog_and_the_install_note(self):
self.assertEqual(changelog.notes(DOCUMENT, "0.27.1"),
- f"第四个预发布。\n\n{changelog.INSTALL_NOTE}\n")
+ "第四个预发布。\n\n[Full Changelog / 完整变更]"
+ "(https://github.com/owner/repo/releases/tag/v0.27.1)\n\n"
+ f"{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_a_section_without_its_link_cannot_be_released(self):
+ unlinked = DOCUMENT.replace("[0.27.1]: https://github.com/owner/repo/releases/tag/v0.27.1\n", "")
+ with self.assertRaisesRegex(VersionError, r"\[0\.27\.1\]:"):
+ changelog.notes(unlinked, "0.27.1")
+
def test_the_command_line_names_what_it_failed_to_produce(self):
"""`--notes` 失败说的是 Release 正文,不借用定版那条「变更日志未更新」。"""
with tempfile.TemporaryDirectory() as folder: