forked from openRin/Rin
-
Notifications
You must be signed in to change notification settings - Fork 0
257 lines (217 loc) · 9.08 KB
/
Copy pathrelease.yml
File metadata and controls
257 lines (217 loc) · 9.08 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
246
247
248
249
250
251
252
253
254
255
256
257
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: write
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Set up Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.3.6
- name: Install dependencies
run: bun install
- name: Validate version consistency
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
PKG_VERSION=$(cat package.json | grep '"version"' | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')
echo "Tag version: $TAG_VERSION"
echo "Package version: $PKG_VERSION"
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
echo "❌ Version mismatch: tag is v$TAG_VERSION but package.json is $PKG_VERSION"
exit 1
fi
echo "✅ Version consistency check passed"
- name: Run typecheck
run: bun run check
- name: Setup Wrangler
uses: ./.github/actions/setup-wrangler
with:
mode: 'dry-run'
- name: Run build
run: bun run build
build:
needs: validate
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.3.6
- name: Install dependencies
run: bun install
- name: Setup Wrangler
uses: ./.github/actions/setup-wrangler
with:
mode: 'dry-run'
- name: Save build metadata
run: |
DEPLOY_SCRIPT_HASH=$(cat ./cli/src/tasks/deploy-cf.ts ./cli/src/lib/db-migration.ts | sha256sum | awk '{print $1}')
mkdir -p ./build-meta
echo "${{ github.event_name }}" > ./build-meta/event_name
echo "${{ github.ref }}" > ./build-meta/ref
echo "${{ github.repository }}" > ./build-meta/repository
echo "0" > ./build-meta/pr_number
echo "${{ github.sha }}" > ./build-meta/sha
echo "${{ github.sha }}" > ./build-meta/head_sha
echo "$DEPLOY_SCRIPT_HASH" > ./build-meta/deploy_script_hash
# Note: vite.config.ts builds directly to ../dist/client
- name: Build client
run: |
cd client
bun run build
cd ..
- name: Build server
run: |
mkdir -p ./dist/server
bunx wrangler deploy --dry-run --outdir=dist/server
- name: Package build artifacts
run: |
VERSION=${GITHUB_REF#refs/tags/v}
tar -czf "build-v${VERSION}-cloudflare.tar.gz" dist/ build-meta/ server/sql/
echo "Artifact packaged: build-v${VERSION}-cloudflare.tar.gz"
ls -lh build-v*.tar.gz
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-release
path: build-v*-cloudflare.tar.gz
create-release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-release
path: ./
- name: Generate release notes
id: release_notes
run: |
VERSION=${GITHUB_REF#refs/tags/v}
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
echo "## What's Changed" > release_notes.md
echo "" >> release_notes.md
if [ -z "$PREVIOUS_TAG" ]; then
echo "This is the first release! 🎉" >> release_notes.md
COMMIT_RANGE="HEAD"
else
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREVIOUS_TAG}...v${VERSION}" >> release_notes.md
echo "" >> release_notes.md
COMMIT_RANGE="${PREVIOUS_TAG}..HEAD"
fi
# Categorize commits
FEATURES=$(git log $COMMIT_RANGE --pretty=format:"- %s (%h)" --grep="^feat" 2>/dev/null || true)
FIXES=$(git log $COMMIT_RANGE --pretty=format:"- %s (%h)" --grep="^fix" 2>/dev/null || true)
DOCS=$(git log $COMMIT_RANGE --pretty=format:"- %s (%h)" --grep="^docs" 2>/dev/null || true)
REFACTOR=$(git log $COMMIT_RANGE --pretty=format:"- %s (%h)" --grep="^refactor" 2>/dev/null || true)
PERF=$(git log $COMMIT_RANGE --pretty=format:"- %s (%h)" --grep="^perf" 2>/dev/null || true)
OTHER=$(git log $COMMIT_RANGE --pretty=format:"- %s (%h)" --grep="^\(feat\\|fix\\|docs\\|refactor\\|perf\)" --invert-grep 2>/dev/null || true)
if [ -n "$FEATURES" ]; then
echo "### 🚀 Features" >> release_notes.md
echo "$FEATURES" | sed 's/^feat(\([^)]*\)):/\1:/' | sed 's/^feat:/✨:/' >> release_notes.md
echo "" >> release_notes.md
fi
if [ -n "$FIXES" ]; then
echo "### 🐛 Bug Fixes" >> release_notes.md
echo "$FIXES" | sed 's/^fix(\([^)]*\)):/\1:/' | sed 's/^fix:/🐛:/' >> release_notes.md
echo "" >> release_notes.md
fi
if [ -n "$PERF" ]; then
echo "### ⚡ Performance" >> release_notes.md
echo "$PERF" | sed 's/^perf(\([^)]*\)):/\1:/' | sed 's/^perf:/⚡:/' >> release_notes.md
echo "" >> release_notes.md
fi
if [ -n "$REFACTOR" ]; then
echo "### ♻️ Refactoring" >> release_notes.md
echo "$REFACTOR" | sed 's/^refactor(\([^)]*\)):/\1:/' | sed 's/^refactor:/♻️:/' >> release_notes.md
echo "" >> release_notes.md
fi
if [ -n "$DOCS" ]; then
echo "### 📚 Documentation" >> release_notes.md
echo "$DOCS" | sed 's/^docs(\([^)]*\)):/\1:/' | sed 's/^docs:/📚:/' >> release_notes.md
echo "" >> release_notes.md
fi
if [ -n "$OTHER" ]; then
echo "### 📝 Other Changes" >> release_notes.md
echo "$OTHER" >> release_notes.md
echo "" >> release_notes.md
fi
# Add manual CHANGELOG section if exists
if [ -f CHANGELOG.md ]; then
CHANGELOG_SECTION=$(awk "/^## \[v${VERSION}\]/ {flag=1; next} /^## \[/ {flag=0} flag" CHANGELOG.md)
if [ -n "$CHANGELOG_SECTION" ]; then
echo "" >> release_notes.md
echo "---" >> release_notes.md
echo "" >> release_notes.md
echo "## 📋 Detailed Changelog" >> release_notes.md
echo "" >> release_notes.md
echo "$CHANGELOG_SECTION" >> release_notes.md
fi
fi
# Add upgrade guide
echo "" >> release_notes.md
echo "---" >> release_notes.md
echo "" >> release_notes.md
echo "## 📦 Build Artifact" >> release_notes.md
echo "" >> release_notes.md
echo "This release includes the attached file \`build-v${VERSION}-cloudflare.tar.gz\`." >> release_notes.md
echo "Use the release asset URL as \`artifact_url\` when triggering \`deploy.yml\` manually." >> release_notes.md
echo "" >> release_notes.md
echo "---" >> release_notes.md
echo "" >> release_notes.md
echo "## 🆙 Upgrade Guide" >> release_notes.md
echo "" >> release_notes.md
echo "For users who have forked this repository:" >> release_notes.md
echo "" >> release_notes.md
echo "1. Go to your forked repository on GitHub" >> release_notes.md
echo '2. Click **"Sync fork"** to get the latest changes' >> release_notes.md
echo "3. Review the [CHANGELOG.md](./CHANGELOG.md) for migration steps" >> release_notes.md
echo "4. Update your environment variables if needed" >> release_notes.md
echo "5. The deployment will run automatically" >> release_notes.md
# Output for GitHub Actions
NOTES=$(cat release_notes.md)
echo "notes<<EOF" >> $GITHUB_OUTPUT
echo "$NOTES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Also output to console for debugging
echo "Generated release notes:"
cat release_notes.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
body_path: release_notes.md
files: build-v*-cloudflare.tar.gz
draft: false
prerelease: ${{ contains(github.ref, '-') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
notify:
needs: create-release
runs-on: ubuntu-latest
if: failure()
steps:
- name: Notify on failure
run: |
echo "❌ Release workflow failed for ${{ github.ref }}"
echo "Please check the workflow logs for details."