-
Notifications
You must be signed in to change notification settings - Fork 25
370 lines (343 loc) · 12.7 KB
/
Copy pathrelease.yml
File metadata and controls
370 lines (343 loc) · 12.7 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
name: Release
permissions:
contents: read
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag_name:
description: 'Release tag name (e.g.: v1.0.0)'
required: true
type: string
prerelease:
description: 'Mark as pre-release'
required: false
default: false
type: boolean
jobs:
prepare:
name: Prepare Release
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.resolve_tag.outputs.TAG }}
pure_changelog: ${{ steps.changelog_entry.outputs.content }}
release_body: ${{ steps.combine.outputs.content }}
steps:
- name: Resolve release tag
id: resolve_tag
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.tag_name }}"
else
TAG="${{ github.ref_name }}"
fi
TAG="${TAG#refs/tags/}"
echo "TAG=$TAG" >> "$GITHUB_OUTPUT"
echo "Release tag is $TAG"
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ steps.resolve_tag.outputs.TAG }}
fetch-depth: 0
- name: Extract changelog entry from CHANGELOG.md
id: changelog_entry
shell: bash
env:
VERSION: ${{ steps.resolve_tag.outputs.TAG }}
run: |
VERSION="${VERSION#v}"
VERSION_REGEX="${VERSION//./\\.}"
echo "Looking for version: $VERSION"
CHANGELOG_FILE=$(mktemp)
awk "/^## \\[?v?${VERSION_REGEX}\\]?/ {flag=1} flag {if (started && \$0 ~ /^## /) exit; print; started=1}" CHANGELOG.md > "$CHANGELOG_FILE"
if [ -s "$CHANGELOG_FILE" ]; then
DELIMITER="CHANGELOG_$(openssl rand -hex 8)"
{
echo "content<<$DELIMITER"
cat "$CHANGELOG_FILE"
echo "$DELIMITER"
} >> "$GITHUB_OUTPUT"
echo "Found changelog content for $VERSION"
else
echo "content=See the assets to download and install this version." >> "$GITHUB_OUTPUT"
echo "No matching changelog found for version $VERSION"
fi
rm -f "$CHANGELOG_FILE"
- name: Generate download links
uses: orhun/git-cliff-action@v4
id: cliff_links
env:
INCLUDE_DOWNLOAD_LINKS: "only"
with:
config: cliff.toml
args: --current --strip header
- name: Combine full release body
id: combine
shell: bash
run: |
# 生成一个随机定界符,避免内容中含有 EOF 导致截断
EOF=$(openssl rand -hex 8)
{
echo "content<<$EOF"
cat << INNER_EOF
${{ steps.changelog_entry.outputs.content }}
${{ steps.cliff_links.outputs.content }}
INNER_EOF
echo "$EOF"
} >> "$GITHUB_OUTPUT"
build-linux:
name: Build Linux
runs-on: ${{ matrix.os }}
needs: prepare
permissions:
contents: write
strategy:
matrix:
include:
- os: ubuntu-22.04
rust_target: x86_64-unknown-linux-gnu
- os: ubuntu-22.04-arm
rust_target: aarch64-unknown-linux-gnu
environment: TAURI_KEY
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ needs.prepare.outputs.release_tag }}
- name: Install Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- name: Install pnpm
uses: pnpm/action-setup@v6
with:
run_install: false
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.rust_target }}
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: "./src-tauri -> target"
key: ${{ matrix.rust_target }}
shared-key: ${{ matrix.rust_target }}
save-if: false
- name: Install Mold
uses: rui314/setup-mold@v1
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libsoup-3.0-dev libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf clang
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Configure Rust linker
shell: bash
run: |
mkdir -p .cargo
echo "Configuring mold for Linux..."
cat >> .cargo/config.toml <<EOF
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
EOF
- name: Build and Upload to Draft Release
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
BGM_APP_SECRET: ${{ secrets.BGM_APP_SECRET }}
TAURI_UPDATER_ACTIVE: true
CARGO_INCREMENTAL: 0
with:
tagName: ${{ needs.prepare.outputs.release_tag }}
releaseName: ${{ needs.prepare.outputs.release_tag }}
releaseBody: ${{ needs.prepare.outputs.pure_changelog }}
releaseDraft: true
prerelease: false
includeUpdaterJson: true
includeRelease: true
tauriScript: pnpm tauri
args: --target ${{ matrix.rust_target }}
build-windows:
name: Build Windows
runs-on: windows-latest
needs: prepare
permissions:
contents: write
strategy:
matrix:
rust_target: [ x86_64-pc-windows-msvc, aarch64-pc-windows-msvc ]
environment: TAURI_KEY
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ needs.prepare.outputs.release_tag }}
- name: Install Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- name: Install pnpm
uses: pnpm/action-setup@v6
with:
run_install: false
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.rust_target }}
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: "./src-tauri -> target"
shared-key: ${{ matrix.rust_target }}
save-if: false
- name: Configure Rust linker (Windows lld)
shell: bash
run: |
mkdir -p .cargo
echo "Configuring lld for Windows..."
cat >> .cargo/config.toml <<EOF
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
[target.aarch64-pc-windows-msvc]
linker = "rust-lld.exe"
EOF
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Get version
id: get_version
shell: bash
run: |
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Version is $VERSION"
- name: Compute short target name
id: short
shell: bash
run: |
case "${{ matrix.rust_target }}" in
*x86_64-pc-windows*) SHORT=win_x64 ;;
*aarch64-pc-windows*) SHORT=win_arm64 ;;
*) SHORT=unknown ;;
esac
echo "SHORT=$SHORT" >> $GITHUB_OUTPUT
- name: Build and Upload to Draft Release
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
BGM_APP_SECRET: ${{ secrets.BGM_APP_SECRET }}
TAURI_UPDATER_ACTIVE: true
CARGO_INCREMENTAL: 0
with:
tagName: ${{ needs.prepare.outputs.release_tag }}
releaseName: ${{ needs.prepare.outputs.release_tag }}
releaseBody: ${{ needs.prepare.outputs.pure_changelog }}
releaseDraft: true
prerelease: false
includeUpdaterJson: true
includeRelease: true
tauriScript: pnpm tauri
args: --target ${{ matrix.rust_target }}
- name: Prepare portable package (Windows)
shell: pwsh
run: |
$version = "${{ steps.get_version.outputs.VERSION }}"
$short = "${{ steps.short.outputs.SHORT }}"
$target = "${{ matrix.rust_target }}"
$portableRoot = "src-tauri/target/$target/release/portable/ReinaManager_${version}_${short}"
$resourcesDataDir = Join-Path $portableRoot "resources/data"
$zipPath = "src-tauri/target/$target/release/ReinaManager_${version}_${short}-portable.zip"
if (Test-Path $portableRoot) {
Remove-Item $portableRoot -Recurse -Force
}
if (Test-Path $zipPath) {
Remove-Item $zipPath -Force
}
New-Item -ItemType Directory -Path $resourcesDataDir -Force | Out-Null
@"
该文件夹为数据库文件夹,删除该文件夹则退出便携模式,反之则保持便携模式。
This folder stores the database. Deleting this folder exits portable mode; keeping it preserves portable mode.
"@ | Set-Content -Path (Join-Path $resourcesDataDir "readme.txt") -Encoding UTF8
Copy-Item "src-tauri/target/$target/release/ReinaManager.exe" "$portableRoot/ReinaManager.exe"
Compress-Archive -Path "$portableRoot/*" -DestinationPath $zipPath
- name: Upload portable package to Draft Release
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload "${{ needs.prepare.outputs.release_tag }}" \
"src-tauri/target/${{ matrix.rust_target }}/release/ReinaManager_${{ steps.get_version.outputs.VERSION }}_${{ steps.short.outputs.SHORT }}-portable.zip" \
--clobber
finalize-release:
name: Finalize Release
runs-on: ubuntu-latest
needs: [prepare, build-linux, build-windows]
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Determine release type
id: release-type
shell: bash
run: |
if [[ "${{ needs.prepare.outputs.release_tag }}" == *"alpha"* ]] || [[ "${{ needs.prepare.outputs.release_tag }}" == *"beta"* ]] || [[ "${{ needs.prepare.outputs.release_tag }}" == *"rc"* ]] || [[ "${{ needs.prepare.outputs.release_tag }}" == *"pre"* ]] || [[ "${{ github.event.inputs.prerelease }}" == "true" ]]; then
echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT
else
echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT
fi
- name: Publish Final Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FULL_RELEASE_BODY: ${{ needs.prepare.outputs.release_body }}
run: |
# 1. 将包含下载链接的完整内容写入临时文件
echo "$FULL_RELEASE_BODY" > full_release_notes.md
# 2. 判断是否添加 prerelease 标签
PRERELEASE_FLAG=""
if [ "${{ steps.release-type.outputs.IS_PRERELEASE }}" == "true" ]; then
PRERELEASE_FLAG="--prerelease"
fi
# 3. 强制覆写 Release 正文,并解除草稿状态
gh release edit "${{ needs.prepare.outputs.release_tag }}" \
--draft=false \
--notes-file full_release_notes.md \
$PRERELEASE_FLAG
update_cdn_urls:
name: Update CDN URLs in latest.json
runs-on: ubuntu-latest
needs: [prepare, finalize-release] # 等待 release 正式发布
permissions:
contents: write
if: needs.prepare.outputs.release_tag != ''
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Update latest.json with CDN URLs
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG_NAME="${{ needs.prepare.outputs.release_tag }}"
URL="https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/latest.json"
n=0
until [ "$n" -ge 5 ]; do
curl -L -f -o latest.json "$URL" && break
n=$((n+1))
sleep 5
done
if [ ! -f "latest.json" ]; then
echo "Error: Could not download latest.json after several retries."
exit 1
fi
jq '.platforms |= with_entries(.value.url |= "https://gh.huoshen80.top/\(.)")' latest.json > latest_modified.json
mv -f latest_modified.json latest.json
gh release upload $TAG_NAME "latest.json" --clobber
echo "Successfully updated latest.json with CDN URLs"