-
Notifications
You must be signed in to change notification settings - Fork 65
364 lines (310 loc) · 12.4 KB
/
release.yml
File metadata and controls
364 lines (310 loc) · 12.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
name: Release
on:
push:
tags:
- 'v*'
jobs:
build-tauri:
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- platform: macos-latest
args: "--target aarch64-apple-darwin"
target: aarch64-apple-darwin
- platform: macos-latest
args: "--target x86_64-apple-darwin"
target: x86_64-apple-darwin
- platform: ubuntu-22.04
args: "--target x86_64-unknown-linux-gnu"
target: x86_64-unknown-linux-gnu
- platform: windows-latest
args: ""
target: x86_64-pc-windows-msvc
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
- name: Install Linux build dependencies
if: startsWith(matrix.platform, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y \
libwebkit2gtk-4.1-dev \
libgtk-3-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
patchelf \
libfuse2
- name: Install frontend dependencies
run: npm install
- name: Build application
env:
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
run: npm run tauri build -- ${{ matrix.args }}
- name: Rename macOS updater assets
if: startsWith(matrix.platform, 'macos')
shell: bash
run: |
set -euo pipefail
normalize_name() {
local filename="$1"
printf '%s' "${filename// /_}"
}
if [[ "${{ matrix.target }}" == "aarch64-apple-darwin" ]]; then
ARCH_SUFFIX="aarch64"
else
ARCH_SUFFIX="x64"
fi
find src-tauri/target -type f -path "*/release/bundle/macos/*.app.tar.gz" | while read -r file; do
dir="$(dirname "$file")"
base="$(basename "$file" ".app.tar.gz")"
normalized_base="$(normalize_name "$base")"
renamed="${dir}/${normalized_base}_${ARCH_SUFFIX}.app.tar.gz"
mv "$file" "$renamed"
if [[ -f "${file}.sig" ]]; then
mv "${file}.sig" "${renamed}.sig"
fi
done
find src-tauri/target -type f -path "*/release/bundle/dmg/*.dmg" | while read -r file; do
dir="$(dirname "$file")"
name="$(basename "$file")"
normalized_name="$(normalize_name "$name")"
renamed="${dir}/${normalized_name}"
if [[ "$file" != "$renamed" ]]; then
mv "$file" "$renamed"
fi
done
- name: Rename Windows installer assets
if: startsWith(matrix.platform, 'windows')
shell: bash
run: |
set -euo pipefail
normalize_name() {
local filename="$1"
printf '%s' "${filename// /_}"
}
find src-tauri/target -type f -path "*/release/bundle/nsis/*.exe" | while read -r file; do
dir="$(dirname "$file")"
name="$(basename "$file")"
normalized_name="$(normalize_name "$name")"
renamed="${dir}/${normalized_name}"
if [[ "$file" != "$renamed" ]]; then
mv "$file" "$renamed"
fi
if [[ -f "${file}.sig" ]]; then
mv "${file}.sig" "${renamed}.sig"
fi
done
- name: Rename Linux bundle assets
if: startsWith(matrix.platform, 'ubuntu')
shell: bash
run: |
set -euo pipefail
normalize_name() {
local filename="$1"
printf '%s' "${filename// /_}"
}
find src-tauri/target -type f -path "*/release/bundle/appimage/*.AppImage" | while read -r file; do
dir="$(dirname "$file")"
name="$(basename "$file")"
normalized_name="$(normalize_name "$name")"
renamed="${dir}/${normalized_name}"
if [[ "$file" != "$renamed" ]]; then
mv "$file" "$renamed"
fi
done
find src-tauri/target -type f -path "*/release/bundle/deb/*.deb" | while read -r file; do
dir="$(dirname "$file")"
name="$(basename "$file")"
normalized_name="$(normalize_name "$name")"
renamed="${dir}/${normalized_name}"
if [[ "$file" != "$renamed" ]]; then
mv "$file" "$renamed"
fi
done
- name: Verify required artifacts
shell: bash
run: |
set -euo pipefail
require_file() {
local pattern="$1"
local label="$2"
local match
match="$(find src-tauri/target -type f -path "$pattern" | sort | head -n 1 || true)"
if [[ -z "$match" ]]; then
echo "缺少 ${label}: ${pattern}" >&2
exit 1
fi
echo "${label}: ${match}"
}
case "${{ matrix.target }}" in
aarch64-apple-darwin)
require_file "*/release/bundle/macos/*_aarch64.app.tar.gz" "macOS aarch64 自动更新包"
require_file "*/release/bundle/macos/*_aarch64.app.tar.gz.sig" "macOS aarch64 自动更新签名"
require_file "*/release/bundle/dmg/*.dmg" "macOS aarch64 DMG"
;;
x86_64-apple-darwin)
require_file "*/release/bundle/macos/*_x64.app.tar.gz" "macOS x64 自动更新包"
require_file "*/release/bundle/macos/*_x64.app.tar.gz.sig" "macOS x64 自动更新签名"
require_file "*/release/bundle/dmg/*.dmg" "macOS x64 DMG"
;;
x86_64-unknown-linux-gnu)
require_file "*/release/bundle/appimage/*.AppImage" "Linux AppImage"
require_file "*/release/bundle/deb/*.deb" "Linux DEB"
;;
x86_64-pc-windows-msvc)
require_file "*/release/bundle/nsis/*.exe" "Windows 安装包"
require_file "*/release/bundle/nsis/*.sig" "Windows 安装包签名"
;;
esac
- name: Upload release assets
uses: actions/upload-artifact@v4
with:
name: release-assets-${{ matrix.platform }}-${{ strategy.job-index }}
path: |
src-tauri/target/**/release/bundle/dmg/*.dmg
src-tauri/target/**/release/bundle/dmg/*.sig
src-tauri/target/**/release/bundle/macos/*.app.tar.gz
src-tauri/target/**/release/bundle/macos/*.app.tar.gz.sig
src-tauri/target/**/release/bundle/nsis/*.exe
src-tauri/target/**/release/bundle/nsis/*.sig
src-tauri/target/**/release/bundle/appimage/*.AppImage
src-tauri/target/**/release/bundle/deb/*.deb
if-no-files-found: error
publish-release:
needs: build-tauri
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: all-artifacts
pattern: "release-assets-*"
merge-multiple: true
- name: Extract changelog
shell: bash
run: |
set -euo pipefail
VERSION="${GITHUB_REF_NAME#v}"
BODY=$(awk "/^## \[${VERSION}\]/{found=1; next} /^## \[/{if(found) exit} found{print}" CHANGELOG.md)
if [[ -z "$BODY" ]]; then
BODY="版本 ${VERSION} 更新"
fi
BODY="${BODY}
### macOS 安装说明
首次打开可能提示「已损坏,无法打开」,请执行:
\`\`\`bash
sudo xattr -rd com.apple.quarantine '/Applications/Work Review.app'
\`\`\`"
printf '%s\n' "$BODY" > release_notes.md
- name: Build updater.json from signatures
shell: bash
env:
VERSION: ${{ github.ref_name }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail
DOWNLOAD_BASE="https://github.com/${REPO}/releases/download/${VERSION}"
VER="${VERSION#v}"
NOTES="$(cat release_notes.md)"
PUB_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
MAC_AARCH64_FILE="$(find all-artifacts -type f -name '*_aarch64.app.tar.gz' | sort | head -n 1 || true)"
MAC_X64_FILE="$(find all-artifacts -type f -name '*_x64.app.tar.gz' | sort | head -n 1 || true)"
WINDOWS_FILE="$(find all-artifacts -type f \( -name '*setup.exe' -o -name '*installer.exe' \) ! -name '*.sig' | sort | head -n 1 || true)"
require_asset() {
local asset_file="$1"
local signature_file="$2"
local label="$3"
if [[ -z "$asset_file" || ! -f "$asset_file" ]]; then
echo "缺少 ${label} 产物" >&2
exit 1
fi
if [[ ! -f "$signature_file" ]]; then
echo "缺少 ${label} 签名: ${signature_file}" >&2
exit 1
fi
echo "${label}: ${asset_file}"
}
require_asset "$MAC_AARCH64_FILE" "${MAC_AARCH64_FILE}.sig" "darwin-aarch64"
require_asset "$MAC_X64_FILE" "${MAC_X64_FILE}.sig" "darwin-x86_64"
require_asset "$WINDOWS_FILE" "${WINDOWS_FILE}.sig" "windows-x86_64"
json="$(jq -n \
--arg version "$VER" \
--arg notes "$NOTES" \
--arg pub_date "$PUB_DATE" \
'{version: $version, notes: $notes, pub_date: $pub_date, platforms: {}}')"
add_platform() {
local platform_key="$1"
local asset_file="$2"
local signature_file="$3"
local base_url="$4"
if [[ -z "$asset_file" || ! -f "$asset_file" || ! -f "$signature_file" ]]; then
echo "skip ${platform_key}"
return
fi
local signature
signature="$(tr -d '\r\n' < "$signature_file")"
local asset_name
asset_name="$(basename "$asset_file")"
variant_json="$(jq \
--arg key "$platform_key" \
--arg url "${base_url}/${asset_name}" \
--arg signature "$signature" \
'.platforms[$key] = { url: $url, signature: $signature }' \
<<<"$variant_json")"
}
# 为每个代理前缀生成独立的 updater JSON 文件
# 格式: "前缀 文件名"(前缀为空表示直连 GitHub)
PROXY_VARIANTS=(
" updater.json"
"https://ghproxy.cn/ updater-ghproxy.json"
"https://ghp.ci/ updater-ghp.json"
)
for variant in "${PROXY_VARIANTS[@]}"; do
proxy_prefix="${variant%% *}"
output_file="${variant##* }"
if [[ -z "$proxy_prefix" ]]; then
VARIANT_BASE="${DOWNLOAD_BASE}"
else
VARIANT_BASE="${proxy_prefix}${DOWNLOAD_BASE}"
fi
variant_json="$json"
add_platform "darwin-aarch64" "$MAC_AARCH64_FILE" "${MAC_AARCH64_FILE}.sig" "$VARIANT_BASE"
add_platform "darwin-x86_64" "$MAC_X64_FILE" "${MAC_X64_FILE}.sig" "$VARIANT_BASE"
add_platform "windows-x86_64" "$WINDOWS_FILE" "${WINDOWS_FILE}.sig" "$VARIANT_BASE"
if [[ "$(jq '.platforms | length' <<<"$variant_json")" -ne 3 ]]; then
echo "自动更新平台数量异常 (${output_file}),期望 3 个,实际为 $(jq '.platforms | length' <<<"$variant_json")" >&2
exit 1
fi
printf '%s\n' "$variant_json" > "$output_file"
echo "=== ${output_file} ==="
cat "$output_file"
done
- name: Create or update GitHub Release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
name: "Work_Review ${{ github.ref_name }}"
bodyFile: release_notes.md
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: "all-artifacts/**/*,updater.json,updater-ghproxy.json,updater-ghp.json"
artifactErrorsFailBuild: false
replacesArtifacts: true
makeLatest: legacy