-
Notifications
You must be signed in to change notification settings - Fork 0
233 lines (199 loc) · 7.71 KB
/
release.yml
File metadata and controls
233 lines (199 loc) · 7.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
name: Create Release
on:
push:
branches:
- main
paths-ignore:
- "README.md"
- "CONTRIBUTING.md"
- "CODE_OF_CONDUCT.md"
- "SECURITY.md"
- "LICENSE"
- ".github/ISSUE_TEMPLATE/**"
- ".github/PULL_REQUEST_TEMPLATE.md"
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get latest tag
id: get_latest_tag
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Latest tag: $LATEST_TAG"
- name: Determine version bump
id: version_bump
run: |
if [ "${{ steps.get_latest_tag.outputs.latest_tag }}" = "v0.0.0" ]; then
COMMITS=$(git log --pretty=format:"%s" main)
else
COMMITS=$(git log ${{ steps.get_latest_tag.outputs.latest_tag }}..HEAD --pretty=format:"%s")
fi
echo "Commits since last tag:"
echo "$COMMITS"
BUMP="patch"
if echo "$COMMITS" | grep -qiE "^(feat|feature)(\(.+\))?!:|^BREAKING CHANGE:|breaking:"; then
BUMP="major"
elif echo "$COMMITS" | grep -qiE "^(feat|feature)(\(.+\))?:"; then
BUMP="minor"
fi
echo "bump=$BUMP" >> $GITHUB_OUTPUT
echo "Version bump type: $BUMP"
- name: Calculate new version
id: new_version
run: |
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}"
BUMP="${{ steps.version_bump.outputs.bump }}"
VERSION=${LATEST_TAG#v}
IFS='.' read -r -a VERSION_PARTS <<< "$VERSION"
MAJOR="${VERSION_PARTS[0]:-0}"
MINOR="${VERSION_PARTS[1]:-0}"
PATCH="${VERSION_PARTS[2]:-0}"
if [ "$BUMP" = "major" ]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [ "$BUMP" = "minor" ]; then
MINOR=$((MINOR + 1))
PATCH=0
else
PATCH=$((PATCH + 1))
fi
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Generate changelog
id: changelog
run: |
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}"
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
echo "# Release $NEW_VERSION" > /tmp/release_notes.md
echo "" >> /tmp/release_notes.md
if [ "$LATEST_TAG" = "v0.0.0" ]; then
echo "## Initial Release" >> /tmp/release_notes.md
echo "" >> /tmp/release_notes.md
echo "First release of the GitHub Copilot CLI customization blueprint." >> /tmp/release_notes.md
else
echo "## What's Changed" >> /tmp/release_notes.md
echo "" >> /tmp/release_notes.md
FEAT_COMMITS=()
FIX_COMMITS=()
DOCS_COMMITS=()
REFACTOR_COMMITS=()
CHORE_COMMITS=()
OTHER_COMMITS=()
while IFS= read -r line; do
if echo "$line" | grep -qiE "^(feat|feature)(\(.+\))?:"; then
FEAT_COMMITS+=("$line")
elif echo "$line" | grep -qiE "^fix(\(.+\))?:"; then
FIX_COMMITS+=("$line")
elif echo "$line" | grep -qiE "^docs(\(.+\))?:"; then
DOCS_COMMITS+=("$line")
elif echo "$line" | grep -qiE "^refactor(\(.+\))?:"; then
REFACTOR_COMMITS+=("$line")
elif echo "$line" | grep -qiE "^chore(\(.+\))?:"; then
CHORE_COMMITS+=("$line")
else
OTHER_COMMITS+=("$line")
fi
done < <(git log $LATEST_TAG..HEAD --pretty=format:"%s")
if [ ${#FEAT_COMMITS[@]} -gt 0 ]; then
echo "### ✨ Features" >> /tmp/release_notes.md
for commit in "${FEAT_COMMITS[@]}"; do
echo "- $commit" >> /tmp/release_notes.md
done
echo "" >> /tmp/release_notes.md
fi
if [ ${#FIX_COMMITS[@]} -gt 0 ]; then
echo "### 🐛 Bug Fixes" >> /tmp/release_notes.md
for commit in "${FIX_COMMITS[@]}"; do
echo "- $commit" >> /tmp/release_notes.md
done
echo "" >> /tmp/release_notes.md
fi
if [ ${#DOCS_COMMITS[@]} -gt 0 ]; then
echo "### 📚 Documentation" >> /tmp/release_notes.md
for commit in "${DOCS_COMMITS[@]}"; do
echo "- $commit" >> /tmp/release_notes.md
done
echo "" >> /tmp/release_notes.md
fi
if [ ${#REFACTOR_COMMITS[@]} -gt 0 ]; then
echo "### ♻️ Refactoring" >> /tmp/release_notes.md
for commit in "${REFACTOR_COMMITS[@]}"; do
echo "- $commit" >> /tmp/release_notes.md
done
echo "" >> /tmp/release_notes.md
fi
if [ ${#CHORE_COMMITS[@]} -gt 0 ]; then
echo "### 🔧 Maintenance" >> /tmp/release_notes.md
for commit in "${CHORE_COMMITS[@]}"; do
echo "- $commit" >> /tmp/release_notes.md
done
echo "" >> /tmp/release_notes.md
fi
if [ ${#OTHER_COMMITS[@]} -gt 0 ]; then
echo "### Other Changes" >> /tmp/release_notes.md
for commit in "${OTHER_COMMITS[@]}"; do
echo "- $commit" >> /tmp/release_notes.md
done
echo "" >> /tmp/release_notes.md
fi
fi
{
echo "changelog<<EOF"
cat /tmp/release_notes.md
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Check if release needed
id: check_release
run: |
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}"
if [ "$LATEST_TAG" = "v0.0.0" ]; then
COMMIT_COUNT=$(git rev-list --count HEAD)
else
COMMIT_COUNT=$(git rev-list --count $LATEST_TAG..HEAD)
fi
if [ "$COMMIT_COUNT" -eq 0 ]; then
echo "needs_release=false" >> $GITHUB_OUTPUT
else
echo "needs_release=true" >> $GITHUB_OUTPUT
fi
- name: Create Release
if: steps.check_release.outputs.needs_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.new_version.outputs.new_version }}
name: Release ${{ steps.new_version.outputs.new_version }}
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
- name: Update CHANGELOG.md
if: steps.check_release.outputs.needs_release == 'true'
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
DATE=$(date +%Y-%m-%d)
{
echo "## [$NEW_VERSION] - $DATE"
echo ""
tail -n +3 /tmp/release_notes.md
echo ""
} > /tmp/changelog_entry.md
if [ -f CHANGELOG.md ]; then
awk '/^---$/ { print; system("cat /tmp/changelog_entry.md"); next }1' CHANGELOG.md > /tmp/new_changelog.md
mv /tmp/new_changelog.md CHANGELOG.md
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if ! git diff --quiet CHANGELOG.md; then
git add CHANGELOG.md
git commit -m "chore: update CHANGELOG for $NEW_VERSION [skip ci]"
git push origin main
fi