-
Notifications
You must be signed in to change notification settings - Fork 191
347 lines (306 loc) · 14.4 KB
/
Copy pathrelease.yml
File metadata and controls
347 lines (306 loc) · 14.4 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
name: Build and Release
on:
push:
tags:
- "v*"
workflow_dispatch:
jobs:
build:
strategy:
matrix:
include:
# macOS: Use Intel runner for x64, Apple Silicon runner for arm64
# CRITICAL: macos-15-intel is x86_64, macos-15 is Apple Silicon (arm64)
- os: macos-15-intel # Intel (x86_64) runner for x64 builds
platform: mac
arch: x64
- os: macos-15 # Apple Silicon (arm64) runner for arm64 builds
platform: mac
arch: arm64
- os: windows-latest
platform: win
arch: x64
- os: windows-latest
platform: win
arch: arm64
- os: ubuntu-latest
platform: linux
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
# Only use arm64 Node on macOS arm64 runners. Windows/Linux runners are x64.
# 仅在 macOS arm64 runner 上使用 arm64 Node,Windows/Linux runner 都是 x64
architecture: ${{ matrix.platform == 'mac' && matrix.arch == 'arm64' && 'arm64' || 'x64' }}
- name: Check Environment Architecture
shell: bash
run: |
echo "System Architecture (uname -m): $(uname -m)"
echo "Node Architecture (process.arch): $(node -p 'process.arch')"
# Only enforce arch match on macOS where we have dedicated runners
if [ "${{ matrix.platform }}" = "mac" ] && [ "${{ matrix.arch }}" = "arm64" ] && [ "$(node -p 'process.arch')" != "arm64" ]; then
echo "ERROR: Node.js is not arm64 on macOS arm64 runner!"
exit 1
fi
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
# 显式使用与 package.json 中一致的 pnpm 版本
version: 9.15.0
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-${{ matrix.arch || 'default' }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-${{ matrix.arch || 'default' }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Clean previous build artifacts
shell: bash
run: |
rm -rf dist || true
- name: Build for ${{ matrix.platform }} ${{ matrix.arch }}
shell: bash
run: |
if [ -n "${{ matrix.arch }}" ]; then
# Build specific architecture (Windows or macOS with arch specified)
# 构建特定架构(Windows 或指定了 arch 的 macOS)
if [ "${{ matrix.platform }}" = "win" ]; then
pnpm vite build && pnpm electron-builder --win --${{ matrix.arch }} --publish never
elif [ "${{ matrix.platform }}" = "mac" ]; then
pnpm vite build && pnpm electron-builder --mac --${{ matrix.arch }} --publish never
fi
else
pnpm electron:build:${{ matrix.platform }}
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Verify macOS app architecture
if: matrix.platform == 'mac' && matrix.arch != ''
shell: bash
run: |
ZIP_FILE=$(find dist -maxdepth 1 -name "PromptHub-*-${{ matrix.arch }}.zip" | head -n 1)
if [ -z "$ZIP_FILE" ]; then
echo "Expected macOS ZIP artifact not found for ${{ matrix.arch }}"
exit 1
fi
TMP_DIR=$(mktemp -d)
ditto -x -k "$ZIP_FILE" "$TMP_DIR/app"
APP_BIN=$(find "$TMP_DIR/app" -path "*/PromptHub.app/Contents/MacOS/PromptHub" | head -n 1)
if [ -z "$APP_BIN" ]; then
echo "PromptHub.app binary not found inside $ZIP_FILE"
exit 1
fi
ACTUAL_ARCHS=$(lipo -archs "$APP_BIN")
echo "Detected macOS binary archs: $ACTUAL_ARCHS"
if [ "${{ matrix.arch }}" = "x64" ] && [ "$ACTUAL_ARCHS" != "x86_64" ]; then
echo "Expected x86_64 binary, got: $ACTUAL_ARCHS"
exit 1
fi
if [ "${{ matrix.arch }}" = "arm64" ] && [ "$ACTUAL_ARCHS" != "arm64" ]; then
echo "Expected arm64 binary, got: $ACTUAL_ARCHS"
exit 1
fi
- name: Verify Windows installer architecture
if: matrix.platform == 'win' && matrix.arch != ''
shell: bash
run: |
EXE_FILE=$(find dist -maxdepth 1 -name "PromptHub-Setup-*-${{ matrix.arch }}.exe" | head -n 1)
if [ -z "$EXE_FILE" ]; then
echo "Expected Windows installer not found for ${{ matrix.arch }}"
exit 1
fi
node scripts/verify-windows-installer-arch.js --file "$EXE_FILE" --arch "${{ matrix.arch }}"
- name: Normalize Windows update metadata
if: matrix.platform == 'win' && matrix.arch != ''
shell: bash
run: |
# Generate appropriate yml files for each architecture
# 为每个架构生成适当的 yml 文件
if [ "${{ matrix.arch }}" = "arm64" ]; then
if [ -f "dist/latest.yml" ]; then
node scripts/fix-latest-yml.js --file dist/latest.yml --arch arm64
# Rename to latest-arm64.yml for arm64 builds
mv dist/latest.yml dist/latest-arm64.yml
echo "Renamed latest.yml to latest-arm64.yml for ARM64"
fi
else
# x64: Generate latest-x64.yml for backward compatibility with older versions
# x64: 生成 latest-x64.yml 以兼容旧版本
# electron-builder already generates correct filenames via artifactName
# electron-builder 已通过 artifactName 配置生成正确的文件名
if [ -f "dist/latest.yml" ]; then
node scripts/fix-latest-yml.js --file dist/latest.yml --arch x64
# Create latest-x64.yml as a copy for backward compatibility with old versions
# 创建 latest-x64.yml 副本以兼容旧版本
cp dist/latest.yml dist/latest-x64.yml
echo "Created latest-x64.yml for backward compatibility"
fi
fi
# Remove duplicate NSIS blockmap without arch (prevents release upload errors)
shopt -s nullglob
for file in dist/*.exe.blockmap; do
case "$file" in
*-x64.exe.blockmap|*-arm64.exe.blockmap) ;;
*) rm -f "$file" ;;
esac
done
- name: Normalize macOS update metadata
if: matrix.platform == 'mac' && matrix.arch != ''
shell: bash
run: |
# Keep x64 latest-mac.yml as the canonical filename for backward compatibility.
# ARM64 manifest is stored separately and merged in the release job.
# 保留 x64 latest-mac.yml 作为兼容旧客户端的标准文件名。
# ARM64 manifest 单独保存,稍后在 release job 中合并。
if [ -f "dist/latest-mac.yml" ]; then
if [ "${{ matrix.arch }}" = "arm64" ]; then
mv dist/latest-mac.yml dist/latest-mac-arm64.yml
echo "Saved ARM64 manifest as latest-mac-arm64.yml"
else
# x64 remains latest-mac.yml; also keep an explicit alias for debugging.
# x64 继续保留 latest-mac.yml,同时生成一个显式别名便于调试。
cp dist/latest-mac.yml dist/latest-mac-x64.yml
echo "Created latest-mac-x64.yml alias"
fi
fi
- name: Remove debug files
shell: bash
run: |
# 删除 builder-debug.yml
find dist -name "builder-debug.yml" -delete || true
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-${{ matrix.arch || 'default' }}-build
path: |
dist/*.dmg
dist/*.zip
dist/*-x64.exe
dist/*-arm64.exe
dist/*.AppImage
dist/*.deb
dist/*.blockmap
dist/latest*.yml
if-no-files-found: ignore
release:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Set release version
shell: bash
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
- name: List artifacts for debugging
shell: bash
run: |
echo "=== Artifact structure ==="
find artifacts -type f -name "*.yml" -o -name "*.exe" -o -name "*.dmg" | head -50
- name: Create Release with gh CLI
shell: bash
run: |
# 1. Prepare Release Notes
cat > release_notes.md <<EOF
## 📦 下载安装
| 平台 | 下载 |
|------|------|
| Windows | [](https://github.com/legeling/PromptHub/releases/latest/download/PromptHub-Setup-${VERSION}-x64.exe) [](https://github.com/legeling/PromptHub/releases/latest/download/PromptHub-Setup-${VERSION}-arm64.exe) |
| macOS | [](https://github.com/legeling/PromptHub/releases/latest/download/PromptHub-${VERSION}-arm64.dmg) [](https://github.com/legeling/PromptHub/releases/latest/download/PromptHub-${VERSION}-x64.dmg) |
| Linux | [](https://github.com/legeling/PromptHub/releases/latest/download/PromptHub-${VERSION}-x64.AppImage) [](https://github.com/legeling/PromptHub/releases/latest/download/prompthub_${VERSION}_amd64.deb) |
### ⚠️ macOS 首次启动
如果提示"无法打开"或"已损坏",请在终端执行:
\`\`\`bash
sudo xattr -rd com.apple.quarantine /Applications/PromptHub.app
\`\`\`
---
## 🔄 本次更新
详细更新日志请查看 [更新日志](https://github.com/legeling/PromptHub#-更新日志)
EOF
# 2. Collect and Deduplicate Assets
echo "Collecting and deduplicating assets..."
mkdir -p release_assets
# Find all matching files and copy them to a single directory
# This handles duplicates by overwriting (latest version wins)
find artifacts -type f \( \
-name "PromptHub-*-x64.dmg" -o \
-name "PromptHub-*-arm64.dmg" -o \
-name "PromptHub-Setup-*-x64.exe" -o \
-name "PromptHub-Setup-*-arm64.exe" -o \
-name "PromptHub-*-x64.AppImage" -o \
-name "prompthub_*_amd64.deb" -o \
-name "PromptHub-*.zip" -o \
-name "latest*.yml" -o \
-name "*.blockmap" \
\) -exec cp -f {} release_assets/ \;
echo "Files to upload (deduplicated):"
ls -1 release_assets/
# 3. Merge macOS manifests into one canonical latest-mac.yml for both Intel and Apple Silicon.
# This keeps old mac clients updating via latest-mac.yml while also publishing latest-mac-arm64.yml.
if [ -f "release_assets/latest-mac.yml" ] && [ -f "release_assets/latest-mac-arm64.yml" ]; then
node scripts/merge-mac-latest-yml.js \
--x64 release_assets/latest-mac.yml \
--arm64 release_assets/latest-mac-arm64.yml \
--output release_assets/latest-mac.yml
cp release_assets/latest-mac.yml release_assets/latest-mac-arm64.yml
cp release_assets/latest-mac.yml release_assets/latest-mac-x64.yml
fi
# 4. Verify manifest hashes before publishing. A mismatch here would become a broken auto update.
node scripts/verify-update-manifest.js \
release_assets/latest.yml \
release_assets/latest-arm64.yml \
release_assets/latest-x64.yml \
release_assets/latest-mac.yml \
release_assets/latest-mac-arm64.yml \
release_assets/latest-mac-x64.yml
# 5. Never replace an existing release/tag with different bytes.
# Reusing the same version poisons updater metadata and CDN caches.
if gh release view "${GITHUB_REF_NAME}" >/dev/null 2>&1; then
echo "Release ${GITHUB_REF_NAME} already exists. Published versions must be immutable."
exit 1
fi
# 6. Create Release and Upload
echo "Creating release..."
gh release create "${GITHUB_REF_NAME}" \
release_assets/* \
--title "PromptHub ${VERSION}" \
--notes-file release_notes.md \
--draft=false \
--prerelease=${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }} \
--generate-notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update Homebrew Cask
if: ${{ !contains(github.ref, 'beta') && !contains(github.ref, 'alpha') && secrets.HOMEBREW_TAP_TOKEN != '' }}
shell: bash
run: |
# Wait for release assets to be fully available
sleep 15
bash scripts/update-homebrew-cask.sh "$VERSION"
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
- name: Skip Homebrew Cask update
if: ${{ !contains(github.ref, 'beta') && !contains(github.ref, 'alpha') && secrets.HOMEBREW_TAP_TOKEN == '' }}
shell: bash
run: |
echo "HOMEBREW_TAP_TOKEN is not configured; skipping Homebrew cask publish."