-
Notifications
You must be signed in to change notification settings - Fork 6
245 lines (214 loc) · 8.6 KB
/
release.yml
File metadata and controls
245 lines (214 loc) · 8.6 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
234
235
236
237
238
239
240
241
242
243
244
245
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., 1.4.0)'
required: true
type: string
prerelease:
description: 'Mark as pre-release'
required: false
type: boolean
default: false
dry_run:
description: 'Dry run (skip publish steps)'
required: false
type: boolean
default: false
permissions:
contents: write
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Validate version format
run: |
VERSION="${{ github.event.inputs.version }}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
echo "::error::Invalid version format. Expected: X.Y.Z or X.Y.Z-suffix (e.g., 1.4.0, 2.0.0-beta.1)"
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "TAG=v$VERSION" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Run tests
run: bun test
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Update package.json version
run: |
# Update version in package.json
bun --eval "
const pkg = await Bun.file('package.json').json();
pkg.version = '${{ env.VERSION }}';
await Bun.write('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
echo "Updated package.json to version ${{ env.VERSION }}"
- name: Commit version bump
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
git add package.json
if git diff --cached --quiet; then
echo "No changes to package.json (version already set to ${{ env.VERSION }})"
else
git commit -m "chore(release): bump version to ${{ env.VERSION }}"
git push
fi
- name: Get previous tag
id: prev_tag
run: |
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT
echo "Previous tag: $PREV_TAG"
- name: Generate release notes
id: release_notes
run: |
PREV_TAG="${{ steps.prev_tag.outputs.prev_tag }}"
if [ -z "$PREV_TAG" ]; then
# No previous tag, get all commits
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges HEAD)
COMPARE_URL=""
else
# Get commits since last tag
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges ${PREV_TAG}..HEAD)
COMPARE_URL="**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${{ env.TAG }}"
fi
# Categorize commits
FEATURES=$(echo "$COMMITS" | grep -iE "^- (feat|feature)" || true)
FIXES=$(echo "$COMMITS" | grep -iE "^- fix" || true)
DOCS=$(echo "$COMMITS" | grep -iE "^- docs?" || true)
CHORES=$(echo "$COMMITS" | grep -iE "^- (chore|build|ci|refactor|perf|test|style)" || true)
BREAKING=$(echo "$COMMITS" | grep -iE "^- .*!:|BREAKING" || true)
OTHER=$(echo "$COMMITS" | grep -ivE "^- (feat|feature|fix|docs?|chore|build|ci|refactor|perf|test|style)" || true)
# Build release notes
{
echo "RELEASE_NOTES<<EOF"
echo "## What's Changed"
echo ""
if [ -n "$BREAKING" ]; then
echo "### Breaking Changes"
echo "$BREAKING"
echo ""
fi
if [ -n "$FEATURES" ]; then
echo "### Features"
echo "$FEATURES"
echo ""
fi
if [ -n "$FIXES" ]; then
echo "### Bug Fixes"
echo "$FIXES"
echo ""
fi
if [ -n "$DOCS" ]; then
echo "### Documentation"
echo "$DOCS"
echo ""
fi
if [ -n "$CHORES" ]; then
echo "### Maintenance"
echo "$CHORES"
echo ""
fi
if [ -n "$OTHER" ]; then
echo "### Other Changes"
echo "$OTHER"
echo ""
fi
echo "---"
echo ""
echo "## Installation"
echo ""
echo "Add to your OpenCode config (\`~/.config/opencode/opencode.json\`):"
echo ""
echo "\`\`\`json"
echo "{"
echo " \"plugin\": [\"opencode-smart-voice-notify@${{ env.VERSION }}\"]"
echo "}"
echo "\`\`\`"
echo ""
echo "Or install from GitHub:"
echo ""
echo "\`\`\`json"
echo "{"
echo " \"plugin\": [\"github:MasuRii/opencode-smart-voice-notify#${{ env.TAG }}\"]"
echo "}"
echo "\`\`\`"
echo ""
if [ -n "$COMPARE_URL" ]; then
echo "$COMPARE_URL"
fi
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "${{ env.TAG }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "::warning::Tag ${{ env.TAG }} already exists"
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create and push tag
if: ${{ github.event.inputs.dry_run != 'true' && steps.check_tag.outputs.exists != 'true' }}
run: |
git tag -a "${{ env.TAG }}" -m "Release ${{ env.VERSION }}"
git push origin "${{ env.TAG }}"
- name: Create GitHub Release
if: ${{ github.event.inputs.dry_run != 'true' && steps.check_tag.outputs.exists != 'true' }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG }}
name: v${{ env.VERSION }}
body: ${{ steps.release_notes.outputs.RELEASE_NOTES }}
draft: false
prerelease: ${{ github.event.inputs.prerelease }}
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Dry run summary
if: ${{ github.event.inputs.dry_run == 'true' }}
run: |
echo "## Dry Run Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "**Tag:** ${{ env.TAG }}" >> $GITHUB_STEP_SUMMARY
echo "**Pre-release:** ${{ github.event.inputs.prerelease }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Release Notes Preview" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.release_notes.outputs.RELEASE_NOTES }}" >> $GITHUB_STEP_SUMMARY
- name: Release summary
if: ${{ github.event.inputs.dry_run != 'true' && steps.check_tag.outputs.exists != 'true' }}
run: |
echo "## Release Created Successfully" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "**Tag:** ${{ env.TAG }}" >> $GITHUB_STEP_SUMMARY
echo "**Pre-release:** ${{ github.event.inputs.prerelease }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Release URL:** https://github.com/${{ github.repository }}/releases/tag/${{ env.TAG }}" >> $GITHUB_STEP_SUMMARY
- name: Tag exists summary
if: ${{ github.event.inputs.dry_run != 'true' && steps.check_tag.outputs.exists == 'true' }}
run: |
echo "## Release Skipped" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Reason:** Tag ${{ env.TAG }} already exists" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "To create a new release, use a different version number." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Existing Release:** https://github.com/${{ github.repository }}/releases/tag/${{ env.TAG }}" >> $GITHUB_STEP_SUMMARY