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()