Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

Automatic Changelog in Github Release

Thomas Hebrard6b7db03faa88
diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml
index 2c33cdc21..8912c73e5 100644
--- a/.github/workflows/publish-pypi.yml
+++ b/.github/workflows/publish-pypi.yml
@@ -55,9 +55,9 @@ jobs:
github-release:
name: >-
- Sign the Python 🐍 distribution 📦 with Sigstore
- and upload them to GitHub Release
+ Test GitHub Release Creation with Changelog
needs:
+ - build
- publish-to-pypi
runs-on: ubuntu-latest
@@ -74,6 +74,45 @@ jobs:
run: |
VERSION=$(grep -m 1 'version = ' pyproject.toml | cut -d '"' -f 2)
echo "VERSION=$VERSION" >> $GITHUB_ENV
+ - name: Extract changelog notes for current version
+ id: get_changelog
+ run: |
+ VERSION=${{ env.VERSION }}
+ echo "Extracting changelog for version v$VERSION"
+
+ # Find the start of the current version section
+ START_LINE=$(grep -n "## \[v$VERSION\] - " CHANGELOG.md | cut -d: -f1)
+
+ if [ -z "$START_LINE" ]; then
+ echo "Warning: No changelog entry found for version v$VERSION"
+ echo "CHANGELOG_NOTES=" >> $GITHUB_ENV
+ exit 0
+ fi
+
+ # Find the start of the next version section (previous version)
+ NEXT_VERSION_LINE=$(tail -n +$((START_LINE + 1)) CHANGELOG.md | grep -n "^## \[v.*\] - " | head -1 | cut -d: -f1)
+
+ if [ -z "$NEXT_VERSION_LINE" ]; then
+ # No next version found, extract from current version till end of file
+ CHANGELOG_CONTENT=$(tail -n +$START_LINE CHANGELOG.md)
+ else
+ # Extract content from current version header to before next version
+ END_LINE=$((START_LINE + NEXT_VERSION_LINE - 1))
+ CHANGELOG_CONTENT=$(sed -n "$START_LINE,$((END_LINE - 1))p" CHANGELOG.md)
+ fi
+
+ # Clean up the content but preserve the blank line after the header
+ # First, get the header line and add a blank line after it
+ HEADER_LINE=$(echo "$CHANGELOG_CONTENT" | head -1)
+ CONTENT_LINES=$(echo "$CHANGELOG_CONTENT" | tail -n +2 | sed '/^$/d' | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//')
+
+ # Combine header + blank line + content
+ CHANGELOG_CONTENT=$(printf "%s\n\n%s" "$HEADER_LINE" "$CONTENT_LINES")
+
+ # Escape for GitHub Actions
+ echo "CHANGELOG_NOTES<<EOF" >> $GITHUB_ENV
+ echo "$CHANGELOG_CONTENT" >> $GITHUB_ENV
+ echo "EOF" >> $GITHUB_ENV
- name: Download all the dists
uses: actions/download-artifact@v4
with:
@@ -88,12 +127,18 @@ jobs:
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
- run: >-
- gh release create
- "v$VERSION"
- --repo "$GITHUB_REPOSITORY"
- --title "v$VERSION"
- --notes ""
+ run: |
+ if [ -n "$CHANGELOG_NOTES" ]; then
+ gh release create "v$VERSION" \
+ --repo "$GITHUB_REPOSITORY" \
+ --title "v$VERSION" \
+ --notes "$CHANGELOG_NOTES"
+ else
+ gh release create "v$VERSION" \
+ --repo "$GITHUB_REPOSITORY" \
+ --title "v$VERSION" \
+ --notes "Release v$VERSION"
+ fi
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}