Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

fix(release): a tilde fence is a fence, and a tag does not answer for its rc

Soohong Kim1f3e0ace3d94
diff --git a/scripts/release_notes.py b/scripts/release_notes.py
index 9061fbf..13b639e 100644
--- a/scripts/release_notes.py
+++ b/scripts/release_notes.py
@@ -38,6 +38,8 @@ DEFAULT_BRANCH = "main"
ASSET_REF = re.compile(r"(?P<prefix>docs/assets/)?(?P<name>[\w.-]+\.gif)")
# The same path where it is actually a link target: `](path)`, `src="path"`, `href='path'`.
LINK_TARGET = re.compile(r"""(?P<pre>\]\(|(?:src|href)=["'])(?P<path>docs/assets/[\w.-]+\.gif)""")
+# A code fence, either spelling. Only the character that opened one can close it.
+FENCE = re.compile(r"^(?P<marker>`{3,}|~{3,})")
class ReleaseNotesError(RuntimeError):
@@ -52,18 +54,31 @@ def version_of(tag: str) -> str:
def _heading_pattern(version: str) -> re.Pattern[str]:
- # `(?![\w.])` so v2.5.3 does not match the v2.5.30 heading sitting above it.
- return re.compile(rf"^##\s+v{re.escape(version)}(?![\w.])")
+ # `(?![\w.-])` so v2.5.3 matches neither the v2.5.30 heading sitting above it nor a
+ # v2.5.3-rc1 pre-release section: `version_of` accepts a `-` suffix as a tag, so the
+ # heading guard has to refuse one too, or the rc notes become the release page.
+ return re.compile(rf"^##\s+v{re.escape(version)}(?![\w.-])")
def _heading_lines(lines: list[str]) -> list[int]:
- """Indices of real `## ` headings: a `## …` inside a fenced block is code, not a section."""
- fenced = False
+ """Indices of real `## ` headings: a `## …` inside a fenced block is code, not a section.
+
+ Markdown fences both ways, and a block is closed only by the character that opened it:
+ a ``` line inside a `~~~` block is the block's content. Reading one spelling as a fence
+ and the other as prose would keep the rule for quoted shell and drop it for quoted
+ markdown — which is the CHANGELOG entry most likely to contain a `## vX.Y.Z` line.
+ """
+ fence: str | None = None
found: list[int] = []
for i, line in enumerate(lines):
- if line.startswith("```"):
- fenced = not fenced
- elif not fenced and line.startswith("## "):
+ opened = FENCE.match(line)
+ if opened:
+ marker = opened.group("marker")[0]
+ if fence is None:
+ fence = marker
+ elif marker == fence:
+ fence = None
+ elif fence is None and line.startswith("## "):
found.append(i)
return found
@@ -79,7 +94,7 @@ def extract_section(changelog: str, version: str) -> tuple[str, str]:
headings = _heading_lines(lines)
start = next((i for i in headings if pattern.match(lines[i])), None)
if start is None:
- known = [m.group(1) for m in (re.match(r"##\s+(v[\w.]+)", lines[i]) for i in headings) if m]
+ known = [m.group(1) for m in (re.match(r"##\s+(v[\w.-]+)", lines[i]) for i in headings) if m]
raise ReleaseNotesError(
f"CHANGELOG.md has no `## v{version}` section. "
f"Newest sections: {', '.join(known[:5]) or '(none)'}"
diff --git a/tests/release/test_release_notes.py b/tests/release/test_release_notes.py
index 3973e31..54e3876 100644
--- a/tests/release/test_release_notes.py
+++ b/tests/release/test_release_notes.py
@@ -92,6 +92,15 @@ def test_a_version_is_not_matched_by_a_longer_one(tmp_path: Path) -> None:
_render(tmp_path, "v1.3.0", longer)
+def test_a_version_is_not_matched_by_a_pre_release_of_itself(tmp_path: Path) -> None:
+ """`## v1.3.0-rc1` must not answer for tag v1.3.0 — a tag may carry a `-` suffix too."""
+ rc = "# Changelog\n\n## v1.3.0-rc1 - Release candidate\n\n- Not the release's notes.\n"
+ with pytest.raises(release_notes.ReleaseNotesError) as err:
+ _render(tmp_path, "v1.3.0", rc)
+ assert "v1.3.0-rc1" in str(err.value), "name the section that was refused, suffix included"
+ page = _render(tmp_path, "v1.3.0-rc1", rc, with_footer=False)
+ assert page["title"] == "v1.3.0-rc1 - Release candidate", "the rc tag still gets its own section"
+
def test_a_heading_inside_a_fenced_block_is_code_not_a_section(tmp_path: Path) -> None:
"""A `## v1.2.0` line inside a code fence must not cut the section short or answer for a tag."""
@@ -107,6 +116,22 @@ def test_a_heading_inside_a_fenced_block_is_code_not_a_section(tmp_path: Path) -
middle = _render(tmp_path, "v1.2.0", fenced, with_footer=False)
assert middle["body"] == "- The real middle section."
+
+def test_a_tilde_fence_hides_a_heading_the_way_a_backtick_fence_does(tmp_path: Path) -> None:
+ """Quoted markdown uses `~~~` so its own backticks stay readable; it is still a fence."""
+ fenced = (
+ "# Changelog\n\n## v1.3.0 - Newest\n\n"
+ "- The section this release's notes are quoting:\n\n"
+ "~~~md\n## v1.2.0 - not a heading\n~~~\n\n"
+ "- A line after the fence.\n\n"
+ "## v1.2.0 - Middle\n\n- The real middle section.\n"
+ )
+ newest = _render(tmp_path, "v1.3.0", fenced, with_footer=False)
+ assert "A line after the fence." in str(newest["body"])
+ middle = _render(tmp_path, "v1.2.0", fenced, with_footer=False)
+ assert middle["body"] == "- The real middle section."
+
+
def test_a_tag_that_is_not_a_release_tag_is_refused(tmp_path: Path) -> None:
for tag in ("main", "1.3.0", "release-1.3.0"):
with pytest.raises(release_notes.ReleaseNotesError, match="release tag"):