11name : Create Release
22
33on :
4- workflow_dispatch :
5- push :
6- tags :
7- - ' v*'
4+ workflow_dispatch :
5+ push :
6+ tags :
7+ - ' v*'
88
99permissions :
10- contents : write
10+ contents : write
1111
1212jobs :
13- release :
14- runs-on : ubuntu-latest
15-
16- steps :
17- - name : Checkout code
18- uses : actions/checkout@v4
19- with :
20- fetch-depth : 0
21-
22- - name : Get current tag
23- id : currenttag
24- run : |
25- CURRENT_TAG=$(git tag --sort=-version:refname | head -1)
26- echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
27- echo "Current tag: $CURRENT_TAG"
28-
29- - name : Get previous tag
30- id : previoustag
31- run : |
32- PREVIOUS_TAG=$(git tag --sort=-version:refname | sed -n '2p')
33- PREVIOUS_TAG=${PREVIOUS_TAG//+/}
34- echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
35- echo "Previous tag: $PREVIOUS_TAG"
36-
37- - name : Generate categorized release notes
38- id : release_notes
39- run : |
40- CURRENT_TAG=${{ steps.currenttag.outputs.current_tag }}
41- PREVIOUS_TAG=${{ steps.previoustag.outputs.previous_tag }}
42-
43- echo "Generating release notes from $PREVIOUS_TAG to $CURRENT_TAG"
44-
45- # Get commit hashes
46- if [ -z "$PREVIOUS_TAG" ]; then
47- HASHES=$(git log --pretty=format:"%H" $CURRENT_TAG)
48- else
49- HASHES=$(git log --pretty=format:"%H" $PREVIOUS_TAG..$CURRENT_TAG)
50- fi
51-
52- # Categorize commits
53- FEATURES=""
54- FIXES=""
55- DOCS=""
56- CHORES=""
57- BREAKING=""
58- OTHERS=""
59-
60- # Process each commit individually
61- while read -r hash; do
62- # Get the full message and short hash separately
63- message=$(git log --format=%s -n 1 $hash)
64- short_hash=$(git log --format=%h -n 1 $hash)
65-
66- # Trim whitespace
67- message=$(echo "$message" | xargs)
68- short_hash=$(echo "$short_hash" | xargs)
69-
70- echo "Processing: '$message' ($short_hash)"
71-
72- # Extract clean message
73- clean_message="$message"
74- if [[ "$message" =~ ^[a-z]+: ]]; then
75- clean_message="${message#*: }"
76- fi
77-
78- case "$message" in
79- feat:*|feat\(*|feature:*)
80- FEATURES="${FEATURES}- feat: [${clean_message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
81- ;;
82- fix:*|fix\(*)
83- FIXES="${FIXES}- fix: [${clean_message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
84- ;;
85- docs:*|docs\(*)
86- DOCS="${DOCS}- docs: [${clean_message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
87- ;;
88- chore:*|chore\(*|ci:*|ci\(*|build:*|build\(*)
89- CHORES="${CHORES}- chore: [${clean_message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
90- ;;
91- *BREAKING*|*breaking*|*!:*)
92- BREAKING="${BREAKING}- breaking change: [${message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
93- ;;
94- *)
95- OTHERS="${OTHERS}- [${message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
96- ;;
97- esac
98- done <<< "$HASHES"
99-
100- # Build release notes (same as before)
101- NOTES="## Release $CURRENT_TAG"$'\n\n'
102-
103- if [ -n "$BREAKING" ]; then
104- NOTES="${NOTES}### ⚠️ Breaking Changes"$'\n'"$(echo -e "$BREAKING")"$'\n'
105- fi
106-
107- if [ -n "$FEATURES" ]; then
108- NOTES="${NOTES}### ✨ Features"$'\n'"$(echo -e "$FEATURES")"$'\n'
109- fi
110-
111- if [ -n "$FIXES" ]; then
112- NOTES="${NOTES}### 🐛 Bug Fixes"$'\n'"$(echo -e "$FIXES")"$'\n'
113- fi
114-
115- if [ -n "$DOCS" ]; then
116- NOTES="${NOTES}### 📚 Documentation"$'\n'"$(echo -e "$DOCS")"$'\n'
117- fi
118-
119- if [ -n "$CHORES" ]; then
120- NOTES="${NOTES}### 🔧 Maintenance"$'\n'"$(echo -e "$CHORES")"$'\n'
121- fi
122-
123- if [ -n "$OTHERS" ]; then
124- NOTES="${NOTES}### 📦 Other Changes"$'\n'"$(echo -e "$OTHERS")"$'\n'
125- fi
126-
127- if [ -n "$PREVIOUS_TAG" ]; then
128- NOTES="${NOTES}"$'\n'"**Full Changelog**: https://github.com/${{ github.repository }}/compare/$PREVIOUS_TAG...$CURRENT_TAG"
129- fi
130-
131- {
132- echo "notes<<EOF"
133- echo "$NOTES"
134- echo "EOF"
135- } >> $GITHUB_OUTPUT
136-
137- - name : Create Release
138- uses : softprops/action-gh-release@v2.5.0
139- with :
140- name : Release ${{ steps.currenttag.outputs.current_tag }}
141- body : ${{ steps.release_notes.outputs.notes }}
142- draft : false
143- generate_release_notes : false
144- tag_name : ${{ steps.currenttag.outputs.current_tag }}
145- prerelease : ${{ contains(steps.currenttag.outputs.current_tag, 'alpha') || contains(steps.currenttag.outputs.current_tag, 'beta') || contains(steps.currenttag.outputs.current_tag, 'rc') }}
146- token : ${{ secrets.GITHUB_TOKEN }}
13+ release :
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - name : Checkout code
18+ uses : actions/checkout@v4
19+ with :
20+ fetch-depth : 0
21+
22+ - name : Get current tag
23+ id : currenttag
24+ run : |
25+ CURRENT_TAG=$(git tag --sort=-version:refname | head -1)
26+ echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
27+ echo "Current tag: $CURRENT_TAG"
28+
29+ - name : Get previous tag
30+ id : previoustag
31+ run : |
32+ PREVIOUS_TAG=$(git tag --sort=-version:refname | sed -n '2p')
33+ PREVIOUS_TAG=${PREVIOUS_TAG//+/}
34+ echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
35+ echo "Previous tag: $PREVIOUS_TAG"
36+
37+ - name : Generate categorized release notes
38+ id : release_notes
39+ run : |
40+ CURRENT_TAG=${{ steps.currenttag.outputs.current_tag }}
41+ PREVIOUS_TAG=${{ steps.previoustag.outputs.previous_tag }}
42+
43+ echo "Generating release notes from $PREVIOUS_TAG to $CURRENT_TAG"
44+
45+ # Get commit hashes
46+ if [ -z "$PREVIOUS_TAG" ]; then
47+ HASHES=$(git log --pretty=format:"%H" $CURRENT_TAG)
48+ else
49+ HASHES=$(git log --pretty=format:"%H" $PREVIOUS_TAG..$CURRENT_TAG)
50+ fi
51+
52+ # Categorize commits
53+ FEATURES=""
54+ FIXES=""
55+ DOCS=""
56+ CHORES=""
57+ BREAKING=""
58+ OTHERS=""
59+
60+ # Process each commit individually
61+ while read -r hash; do
62+ # Get the full message and short hash separately
63+ message=$(git log --format=%s -n 1 $hash)
64+ short_hash=$(git log --format=%h -n 1 $hash)
65+
66+ # Trim whitespace
67+ message=$(echo "$message" | xargs)
68+ short_hash=$(echo "$short_hash" | xargs)
69+
70+ echo "Processing: '$message' ($short_hash)"
71+
72+ # Extract clean message
73+ clean_message="$message"
74+ if [[ "$message" =~ ^[a-z]+: ]]; then
75+ clean_message="${message#*: }"
76+ fi
77+
78+ case "$message" in
79+ feat:*|feat\(*|feature:*)
80+ FEATURES="${FEATURES}- feat: [${clean_message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
81+ ;;
82+ fix:*|fix\(*)
83+ FIXES="${FIXES}- fix: [${clean_message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
84+ ;;
85+ docs:*|docs\(*)
86+ DOCS="${DOCS}- docs: [${clean_message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
87+ ;;
88+ chore:*|chore\(*|ci:*|ci\(*|build:*|build\(*)
89+ CHORES="${CHORES}- chore: [${clean_message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
90+ ;;
91+ *BREAKING*|*breaking*|*!:*)
92+ BREAKING="${BREAKING}- breaking change: [${message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
93+ ;;
94+ *)
95+ OTHERS="${OTHERS}- [${message}](https://github.com/${{ github.repository }}/commit/${short_hash})\n"
96+ ;;
97+ esac
98+ done <<< "$HASHES"
99+
100+ # Build release notes (same as before)
101+ NOTES="## Release $CURRENT_TAG"$'\n\n'
102+
103+ if [ -n "$BREAKING" ]; then
104+ NOTES="${NOTES}### ⚠️ Breaking Changes"$'\n'"$(echo -e "$BREAKING")"$'\n'
105+ fi
106+
107+ if [ -n "$FEATURES" ]; then
108+ NOTES="${NOTES}### ✨ Features"$'\n'"$(echo -e "$FEATURES")"$'\n'
109+ fi
110+
111+ if [ -n "$FIXES" ]; then
112+ NOTES="${NOTES}### 🐛 Bug Fixes"$'\n'"$(echo -e "$FIXES")"$'\n'
113+ fi
114+
115+ if [ -n "$DOCS" ]; then
116+ NOTES="${NOTES}### 📚 Documentation"$'\n'"$(echo -e "$DOCS")"$'\n'
117+ fi
118+
119+ if [ -n "$CHORES" ]; then
120+ NOTES="${NOTES}### 🔧 Maintenance"$'\n'"$(echo -e "$CHORES")"$'\n'
121+ fi
122+
123+ if [ -n "$OTHERS" ]; then
124+ NOTES="${NOTES}### 📦 Other Changes"$'\n'"$(echo -e "$OTHERS")"$'\n'
125+ fi
126+
127+ if [ -n "$PREVIOUS_TAG" ]; then
128+ NOTES="${NOTES}"$'\n'"**Full Changelog**: https://github.com/${{ github.repository }}/compare/$PREVIOUS_TAG...$CURRENT_TAG"
129+ fi
130+
131+ {
132+ echo "notes<<EOF"
133+ echo "$NOTES"
134+ echo "EOF"
135+ } >> $GITHUB_OUTPUT
136+
137+ - name : Create Release
138+ uses : softprops/action-gh-release@v2.5.0
139+ with :
140+ name : Release ${{ steps.currenttag.outputs.current_tag }}
141+ body : ${{ steps.release_notes.outputs.notes }}
142+ draft : false
143+ generate_release_notes : false
144+ tag_name : ${{ steps.currenttag.outputs.current_tag }}
145+ prerelease : ${{ contains(steps.currenttag.outputs.current_tag, 'alpha') || contains(steps.currenttag.outputs.current_tag, 'beta') || contains(steps.currenttag.outputs.current_tag, 'rc') }}
146+ token : ${{ secrets.GITHUB_TOKEN }}
0 commit comments