-
Notifications
You must be signed in to change notification settings - Fork 25
220 lines (197 loc) · 8.56 KB
/
Copy pathbuild.yml
File metadata and controls
220 lines (197 loc) · 8.56 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
name: Build & Test Common
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
rust_target: x86_64-unknown-linux-gnu
- os: ubuntu-22.04-arm
rust_target: aarch64-unknown-linux-gnu
- os: windows-latest
rust_target: x86_64-pc-windows-msvc
- os: windows-latest
rust_target: aarch64-pc-windows-msvc
# 主仓库可以访问 TAURI_KEY environment,fork PR 访问不到但不会失败
environment: ${{ (github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request') && 'TAURI_KEY' || '' }}
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
- 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 }}
- 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 ;;
*x86_64-unknown-linux-gnu*) SHORT=linux_x64 ;;
*aarch64-unknown-linux-gnu*) SHORT=linux_arm64 ;;
*) SHORT=unknown ;;
esac
echo "SHORT=$SHORT" >> $GITHUB_OUTPUT
# Linux 专用:使用官方 Action 安装最新版 mold
# 这比 apt-get 安装的旧版本快且稳,而且会自动配置相关环境
- name: Install Mold (Linux)
if: runner.os == 'Linux'
uses: rui314/setup-mold@v1
# Linux 依赖安装 (去掉了 mold,因为上一步已经安装)
- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
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: Configure Rust linker
shell: bash
run: |
mkdir -p .cargo
# === Linux 配置 ===
if [[ "${{ matrix.os }}" == "ubuntu-22.04" ]] || [[ "${{ matrix.os }}" == "ubuntu-22.04-arm" ]]; then
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
# === Windows 配置 ===
elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then
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
fi
- name: Build with Tauri Action
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 }}
CARGO_INCREMENTAL: 0
with:
# 不在这里创建 GitHub release,仅构建
args: >-
--target ${{ matrix.rust_target }}
${{
(github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request')
&& ''
|| '-c ''{"bundle": {"createUpdaterArtifacts": false}}'''
}}
tagName: ""
releaseName: ""
releaseBody: ""
releaseDraft: false
prerelease: false
includeDebug: false
includeRelease: true
tauriScript: pnpm tauri
- name: Prepare portable package (Windows)
if: matrix.os == 'windows-latest'
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"
if (Test-Path $portableRoot) {
Remove-Item $portableRoot -Recurse -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"
# 显示构建状态
- name: Build status
shell: bash
run: |
if [ "${{ github.event_name }}" == "pull_request" ] && [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
echo "⚠️ Fork PR: Build completed WITHOUT signing"
echo " The application will work normally but won't support auto-updates"
else
echo "✅ Build completed with signing enabled and auto-update support"
fi
# Upload build artifacts for testings
- name: Upload Portable Package (Artifact)
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v7
with:
name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-portable
path: src-tauri/target/${{ matrix.rust_target }}/release/portable/ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}
if-no-files-found: warn
- name: Upload MSI Installer (Artifact)
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v7
with:
name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-msi
path: src-tauri/target/${{ matrix.rust_target }}/release/bundle/msi/*.msi
if-no-files-found: warn
- name: Upload NSIS Installer (Artifact)
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v7
with:
name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-setup
path: src-tauri/target/${{ matrix.rust_target }}/release/bundle/nsis/*.exe
if-no-files-found: warn
- name: Upload deb (Artifact)
if: matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-22.04-arm'
uses: actions/upload-artifact@v7
with:
name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-deb
path: src-tauri/target/${{ matrix.rust_target }}/release/bundle/deb/*.deb
if-no-files-found: warn
- name: Upload rpm (Artifact)
if: matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-22.04-arm'
uses: actions/upload-artifact@v7
with:
name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-rpm
path: src-tauri/target/${{ matrix.rust_target }}/release/bundle/rpm/*.rpm
if-no-files-found: warn
- name: Upload AppImage (Artifact)
if: matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-22.04-arm'
uses: actions/upload-artifact@v7
with:
name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-appimage
path: src-tauri/target/${{ matrix.rust_target }}/release/bundle/appimage/*.AppImage
if-no-files-found: warn