99 publish :
1010 runs-on : ubuntu-latest
1111 permissions :
12- contents : read
12+ contents : write
1313 packages : write
1414 steps :
1515 - uses : actions/checkout@v6
16+ with :
17+ fetch-depth : 0
1618
1719 - name : Set up JDK for Maven Central
1820 uses : actions/setup-java@v5
4547 - name : Publish to GitHub Packages
4648 run : mvn --batch-mode deploy -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/${{ github.repository }} -Dcentral.publishing.skip=true
4749 env :
48- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
50+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
51+
52+ - name : Extract version from tag
53+ id : version
54+ run : echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
55+
56+ - name : Extract changelog for version
57+ id : changelog
58+ run : |
59+ # Extract the section for this version from CHANGELOG.md
60+ VERSION="${{ steps.version.outputs.version }}"
61+
62+ # Get changelog content between version headers
63+ CHANGELOG=$(awk "/## \[$VERSION\]/,/## \[/" CHANGELOG.md | sed '1d;$d' | sed '/^$/d')
64+
65+ # If changelog extraction failed, use a default message
66+ if [ -z "$CHANGELOG" ]; then
67+ CHANGELOG="Release version $VERSION
68+
69+ See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/master/CHANGELOG.md) for details."
70+ fi
71+
72+ # Save to output using heredoc to handle multiline content
73+ {
74+ echo 'notes<<EOF'
75+ echo "$CHANGELOG"
76+ echo EOF
77+ } >> $GITHUB_OUTPUT
78+
79+ - name : Create GitHub Release
80+ uses : actions/github-script@v7
81+ with :
82+ github-token : ${{ secrets.GITHUB_TOKEN }}
83+ script : |
84+ const tag = context.ref.replace('refs/tags/', '');
85+ const version = tag.replace('v', '');
86+
87+ await github.rest.repos.createRelease({
88+ owner: context.repo.owner,
89+ repo: context.repo.repo,
90+ tag_name: tag,
91+ name: `Release ${version}`,
92+ body: `${{ steps.changelog.outputs.notes }}`,
93+ draft: false,
94+ prerelease: version.includes('-') || version.includes('alpha') || version.includes('beta') || version.includes('rc')
95+ });
0 commit comments