ci(release): tag-driven GitHub Releases from the CHANGELOG

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
This commit is contained in:
Abolfazl Ranjbaran committed 2026-11-26 06:17:02 +00:00
1 parent e610d067ba
commit 0c5e7c4ec1
2 files changed
+79

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
name: Release
# One release = one tag push. Creates (or updates) the GitHub Release
# with the notes extracted from the matching CHANGELOG.md section, so
# the changelog stays the single source of truth. No artifacts are
# attached — images are already on GHCR, benchmark archives live in
# benchmarks/results/.
on:
push:
tags: ["v*"]
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 1
- name: Extract the CHANGELOG section for this tag
env:
TAG: ${{ github.ref_name }}
run: python scripts/extract_release_notes.py "$TAG" > release-notes.md
- name: Show the extracted notes
run: cat release-notes.md
- name: Create (or update) the GitHub Release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
gh release edit "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--title "Sokhan $TAG" \
--notes-file release-notes.md
else
gh release create "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--title "Sokhan $TAG" \
--notes-file release-notes.md
fi
+32
View File
@@ -0,0 +1,32 @@
"""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()