1+ name : Release
2+
13on :
4+ workflow_dispatch :
5+ inputs :
6+ bump :
7+ description : ' Version bump type'
8+ required : true
9+ type : choice
10+ options :
11+ - patch
12+ - minor
13+ - major
14+ overview :
15+ description : ' Release overview (will be placed at top of notes)'
16+ required : true
17+
18+ jobs :
219 release :
3- types :
4- - published
20+ runs-on : ubuntu-latest
521
6- name : release
22+ steps :
23+ - name : Checkout target branch
24+ uses : actions/checkout@v4
25+ with :
26+ ref : ${{ github.ref_name }}
27+
28+ - name : Set up Node.js
29+ uses : actions/setup-node@v4
30+ with :
31+ node-version : ' 20'
32+
33+ - name : Install dependencies
34+ run : npm ci
35+
36+ - name : Push version bump and tag
37+ run : |
38+ git config user.name "github-actions"
39+ git config user.email "[email protected] " 40+ npm version ${{ github.event.inputs.bump }} --no-git-tag-version
41+ version=$(jq -r .version package.json)
42+ git add package.json package-lock.json
43+ git commit -m "Bump version to $version"
44+ git tag $version
45+ git push origin ${{ github.ref_name }}
46+ git push origin $version
47+
48+ - name : Get merged PR titles and format release notes
49+ id : changelog
50+ run : |
51+ git fetch --tags
52+
53+ # Get most recent and previous tags
54+ tags=($(git tag --sort=-creatordate))
55+ new_tag="${tags[0]}"
56+ prev_tag="${tags[1]}"
57+
58+ if [ -z "$prev_tag" ]; then
59+ echo "Warning: No previous tag found. Skipping full changelog link."
60+ changelog=""
61+ else
62+ changelog="**Full Changelog**: https://github.com/${{ github.repository }}/compare/$prev_tag...$new_tag"
63+ fi
64+
65+ prs=$(gh pr list --state merged --base "${{ github.ref_name }}" --json title,mergedAt --jq '[.[] | select(.mergedAt != null) | .title]')
66+ joined=$(echo "$prs" | jq -r '.[]' | sed 's/^/* /')
67+
68+ echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
69+ echo "${{ github.event.inputs.overview }}" >> $GITHUB_ENV
70+ echo "" >> $GITHUB_ENV
71+ echo "## What's Changed" >> $GITHUB_ENV
72+ echo "$joined" >> $GITHUB_ENV
73+ echo "" >> $GITHUB_ENV
74+ echo "$changelog" >> $GITHUB_ENV
75+ echo "EOF" >> $GITHUB_ENV
76+ env :
77+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
78+
79+ - name : Create GitHub release
80+ run : |
81+ git fetch --tags
82+ tag=$(git describe --tags --abbrev=0)
83+ gh release create "$tag" --title "$tag" --notes "${{ env.RELEASE_NOTES }}"
84+ env :
85+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
786
8- jobs :
987 readme-changelog :
1088 name : Publish changelog to Readme
89+ needs : release
1190 runs-on : ubuntu-latest
91+
1292 steps :
1393 - name : Extract release data
1494 id : release
1595 run : |
16- echo "title=${{ github.event.release.name }}" >> $GITHUB_OUTPUT
96+ echo "title=${{ github.ref_name }}" >> $GITHUB_OUTPUT
97+ body=$(gh release view ${{ github.ref_name }} --json body --jq .body)
1798 {
1899 echo "body<<EOF"
19- echo "${{ github.event.release. body }} "
100+ echo "$body"
20101 echo "EOF"
21102 } >> $GITHUB_OUTPUT
103+ env :
104+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
22105
23106 - name : Install jq
24107 run : sudo apt-get update && sudo apt-get install -y jq
40123 curl --location 'https://api.readme.com/v2/changelogs' \
41124 --header "Authorization: Bearer $README_API_KEY" \
42125 --header 'Content-Type: application/json' \
43- --data @payload.json
126+ --data @payload.json
0 commit comments