66 bump :
77 description : ' Version bump type'
88 required : true
9- default : ' patch'
109 type : choice
1110 options :
1211 - patch
1312 - minor
1413 - major
1514 overview :
16- description : ' Overview for the release notes (optional)'
17- required : false
18- type : string
15+ description : ' Release overview (will be placed at top of notes)'
16+ required : true
1917
2018jobs :
2119 release :
22- name : Create Release
20+ name : Create tag and release
2321 runs-on : ubuntu-latest
24- env :
25- NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
26- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2722
2823 steps :
29- - name : Checkout repo
24+ - name : Checkout target branch
3025 uses : actions/checkout@v4
3126 with :
32- fetch-depth : 0
27+ ref : ${{ github.ref_name }}
3328
3429 - name : Set up Node.js
3530 uses : actions/setup-node@v4
3631 with :
37- node-version : 20
32+ node-version : ' 20'
33+
34+ - name : Install dependencies
35+ run : npm ci
3836
39- - name : Configure git
37+ - name : Push version bump and tag
4038 run : |
4139 git config user.name "github-actions"
4240 git config user.email "[email protected] " 41+ npm version ${{ github.event.inputs.bump }} --no-git-tag-version
42+ version=$(jq -r .version package.json)
43+ git add package.json package-lock.json
44+ git commit -m "Bump version to $version"
45+ git tag $version
46+ git push origin ${{ github.ref_name }}
47+ git push origin $version
4348
44- - name : Fetch tags
45- run : git fetch --tags
46-
47- - name : Bump version
49+ - name : Get merged PR titles and format release notes
50+ id : changelog
4851 run : |
49- NEW_VERSION=$(npm version ${{ github.event.inputs.bump }} --no-git-tag-version)
50- echo "VERSION=${NEW_VERSION}" >> $GITHUB_ENV
52+ git fetch --tags
5153
52- - name : Commit and tag version bump
53- run : |
54- git commit -am "Bump version to ${VERSION}"
55- git tag ${VERSION}
56- git push origin HEAD
57- git push origin ${VERSION}
54+ # Get most recent and previous tags
55+ tags=($(git tag --sort=-creatordate))
56+ new_tag="${tags[0]}"
57+ prev_tag="${tags[1]}"
5858
59- - name : Get previous tag
60- id : previous_tag
61- run : |
62- PREV_TAG=$(git tag --sort=-creatordate | grep -v ${VERSION} | head -n 1)
63- echo "PREV_TAG=$PREV_TAG" >> $GITHUB_ENV
64- echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT
59+ if [ -z "$prev_tag" ]; then
60+ echo "Warning: No previous tag found. Skipping full changelog link."
61+ changelog=""
62+ else
63+ changelog="**Full Changelog**: https://github.com/${{ github.repository }}/compare/$prev_tag...$new_tag"
64+ fi
65+
66+ prs=$(gh pr list --state merged --base "${{ github.ref_name }}" --json title,mergedAt --jq '[.[] | select(.mergedAt != null) | .title]')
67+ joined=$(echo "$prs" | jq -r '.[]' | sed 's/^/* /')
6568
66- - name : Generate release notes from merged PRs
67- id : release_notes
68- run : |
69- OVERVIEW="${{ github.event.inputs.overview }}"
70- NOTES=$(git log ${{ env.PREV_TAG }}..HEAD --pretty=format:"* %s" --merges)
71- echo -e "${OVERVIEW}\n\n## What's Changed\n${NOTES}\n\n**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ env.PREV_TAG }}...${{ env.VERSION }}" > release-notes.md
72- cat release-notes.md
7369 echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
74- cat release-notes.md >> $GITHUB_ENV
70+ echo "${{ github.event.inputs.overview }}" >> $GITHUB_ENV
71+ echo "" >> $GITHUB_ENV
72+ echo "## What's Changed" >> $GITHUB_ENV
73+ echo "$joined" >> $GITHUB_ENV
74+ echo "" >> $GITHUB_ENV
75+ echo "$changelog" >> $GITHUB_ENV
7576 echo "EOF" >> $GITHUB_ENV
77+ env :
78+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
7679
77- - name : Create GitHub Release
80+ - name : Create GitHub release
7881 run : |
79- gh release create "${VERSION}" \
80- --title "${VERSION}" \
81- --notes "$(cat release-notes.md)"
82+ git fetch --tags
83+ tag=$(git describe --tags --abbrev=0)
84+ gh release create "$tag" --title "$tag" --notes "${{ env.RELEASE_NOTES }}"
85+ env :
86+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
87+
88+ readme-changelog :
89+ name : Publish changelog to Readme
90+ needs : release
91+ runs-on : ubuntu-latest
92+
93+ steps :
94+ - name : Checkout repo
95+ uses : actions/checkout@v4
96+
97+ - name : Extract release data
98+ id : release_data
99+ run : |
100+ echo "title=${{ github.ref_name }}" >> $GITHUB_OUTPUT
101+ body=$(gh release view ${{ github.ref_name }} --json body --jq .body)
102+ {
103+ echo "body<<EOF"
104+ echo "$body"
105+ echo "EOF"
106+ } >> $GITHUB_OUTPUT
107+ env :
108+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
82109
83110 - name : Publish changelog to Readme
84111 env :
85112 README_API_KEY : ${{ secrets.README_API_KEY }}
86113 run : |
87- jq -n --arg title "Node.js Unified SDK v${VERSION }" \
88- --arg body "$(<release-notes.md) " \
114+ jq -n --arg title "Node.js Unified SDK v${{ steps.release_data.outputs.title } }" \
115+ --arg body "${{ steps.release_data.outputs.body }} " \
89116 '{
90117 title: $title,
91118 content: {
97124 curl --location 'https://api.readme.com/v2/changelogs' \
98125 --header "Authorization: Bearer $README_API_KEY" \
99126 --header 'Content-Type: application/json' \
100- --data @payload.json
127+ --data @payload.json
0 commit comments