Skip to content

Commit 0e53ad8

Browse files
authored
Create generate-release-note.yml
1 parent 0787cfc commit 0e53ad8

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: "Generate Release Note"
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*" # Triggers for any tag starting with 'v' (e.g., v1.0, v2.1.3)
7+
- "release-*" # Triggers for any tag starting with 'release-'
8+
- "1.*.*" # Triggers for any tag starting with '1.' (e.g., 1.0.0, 1.1.0)
9+
- "2.*.*" # Triggers for any tag starting with '2.' (e.g., 2.0.0, 2.1.0)
10+
11+
permissions:
12+
contents: write
13+
pull-requests: read
14+
15+
jobs:
16+
check-for-release:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
should-release: ${{ steps.check.outputs.should-release }}
20+
version: ${{ steps.check.outputs.version }}
21+
tag: ${{ steps.check.outputs.tag }}
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Check if release is needed
29+
id: check
30+
run: |
31+
echo "Tag pushed: ${{ github.ref_name }}"
32+
33+
if [[ -z "${{ github.ref_name }}" ]]; then
34+
echo "No tag name found in the event."
35+
echo "should-release=false" >> $GITHUB_OUTPUT
36+
exit 0
37+
fi
38+
39+
HAVE_RELEASE=$(gh release view ${{ github.ref_name }} --json tagName --jq '.tagName' 2>/dev/null || echo "")
40+
if [[ -n "$HAVE_RELEASE" ]]; then
41+
echo "Release already exists for tag: ${{ github.ref_name }}"
42+
echo "should-release=false" >> $GITHUB_OUTPUT
43+
exit 0
44+
fi
45+
46+
echo "should-release=true" >> $GITHUB_OUTPUT
47+
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
48+
echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
49+
50+
create-release:
51+
needs: check-for-release
52+
if: needs.check-for-release.outputs.should-release == 'true'
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
with:
58+
fetch-depth: 0
59+
60+
- name: Generate Release Notes
61+
id: generate_notes
62+
run: |
63+
# Get the latest tag
64+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
65+
66+
if [ -z "$LATEST_TAG" ]; then
67+
# If no previous tag, get all commits
68+
COMMITS=$(git log --pretty=format:"- %s (%h)" --reverse)
69+
else
70+
# Get commits since last tag
71+
COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"- %s (%h)" --reverse)
72+
fi
73+
74+
# Categorize commits
75+
BREAKING_CHANGES=""
76+
FEATURES=""
77+
FIXES=""
78+
OTHER=""
79+
80+
while IFS= read -r commit; do
81+
if echo "$commit" | grep -qE "(BREAKING CHANGE|!:)"; then
82+
BREAKING_CHANGES="$BREAKING_CHANGES$commit"$'\n'
83+
elif echo "$commit" | grep -qE "^- feat"; then
84+
FEATURES="$FEATURES$commit"$'\n'
85+
elif echo "$commit" | grep -qE "^- fix"; then
86+
FIXES="$FIXES$commit"$'\n'
87+
else
88+
OTHER="$OTHER$commit"$'\n'
89+
fi
90+
done <<< "$COMMITS"
91+
92+
# Build release notes
93+
RELEASE_NOTES="## What's Changed in ${{ needs.check-for-release.outputs.version }}"$'\n\n'
94+
95+
if [ -n "$BREAKING_CHANGES" ]; then
96+
RELEASE_NOTES="$RELEASE_NOTES### 💥 Breaking Changes"$'\n'"$BREAKING_CHANGES"$'\n'
97+
fi
98+
99+
if [ -n "$FEATURES" ]; then
100+
RELEASE_NOTES="$RELEASE_NOTES### ✨ New Features"$'\n'"$FEATURES"$'\n'
101+
fi
102+
103+
if [ -n "$FIXES" ]; then
104+
RELEASE_NOTES="$RELEASE_NOTES### 🐛 Bug Fixes"$'\n'"$FIXES"$'\n'
105+
fi
106+
107+
if [ -n "$OTHER" ]; then
108+
RELEASE_NOTES="$RELEASE_NOTES### 🔧 Other Changes"$'\n'"$OTHER"$'\n'
109+
fi
110+
111+
# Add installation instructions
112+
RELEASE_NOTES="$RELEASE_NOTES"$'\n'"## Installation"$'\n\n'
113+
RELEASE_NOTES="$RELEASE_NOTES\`\`\`bash"$'\n'
114+
RELEASE_NOTES="$RELEASE_NOTES""composer require solution-forest/tab-layout-plugin:^${{ needs.check-for-release.outputs.version }}"$'\n'
115+
RELEASE_NOTES="$RELEASE_NOTES\`\`\`"$'\n\n'
116+
117+
# Save to file for GitHub release
118+
echo "$RELEASE_NOTES" > release_notes.md
119+
120+
# Output for GitHub (escape newlines)
121+
echo "notes<<EOF" >> $GITHUB_OUTPUT
122+
echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT
123+
echo "EOF" >> $GITHUB_OUTPUT
124+
125+
- name: Create Release
126+
uses: actions/create-release@v1
127+
env:
128+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129+
with:
130+
tag_name: ${{ needs.check-for-release.outputs.tag }}
131+
release_name: "Release ${{ needs.check-for-release.outputs.version }}"
132+
body: ${{ steps.generate_notes.outputs.notes }}
133+
draft: true
134+
prerelease: false

0 commit comments

Comments
 (0)