-
Notifications
You must be signed in to change notification settings - Fork 3.3k
505 lines (427 loc) · 17.6 KB
/
release.yml
File metadata and controls
505 lines (427 loc) · 17.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
name: Release Desktop Apps
on:
push:
tags:
- 'v*.*.*' # 正式版本: v1.0.0, v2.1.3
- 'v*.*.*-*' # 预览版本: v1.0.0-beta.1, v1.0.0-rc.1
workflow_dispatch:
inputs:
version:
description: '当前所选 ref 上待发布的版本号(例如: v2.8.0)'
required: true
type: string
env:
NODE_VERSION: '22'
jobs:
test:
uses: ./.github/workflows/test.yml
validate-release-notes:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- name: 设置 Node.js 环境
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
- name: 校验版本说明文件
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
echo "📝 Using manual input version: $VERSION"
else
VERSION="${GITHUB_REF#refs/tags/}"
echo "🏷️ Using git tag version: $VERSION"
fi
echo "Validating release notes for $VERSION"
node scripts/release-notes.js check "$VERSION"
prepare-release:
needs: [test, validate-release-notes]
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.version.outputs.version }}
version_no_prefix: ${{ steps.version.outputs.version_no_prefix }}
is_prerelease: ${{ steps.version.outputs.is_prerelease }}
version_type: ${{ steps.version.outputs.version_type }}
steps:
- name: 检出代码
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- name: 设置 Node.js 环境
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
- name: 获取版本号和类型
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
echo "📝 Using manual input version: $VERSION"
else
VERSION="${GITHUB_REF#refs/tags/}"
echo "🏷️ Using git tag version: $VERSION"
fi
VERSION_NO_PREFIX="${VERSION#v}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "version_no_prefix=$VERSION_NO_PREFIX" >> "$GITHUB_OUTPUT"
echo "Version: $VERSION"
IS_PRERELEASE=false
VERSION_TYPE="release"
if [[ $VERSION =~ -(alpha|beta|rc) ]]; then
IS_PRERELEASE=true
VERSION_TYPE="prerelease"
echo "🧪 Detected prerelease version"
elif [[ $VERSION =~ -(hotfix|patch) ]]; then
IS_PRERELEASE=false
VERSION_TYPE="hotfix"
echo "🔧 Detected hotfix version"
else
IS_PRERELEASE=false
VERSION_TYPE="release"
echo "🚀 Detected stable release version"
fi
echo "is_prerelease=$IS_PRERELEASE" >> "$GITHUB_OUTPUT"
echo "version_type=$VERSION_TYPE" >> "$GITHUB_OUTPUT"
- name: 生成 Release 正文
run: |
CURRENT_TAG="${{ steps.version.outputs.version }}"
node scripts/release-notes.js render-body "$CURRENT_TAG" "${{ github.repository }}" > release_body.md
echo "Generated release body:"
cat release_body.md
- name: 创建或更新 Draft Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
IS_PRERELEASE: ${{ steps.version.outputs.is_prerelease }}
run: |
if gh release view "$VERSION" --repo "${{ github.repository }}" >/dev/null 2>&1; then
echo "Release already exists, updating metadata in place"
gh release edit "$VERSION" \
--repo "${{ github.repository }}" \
--title "$VERSION" \
--notes-file release_body.md \
$([ "$IS_PRERELEASE" = "true" ] && echo "--prerelease")
else
echo "Creating draft release shell"
gh release create "$VERSION" \
--repo "${{ github.repository }}" \
--title "$VERSION" \
--notes-file release_body.md \
--target "${GITHUB_SHA}" \
--draft \
$([ "$IS_PRERELEASE" = "true" ] && echo "--prerelease")
fi
# 构建 Windows 版本
build-windows:
needs: [prepare-release]
runs-on: windows-latest
permissions:
contents: write
steps:
- name: 检出代码
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- name: 安装 pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: 设置 Node.js 环境
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'pnpm'
- name: 动态配置 package.json
shell: pwsh
run: |
$pkgPath = "packages/desktop/package.json"
$pkgJson = Get-Content $pkgPath -Raw | ConvertFrom-Json
$tagVersion = "${{ needs.prepare-release.outputs.version_no_prefix }}"
Write-Host "✅ Set version to: $tagVersion"
$repoUrl = "https://github.com/${{ github.repository }}.git"
$pkgJson.version = $tagVersion
$pkgJson.repository.url = $repoUrl
$repoInfo = "${{ github.repository }}".split("/")
$repoOwner = $repoInfo[0]
$repoName = $repoInfo[1]
$pkgJson | ConvertTo-Json -Depth 10 | Set-Content $pkgPath -Encoding UTF8
Write-Host ""
Write-Host "📋 Configuration Summary:"
Write-Host " Version: $tagVersion"
Write-Host " Type: ${{ needs.prepare-release.outputs.version_type }}"
Write-Host " Repository: $repoUrl"
Write-Host " Owner: $repoOwner"
Write-Host " Repo: $repoName"
Write-Host " Private: false (fixed)"
Write-Host " Prerelease: ${{ needs.prepare-release.outputs.is_prerelease }}"
- name: 安装依赖
run: pnpm install
- name: 构建 Desktop 应用
run: pnpm build:desktop:ci
- name: 验证构建产物
shell: bash
run: |
echo "Checking build artifacts..."
ls -la packages/desktop/dist/ || echo "No dist directory found"
exe_files=$(find packages/desktop/dist -name "*.exe" 2>/dev/null | wc -l)
zip_files=$(find packages/desktop/dist -name "*.zip" 2>/dev/null | wc -l)
blockmap_files=$(find packages/desktop/dist -name "*.blockmap" 2>/dev/null | wc -l)
echo "Found $exe_files .exe files, $zip_files .zip files, and $blockmap_files .blockmap files"
if [ "$exe_files" -eq 0 ] || [ "$zip_files" -eq 0 ] || [ "$blockmap_files" -eq 0 ]; then
echo "Error: Windows build is missing required release artifacts (.exe, .zip, or .blockmap)"
echo "Directory contents:"
find packages/desktop/dist -type f 2>/dev/null || echo "Directory not found or empty"
exit 1
fi
echo "Build artifacts verification passed"
- name: 清理调试文件
shell: bash
run: find packages/desktop/dist -type f -name "builder-debug.yml" -delete
- name: 直接上传 Windows Release Assets
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.prepare-release.outputs.version }}
run: |
gh release upload "$VERSION" \
packages/desktop/dist/PromptOptimizer-*.exe \
packages/desktop/dist/PromptOptimizer-*.zip \
packages/desktop/dist/*.blockmap \
packages/desktop/dist/latest*.yml \
--repo "${{ github.repository }}" \
--clobber
# 构建 macOS 版本
build-macos:
needs: [prepare-release]
runs-on: macos-latest
permissions:
contents: write
steps:
- name: 检出代码
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- name: 安装 pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: 设置 Node.js 环境
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'pnpm'
- name: 动态配置 package.json
run: |
PKG_PATH="packages/desktop/package.json"
TAG_VERSION="${{ needs.prepare-release.outputs.version_no_prefix }}"
REPO_URL="https://github.com/${{ github.repository }}.git"
IFS='/' read -r REPO_OWNER REPO_NAME <<< "${{ github.repository }}"
jq --arg version "$TAG_VERSION" \
--arg repo_url "$REPO_URL" \
'.version = $version |
.repository.url = $repo_url' \
"$PKG_PATH" > "${PKG_PATH}.tmp" && mv "${PKG_PATH}.tmp" "$PKG_PATH"
echo "✅ package.json updated successfully"
echo ""
echo "📋 Configuration Summary:"
echo " Version: $TAG_VERSION"
echo " Type: ${{ needs.prepare-release.outputs.version_type }}"
echo " Repository: $REPO_URL"
echo " Owner: $REPO_OWNER"
echo " Repo: $REPO_NAME"
echo " Private: false (fixed)"
echo " Prerelease: ${{ needs.prepare-release.outputs.is_prerelease }}"
- name: 安装依赖
run: pnpm install
- name: 构建 Desktop 应用
run: pnpm build:desktop:ci
- name: 验证构建产物
run: |
echo "Checking build artifacts..."
ls -la packages/desktop/dist/ || echo "No dist directory found"
dmg_files=$(find packages/desktop/dist -name "*.dmg" 2>/dev/null | wc -l)
zip_files=$(find packages/desktop/dist -name "*.zip" 2>/dev/null | wc -l)
blockmap_files=$(find packages/desktop/dist -name "*.blockmap" 2>/dev/null | wc -l)
echo "Found $dmg_files .dmg files, $zip_files .zip files, and $blockmap_files .blockmap files"
if [ "$dmg_files" -eq 0 ] || [ "$zip_files" -eq 0 ] || [ "$blockmap_files" -eq 0 ]; then
echo "Error: macOS build is missing required release artifacts (.dmg, .zip, or .blockmap)"
echo "Directory contents:"
find packages/desktop/dist -type f 2>/dev/null || echo "Directory not found or empty"
exit 1
fi
echo "Build artifacts verification passed"
- name: 清理调试文件
run: find packages/desktop/dist -type f -name "builder-debug.yml" -delete
- name: 直接上传 macOS Release Assets
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.prepare-release.outputs.version }}
run: |
gh release upload "$VERSION" \
packages/desktop/dist/*.dmg \
packages/desktop/dist/*.zip \
packages/desktop/dist/*.blockmap \
packages/desktop/dist/*.yml \
--repo "${{ github.repository }}" \
--clobber
# 构建 Linux 版本
build-linux:
needs: [prepare-release]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: 检出代码
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- name: 安装 pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: 设置 Node.js 环境
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'pnpm'
- name: 动态配置 package.json
run: |
PKG_PATH="packages/desktop/package.json"
TAG_VERSION="${{ needs.prepare-release.outputs.version_no_prefix }}"
REPO_URL="https://github.com/${{ github.repository }}.git"
IFS='/' read -r REPO_OWNER REPO_NAME <<< "${{ github.repository }}"
jq --arg version "$TAG_VERSION" \
--arg repo_url "$REPO_URL" \
'.version = $version |
.repository.url = $repo_url' \
"$PKG_PATH" > "${PKG_PATH}.tmp" && mv "${PKG_PATH}.tmp" "$PKG_PATH"
echo "✅ package.json updated successfully"
echo ""
echo "📋 Configuration Summary:"
echo " Version: $TAG_VERSION"
echo " Type: ${{ needs.prepare-release.outputs.version_type }}"
echo " Repository: $REPO_URL"
echo " Owner: $REPO_OWNER"
echo " Repo: $REPO_NAME"
echo " Private: false (fixed)"
echo " Prerelease: ${{ needs.prepare-release.outputs.is_prerelease }}"
- name: 安装依赖
run: pnpm install
- name: 构建 Desktop 应用
run: pnpm build:desktop:ci
- name: 验证构建产物
run: |
echo "Checking build artifacts..."
ls -la packages/desktop/dist/ || echo "No dist directory found"
appimage_files=$(find packages/desktop/dist -name "*.AppImage" 2>/dev/null | wc -l)
zip_files=$(find packages/desktop/dist -name "*.zip" 2>/dev/null | wc -l)
metadata_files=$(find packages/desktop/dist -name "latest*.yml" 2>/dev/null | wc -l)
echo "Found $appimage_files .AppImage files, $zip_files .zip files, and $metadata_files latest*.yml files"
if [ "$appimage_files" -eq 0 ] && [ "$zip_files" -eq 0 ]; then
echo "Error: No build artifacts (.AppImage or .zip) found in packages/desktop/dist/"
echo "Directory contents:"
find packages/desktop/dist -type f 2>/dev/null || echo "Directory not found or empty"
exit 1
fi
if [ "$metadata_files" -eq 0 ]; then
echo "Error: Linux build is missing updater metadata (latest*.yml)"
echo "Directory contents:"
find packages/desktop/dist -type f 2>/dev/null || echo "Directory not found or empty"
exit 1
fi
echo "Build artifacts verification passed"
- name: 清理调试文件
run: find packages/desktop/dist -type f -name "builder-debug.yml" -delete
- name: 直接上传 Linux Release Assets
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.prepare-release.outputs.version }}
run: |
shopt -s nullglob
files=(
packages/desktop/dist/*.AppImage
packages/desktop/dist/*.zip
packages/desktop/dist/latest*.yml
)
if [ "${#files[@]}" -eq 0 ]; then
echo "Error: No Linux release assets found to upload"
exit 1
fi
echo "Uploading Linux release assets:"
printf ' %s\n' "${files[@]}"
gh release upload "$VERSION" \
"${files[@]}" \
--repo "${{ github.repository }}" \
--clobber
publish-release:
needs: [prepare-release, build-windows, build-macos, build-linux]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: 发布 Draft Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.prepare-release.outputs.version }}
IS_PRERELEASE: ${{ needs.prepare-release.outputs.is_prerelease }}
run: |
gh release edit "$VERSION" \
--repo "${{ github.repository }}" \
--draft=false \
--title "$VERSION" \
$([ "$IS_PRERELEASE" = "true" ] && echo "--prerelease")
- name: 验证 Release 元数据
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.prepare-release.outputs.version }}
run: |
RELEASE_JSON=$(gh release view "$VERSION" \
--repo "${{ github.repository }}" \
--json name,body,url,assets,isDraft,isPrerelease)
echo "Release metadata:"
echo "$RELEASE_JSON"
EXPECTED_NAME="$VERSION"
RELEASE_NAME=$(echo "$RELEASE_JSON" | jq -r '.name')
RELEASE_BODY=$(echo "$RELEASE_JSON" | jq -r '.body')
RELEASE_IS_DRAFT=$(echo "$RELEASE_JSON" | jq -r '.isDraft')
RELEASE_IS_PRERELEASE=$(echo "$RELEASE_JSON" | jq -r '.isPrerelease')
RELEASE_ASSET_NAMES=$(echo "$RELEASE_JSON" | jq -r '.assets[].name')
WINDOWS_BLOCKMAP_COUNT=$(echo "$RELEASE_ASSET_NAMES" | grep -Ec '^PromptOptimizer-.*-win-.*\.exe\.blockmap$' || true)
MAC_ZIP_BLOCKMAP_COUNT=$(echo "$RELEASE_ASSET_NAMES" | grep -Ec '^PromptOptimizer-.*-mac-.*\.zip\.blockmap$' || true)
if [ "$RELEASE_NAME" != "$EXPECTED_NAME" ]; then
echo "Release name mismatch: expected '$EXPECTED_NAME', got '$RELEASE_NAME'"
exit 1
fi
if [ "$RELEASE_IS_DRAFT" != "false" ]; then
echo "Release should be published, but is still a draft"
exit 1
fi
if [ -z "$RELEASE_BODY" ] || [ "$RELEASE_BODY" = "null" ]; then
echo "Release body is empty"
exit 1
fi
if [ "${{ needs.prepare-release.outputs.is_prerelease }}" = "true" ] && [ "$RELEASE_IS_PRERELEASE" != "true" ]; then
echo "Expected prerelease metadata but release is not marked as prerelease"
exit 1
fi
if [ "$WINDOWS_BLOCKMAP_COUNT" -lt 1 ]; then
echo "Release is missing Windows differential-update blockmap assets"
echo "$RELEASE_ASSET_NAMES"
exit 1
fi
if [ "$MAC_ZIP_BLOCKMAP_COUNT" -lt 1 ]; then
echo "Release is missing macOS zip blockmap assets for differential updates"
echo "$RELEASE_ASSET_NAMES"
exit 1
fi