Phase C of professionalization round 3: - New Release workflow: pushing a v* tag extracts the matching CHANGELOG.md section (scripts/extract_release_notes.py) and creates or updates the GitHub Release — the changelog stays the single source of truth and releases stop being manual API calls - The extractor fails loudly on a tag without a section, so an unnoticed version mismatch cannot ship empty notes - Tested both paths locally: v1.4.0 yields the full section, a bogus version exits 1 with the hint to add one
33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
"""Extract one version's section from CHANGELOG.md for the release notes.
|
|
|
|
Used by the Release workflow: `python scripts/extract_release_notes.py vX.Y.Z`.
|
|
The changelog is the single source of truth — a tag without a matching
|
|
section fails loudly instead of shipping empty notes.
|
|
"""
|
|
import re
|
|
import sys
|
|
|
|
|
|
def extract(text: str, version: str) -> str:
|
|
# "## [X.Y.Z] - date" (date optional) up to the next "## ["
|
|
pattern = rf"^## \[{re.escape(version)}\][^\n]*\n(.*?)(?=^## \[|\Z)"
|
|
match = re.search(pattern, text, re.MULTILINE | re.DOTALL)
|
|
if not match:
|
|
raise SystemExit(
|
|
f"no CHANGELOG.md section for [{version}] — add one before tagging"
|
|
)
|
|
return match.group(1).strip()
|
|
|
|
|
|
def main() -> None:
|
|
if len(sys.argv) != 2:
|
|
raise SystemExit("usage: extract_release_notes.py vX.Y.Z")
|
|
tag = sys.argv[1]
|
|
version = tag[1:] if tag.startswith("v") else tag
|
|
text = open("CHANGELOG.md", encoding="utf-8").read()
|
|
print(extract(text, version))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|