Skip to content

Commit 95c4759

Browse files
committed
Add dynamic changelog generation for releases
1 parent 5cfba9d commit 95c4759

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

.github/workflows/publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ jobs:
4141
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALUSERNAME }}
4242
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALPASSWORD }}
4343

44+
- name: Get Previous Release Tag
45+
id: get_previous_tag
46+
run: |
47+
# Get the latest release tag (excluding the current one we're about to create)
48+
PREVIOUS_TAG=$(git tag -l --sort=-version:refname | grep -v "^${{ github.event.inputs.versionName }}$" | head -n 1)
49+
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
50+
echo "Previous tag: $PREVIOUS_TAG"
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
4454
- name: Create and push tag
4555
run: |
4656
git config --global user.email "theapache64@gmail.com"
@@ -51,6 +61,25 @@ jobs:
5161
env:
5262
TAG: ${{ github.event.inputs.versionName }}
5363

64+
- name: Generate Changelog
65+
id: generate_changelog
66+
run: |
67+
PREVIOUS_TAG="${{ steps.get_previous_tag.outputs.previous_tag }}"
68+
CURRENT_TAG="${{ github.event.inputs.versionName }}"
69+
70+
if [ -z "$PREVIOUS_TAG" ]; then
71+
echo "No previous tag found. This might be the first release."
72+
CHANGELOG="## What's New\n\nThis is the first release of the project! 🎉\n\n### Changes\n- Initial release\n\n---\n\n**Full Changelog**: https://github.com/${{ github.repository }}/commits/$CURRENT_TAG"
73+
else
74+
echo "Generating changelog from $PREVIOUS_TAG to $CURRENT_TAG"
75+
CHANGELOG="## What's New\n\nSee the changes between [\`$PREVIOUS_TAG\`](https://github.com/${{ github.repository }}/tree/$PREVIOUS_TAG) and [\`$CURRENT_TAG\`](https://github.com/${{ github.repository }}/tree/$CURRENT_TAG)\n\n---\n\n**Full Changelog**: https://github.com/${{ github.repository }}/compare/$PREVIOUS_TAG...$CURRENT_TAG"
76+
fi
77+
78+
# Save changelog to output (properly escaped for GitHub Actions)
79+
echo "changelog<<EOF" >> $GITHUB_OUTPUT
80+
echo -e "$CHANGELOG" >> $GITHUB_OUTPUT
81+
echo "EOF" >> $GITHUB_OUTPUT
82+
5483
- name: Create Release on GitHub
5584
id: create_release
5685
uses: actions/create-release@v1
@@ -59,5 +88,6 @@ jobs:
5988
with:
6089
tag_name: ${{ github.event.inputs.versionName }}
6190
release_name: ${{ github.event.inputs.versionName }}
91+
body: ${{ steps.generate_changelog.outputs.changelog }}
6292
draft: true
6393
prerelease: false

0 commit comments

Comments
 (0)