5555
5656 github-release :
5757 name : >-
58- Sign the Python 🐍 distribution 📦 with Sigstore
59- and upload them to GitHub Release
58+ Test GitHub Release Creation with Changelog
6059 needs :
60+ - build
6161 - publish-to-pypi
6262 runs-on : ubuntu-latest
6363
7474 run : |
7575 VERSION=$(grep -m 1 'version = ' pyproject.toml | cut -d '"' -f 2)
7676 echo "VERSION=$VERSION" >> $GITHUB_ENV
77+ - name : Extract changelog notes for current version
78+ id : get_changelog
79+ run : |
80+ VERSION=${{ env.VERSION }}
81+ echo "Extracting changelog for version v$VERSION"
82+
83+ # Find the start of the current version section
84+ START_LINE=$(grep -n "## \[v$VERSION\] - " CHANGELOG.md | cut -d: -f1)
85+
86+ if [ -z "$START_LINE" ]; then
87+ echo "Warning: No changelog entry found for version v$VERSION"
88+ echo "CHANGELOG_NOTES=" >> $GITHUB_ENV
89+ exit 0
90+ fi
91+
92+ # Find the start of the next version section (previous version)
93+ NEXT_VERSION_LINE=$(tail -n +$((START_LINE + 1)) CHANGELOG.md | grep -n "^## \[v.*\] - " | head -1 | cut -d: -f1)
94+
95+ if [ -z "$NEXT_VERSION_LINE" ]; then
96+ # No next version found, extract from current version till end of file
97+ CHANGELOG_CONTENT=$(tail -n +$START_LINE CHANGELOG.md)
98+ else
99+ # Extract content from current version header to before next version
100+ END_LINE=$((START_LINE + NEXT_VERSION_LINE - 1))
101+ CHANGELOG_CONTENT=$(sed -n "$START_LINE,$((END_LINE - 1))p" CHANGELOG.md)
102+ fi
103+
104+ # Clean up the content but preserve the blank line after the header
105+ # First, get the header line and add a blank line after it
106+ HEADER_LINE=$(echo "$CHANGELOG_CONTENT" | head -1)
107+ CONTENT_LINES=$(echo "$CHANGELOG_CONTENT" | tail -n +2 | sed '/^$/d' | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//')
108+
109+ # Combine header + blank line + content
110+ CHANGELOG_CONTENT=$(printf "%s\n\n%s" "$HEADER_LINE" "$CONTENT_LINES")
111+
112+ # Escape for GitHub Actions
113+ echo "CHANGELOG_NOTES<<EOF" >> $GITHUB_ENV
114+ echo "$CHANGELOG_CONTENT" >> $GITHUB_ENV
115+ echo "EOF" >> $GITHUB_ENV
77116 - name : Download all the dists
78117 uses : actions/download-artifact@v4
79118 with :
@@ -88,12 +127,18 @@ jobs:
88127 - name : Create GitHub Release
89128 env :
90129 GITHUB_TOKEN : ${{ github.token }}
91- run : >-
92- gh release create
93- "v$VERSION"
94- --repo "$GITHUB_REPOSITORY"
95- --title "v$VERSION"
96- --notes ""
130+ run : |
131+ if [ -n "$CHANGELOG_NOTES" ]; then
132+ gh release create "v$VERSION" \
133+ --repo "$GITHUB_REPOSITORY" \
134+ --title "v$VERSION" \
135+ --notes "$CHANGELOG_NOTES"
136+ else
137+ gh release create "v$VERSION" \
138+ --repo "$GITHUB_REPOSITORY" \
139+ --title "v$VERSION" \
140+ --notes "Release v$VERSION"
141+ fi
97142 - name : Upload artifact signatures to GitHub Release
98143 env :
99144 GITHUB_TOKEN : ${{ github.token }}
0 commit comments