From 0c5e7c4ec1dfe4933c46af12dca484141c0f912e Mon Sep 17 00:00:00 2001 From: Abolfazl Ranjbaran <206173650+Abolfazlrwm@users.noreply.github.com> Date: Thu, 26 Nov 2026 06:17:02 +0000 Subject: [PATCH] ci(release): tag-driven GitHub Releases from the CHANGELOG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .github/workflows/release.yml | 47 ++++++++++++++++++++++++++++++++ scripts/extract_release_notes.py | 32 ++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 scripts/extract_release_notes.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c37df78 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/scripts/extract_release_notes.py b/scripts/extract_release_notes.py new file mode 100644 index 0000000..5060c1f --- /dev/null +++ b/scripts/extract_release_notes.py @@ -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()