From 8b7669438512f5e889a5305a926a10ba5ee998cd Mon Sep 17 00:00:00 2001 From: Gonzalo Casas Date: Sat, 7 Nov 2026 23:35:03 +0100 Subject: [PATCH 1/2] Create GitHub Releases from the release workflow The release workflow only published to PyPI, so v2.0.1 and v2.1.0 got tags but no GitHub Release (2.0.0 had been created by hand). After the PyPI upload, extract the version's section from CHANGELOG.rst, convert it to Markdown, and create the release with the sdist/wheel attached and GitHub's generated notes (contributors, full changelog link) appended. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 56 +++++++++++++++++++++++++++++++++++ CHANGELOG.rst | 3 ++ 2 files changed, 59 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a0e7a01..4c9547d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,6 +9,8 @@ jobs: publish-release: name: publish release runs-on: ubuntu-latest + permissions: + contents: write # create the GitHub Release steps: - uses: actions/checkout@v7 with: @@ -45,3 +47,57 @@ jobs: uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 with: password: ${{ secrets.pypi_password }} + - name: 📝 Extract release notes from changelog + env: + VERSION: ${{ github.ref_name }} + run: | + python - <<'PY' + import os + import re + + version = os.environ["VERSION"].lstrip("v") + lines = open("CHANGELOG.rst", encoding="utf-8").read().splitlines() + + # Collect the lines of the "" section (heading underlined with dashes) + section, inside = [], False + for i, line in enumerate(lines): + is_heading = i + 1 < len(lines) and re.fullmatch(r"-{3,}", lines[i + 1]) + if is_heading: + if inside: + break + inside = line.strip() == version + continue + if inside and not re.fullmatch(r"-{3,}", line): + section.append(line) + if not section: + raise SystemExit(f"No section for {version} in CHANGELOG.rst") + + # Convert to Markdown: **Group** -> ## Group (skipping empty groups), + # join wrapped bullet lines, ``code`` -> `code` + groups, current = [], None + for line in section: + m = re.fullmatch(r"\*\*(.+)\*\*", line.strip()) + if m: + current = (m.group(1), []) + groups.append(current) + elif current and line.startswith("* "): + current[1].append(line) + elif current and current[1] and line.startswith(" ") and line.strip(): + current[1][-1] += " " + line.strip() + + out = [] + for title, items in groups: + if items: + out += [f"## {title}", ""] + [i.replace("``", "`") for i in items] + [""] + open("release-notes.md", "w", encoding="utf-8").write("\n".join(out)) + print("\n".join(out)) + PY + - name: 🚀 Create GitHub Release + env: + GH_TOKEN: ${{ github.token }} + run: | + gh release create "${{ github.ref_name }}" dist/* \ + --verify-tag \ + --title "roslibpy ${{ github.ref_name }}" \ + --notes-file release-notes.md \ + --generate-notes diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5dec664..977b2a5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,9 @@ Unreleased **Changed** +* The release workflow now also creates the GitHub Release for each version tag, + with notes taken from this changelog and the built packages attached. + **Fixed** **Deprecated** From f169e3e38d7bc62ace7075e0502ba785cdad6fdb Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Tue, 10 Nov 2026 11:07:54 +0100 Subject: [PATCH 2/2] Move release notes extraction to an invoke task (#166) The changelog to Markdown conversion moves from an inline Python heredoc in release.yml to an `invoke release-notes` task in tasks.py, next to the other changelog tooling. It can now be run locally to preview the notes. The conversion now fails on lines it cannot convert (paragraphs, text outside a group) and on sections without entries, instead of silently dropping them. Nested bullets are kept. The notes are extracted before building and publishing, so a missing or broken changelog section stops the release before it reaches PyPI. Co-authored-by: Claude Opus 5.5 --- .github/workflows/release.yml | 52 ++++--------------------- CHANGELOG.rst | 3 ++ tasks.py | 73 +++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 45 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4c9547d..d7ad903 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -40,6 +40,13 @@ jobs: - name: 💎 Install run: | python -m pip install --no-cache-dir -r requirements-dev.txt + - name: 📝 Extract release notes from changelog + # Before building and publishing, so a missing or malformed changelog + # section fails the release before anything is uploaded to PyPI + env: + TAG: ${{ github.ref_name }} + run: | + invoke release-notes --tag "$TAG" --output release-notes.md - name: 💃 Build release run: | python setup.py clean --all sdist bdist_wheel @@ -47,51 +54,6 @@ jobs: uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 with: password: ${{ secrets.pypi_password }} - - name: 📝 Extract release notes from changelog - env: - VERSION: ${{ github.ref_name }} - run: | - python - <<'PY' - import os - import re - - version = os.environ["VERSION"].lstrip("v") - lines = open("CHANGELOG.rst", encoding="utf-8").read().splitlines() - - # Collect the lines of the "" section (heading underlined with dashes) - section, inside = [], False - for i, line in enumerate(lines): - is_heading = i + 1 < len(lines) and re.fullmatch(r"-{3,}", lines[i + 1]) - if is_heading: - if inside: - break - inside = line.strip() == version - continue - if inside and not re.fullmatch(r"-{3,}", line): - section.append(line) - if not section: - raise SystemExit(f"No section for {version} in CHANGELOG.rst") - - # Convert to Markdown: **Group** -> ## Group (skipping empty groups), - # join wrapped bullet lines, ``code`` -> `code` - groups, current = [], None - for line in section: - m = re.fullmatch(r"\*\*(.+)\*\*", line.strip()) - if m: - current = (m.group(1), []) - groups.append(current) - elif current and line.startswith("* "): - current[1].append(line) - elif current and current[1] and line.startswith(" ") and line.strip(): - current[1][-1] += " " + line.strip() - - out = [] - for title, items in groups: - if items: - out += [f"## {title}", ""] + [i.replace("``", "`") for i in items] + [""] - open("release-notes.md", "w", encoding="utf-8").write("\n".join(out)) - print("\n".join(out)) - PY - name: 🚀 Create GitHub Release env: GH_TOKEN: ${{ github.token }} diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 977b2a5..b9f78d1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,9 @@ Unreleased **Added** +* Added ``invoke release-notes`` task to preview the GitHub Release notes generated + from this changelog. + **Changed** * The release workflow now also creates the GitHub Release for each version tag, diff --git a/tasks.py b/tasks.py index 82faf04..c3a4b44 100644 --- a/tasks.py +++ b/tasks.py @@ -4,6 +4,7 @@ import contextlib import glob import os +import re import sys from shutil import rmtree @@ -157,6 +158,78 @@ def prepare_changelog(ctx): ctx.run('git add CHANGELOG.rst && git commit -m "Prepare changelog for next release"') +def changelog_to_markdown(changelog, version): + """Convert the section of ``version`` in the CHANGELOG.rst text to GitHub Markdown. + + ``**Group**`` lines become ``## Group`` headings (empty groups are skipped), + wrapped bullet lines are joined and ``code`` spans use single backticks. + + Raises ``ValueError`` if the section is missing, has no entries, or contains + a line that cannot be converted, instead of silently dropping content. + """ + lines = changelog.splitlines() + + def is_underline(line): + return re.match(r'-{3,}$', line) is not None + + # Collect the lines of the "" section (heading underlined with dashes) + section, found, inside = [], False, False + for i, line in enumerate(lines): + if i + 1 < len(lines) and is_underline(lines[i + 1]): + if inside: + break + inside = line.strip() == version + found = found or inside + continue + if inside and not is_underline(line): + section.append((i + 1, line)) + if not found: + raise ValueError('No section for {} in CHANGELOG.rst'.format(version)) + + groups, current = [], None + for lineno, line in section: + if not line.strip(): + continue + group = re.match(r'\*\*(.+)\*\*$', line.strip()) + if group: + current = (group.group(1), []) + groups.append(current) + elif current is not None and re.match(r' *[*-] ', line): + # Nested bullets keep their indentation, so Markdown nests them too + current[1].append(line.rstrip()) + elif current is not None and current[1] and line.startswith(' '): + current[1][-1] += ' ' + line.strip() + else: + raise ValueError('CHANGELOG.rst line {}: cannot convert {!r} to release notes; ' + 'expected a **Group** line, a bullet or an indented continuation'.format(lineno, line)) + + out = [] + for title, items in groups: + if items: + out += ['## ' + title, ''] + [item.replace('``', '`') for item in items] + [''] + if not out: + raise ValueError('The {} section of CHANGELOG.rst has no entries'.format(version)) + return '\n'.join(out) + + +@task(help={ + 'tag': 'Version (tag) to get the notes for, e.g. v2.1.0 or 2.1.0.', + 'output': 'File to also write the notes to.'}) +def release_notes(ctx, tag, output=None): + """Prints the GitHub release notes of a version, taken from CHANGELOG.rst.""" + version = tag[1:] if tag.startswith('v') else tag + with open(os.path.join(BASE_FOLDER, 'CHANGELOG.rst'), encoding='utf-8') as changelog: + try: + notes = changelog_to_markdown(changelog.read(), version) + except ValueError as e: + raise Exit(str(e)) + + if output: + with open(output, 'w', encoding='utf-8') as f: + f.write(notes) + print(notes) + + @task(help={ 'release_type': 'Type of release follows semver rules. Must be one of: major, minor, patch.'}) def release(ctx, release_type):