ci: weekly SemVer releases with generated notes; freeze CHANGELOG.md at 1.7.4 (#800)

* ci: publish a weekly SemVer release with GitHub-generated notes

Every Monday at 06:00 UTC the workflow tags master and publishes a GitHub
Release whose notes list the merged PR titles. tools/next_version.py picks the
version from the commits since the last release: type!: or a BREAKING CHANGE
footer is major, feat is minor, anything else is patch. A manual run can
override it. Weeks without commits are skipped, a master commit whose CI did
not pass is never released, and forks never run it.

* docs: point contributors and forks at weekly GitHub Releases

PR titles are now the release notes and their type sets the version, so
CONTRIBUTING and the PR template say so. README and SETUP describe releases
as weekly checkpoints that passed CI instead of pointing at CHANGELOG.md.

* chore(changelog): freeze at 1.7.4 and fail PRs that still edit it

Rolls [Unreleased] into [1.7.4] and rewrites the intro to point at GitHub
Releases. The structure test becomes a content pin: stale PRs carry entries
that git would merge cleanly into the frozen section, so any edit now fails
CI with a pointer to the PR title.

* fix(release): address review findings on the weekly release

Write access moves to the job; the override rejects existing or older
versions; next_version.py reports a missing tag instead of a traceback and
drops the unused rev argument; tests pin the fork guard and SHA-pinned
checkout. The frozen changelog drops the date written ahead of the release,
describes its guard accurately, and the guard skips on forks.

* chore(changelog): re-pin the frozen hash after rebasing onto master

* ci(release): compute the version with commitizen via setup-uv instead of an in-repo script

A week of only docs, chore or ci commits now ships nothing on its own, matching commitizen's conventional-commit bump rules; fix, refactor and perf bump patch.
This commit is contained in:
Jakob Stender Guldberg authored and GitHub committed 2026-10-31 14:28:12 +01:00
1 parent 83c788d779
commit 7f01d75251
9 files changed
+175 -131

No files matched your search

+23 -122
View File
@@ -1,134 +1,35 @@
"""Structural guard for CHANGELOG.md's [Unreleased] section.
"""CHANGELOG.md is frozen at 1.7.4; releases after it are documented in GitHub Releases.
Contributors edit one shared file by hand, and every PR inserts its entry near
the same line. Two failure shapes have reached master or a merge queue:
- a second `### Fixed` heading added directly under `## [Unreleased]` because
the author did not see the existing one further down (#425, fixed by hand at
merge time), and
- entries placed above any `###` heading, or under a heading Keep a Changelog
does not define.
`lint_skills.py` does not read the changelog, so nothing caught either. This
test does, on every PR. It only inspects [Unreleased]; released sections are
history and stay as they are.
Every PR used to add an entry under `## [Unreleased]`, and PRs opened before the
freeze still carry one. Most of those entries sit mid-section, so git merges
them cleanly into the frozen 1.7.4 section - a heading check would not notice.
Pinning the file's content does: any edit fails here and points the author at
the PR title, which is what the release notes are generated from.
"""
import hashlib
import unittest
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
CHANGELOG = REPO / "CHANGELOG.md"
try:
from tests._upstream import is_upstream_checkout
except ImportError: # `python -m unittest discover -s tests` imports test modules top-level
from _upstream import is_upstream_checkout
KNOWN_HEADINGS = {"Added", "Changed", "Deprecated", "Removed", "Fixed", "Security"}
CONFLICT_MARKERS = ("<<<<<<< ", "=======", ">>>>>>> ")
CHANGELOG = Path(__file__).resolve().parent.parent / "CHANGELOG.md"
FROZEN_SHA256 = "5a4f9ce8270ad872a3154fb872a7e287c27023d68a1b58c6415e2ec21b4b3815"
def unreleased_block(text: str) -> str:
"""The lines between `## [Unreleased]` and the next `## [` heading.
An absent heading (right after a release cut) yields an empty block:
nothing to check is not a defect."""
start = text.find("## [Unreleased]")
if start == -1:
return ""
end = text.find("\n## [", start + 1)
return text[start:] if end == -1 else text[start:end]
def unreleased_problems(text: str) -> list[str]:
"""Return a human-readable problem per structural defect in [Unreleased]."""
problems: list[str] = []
seen: list[str] = []
current: str | None = None
for lineno, line in enumerate(unreleased_block(text).splitlines(), 1):
if any(line.startswith(marker) for marker in CONFLICT_MARKERS):
problems.append(f"conflict marker on [Unreleased] line {lineno}: {line.strip()}")
continue
if line.startswith("### "):
name = line[4:].strip()
if name not in KNOWN_HEADINGS:
problems.append(
f"unknown heading '### {name}' in [Unreleased]; use one of {sorted(KNOWN_HEADINGS)}"
)
if name in seen:
problems.append(
f"'### {name}' appears twice in [Unreleased] - fold the entry into the existing section"
)
seen.append(name)
current = name
elif line.startswith("- ") and current is None:
problems.append(f"entry above any '###' heading in [Unreleased]: {line.strip()[:70]}")
return problems
CLEAN = """# Changelog
## [Unreleased]
### Added
- **A new thing** - described.
### Fixed
- **A fixed thing** - described.
## [1.0.0] - 2026-01-01
### Fixed
- old entry
"""
class UnreleasedProblemsTests(unittest.TestCase):
def test_clean_section_reports_nothing(self):
self.assertEqual(unreleased_problems(CLEAN), [])
def test_duplicate_heading_is_reported(self):
# The exact #425 shape: a second "### Fixed" inserted directly under
# [Unreleased], above "### Added", while "### Fixed" already exists below.
text = CLEAN.replace(
"## [Unreleased]\n\n### Added",
"## [Unreleased]\n\n### Fixed\n\n- **Entry in the wrong place** - described.\n\n### Added",
@unittest.skipIf(not is_upstream_checkout(), "the freeze guards the upstream changelog; forks may keep their own")
class FrozenChangelogTests(unittest.TestCase):
def test_changelog_is_unchanged(self):
# Line endings normalized so a CRLF checkout on Windows hashes the same.
content = CHANGELOG.read_bytes().replace(b"\r\n", b"\n")
self.assertEqual(
hashlib.sha256(content).hexdigest(), FROZEN_SHA256,
"CHANGELOG.md is frozen at 1.7.4: drop your edit and describe the change in the PR title "
"instead (release notes are generated from PR titles). A deliberate fix to the frozen text "
"updates FROZEN_SHA256 in the same PR.",
)
problems = unreleased_problems(text)
self.assertTrue(any("Fixed" in p and "twice" in p for p in problems), problems)
def test_unknown_heading_is_reported(self):
text = CLEAN.replace("### Fixed", "### Fixes")
problems = unreleased_problems(text)
self.assertTrue(any("Fixes" in p for p in problems), problems)
def test_entry_above_any_heading_is_reported(self):
text = CLEAN.replace(
"## [Unreleased]\n\n### Added",
"## [Unreleased]\n\n- **Orphan entry** - no heading above it.\n\n### Added",
)
problems = unreleased_problems(text)
self.assertTrue(any("Orphan entry" in p for p in problems), problems)
def test_conflict_markers_are_reported(self):
text = CLEAN.replace("### Fixed", "<<<<<<< HEAD\n### Fixed")
problems = unreleased_problems(text)
self.assertTrue(any("conflict marker" in p for p in problems), problems)
def test_missing_unreleased_section_is_not_a_defect(self):
# Right after a release cut there may be no [Unreleased] heading at all
# (the 1.7.0 cut removed it). Nothing to check is not a failure.
text = "# Changelog\n\n## [1.7.1] - 2026-09-06\n\n### Fixed\n\n- **A fixed thing** - described.\n"
self.assertEqual(unreleased_problems(text), [])
def test_released_sections_are_not_inspected(self):
# A duplicate heading in an old release is history, not a defect here.
text = CLEAN + "\n### Fixed\n\n- another old entry\n"
self.assertEqual(unreleased_problems(text), [])
class RealChangelogTests(unittest.TestCase):
def test_unreleased_section_is_well_formed(self):
text = CHANGELOG.read_text(encoding="utf-8")
self.assertEqual(unreleased_problems(text), [])
if __name__ == "__main__":