Skip to content

Commit 54fecbb

Browse files
authored
Merge pull request #596 from MoYingJi/ci
build: 多平台 dev 构建
2 parents 5221b20 + 877a543 commit 54fecbb

2 files changed

Lines changed: 104 additions & 30 deletions

File tree

.github/workflows/dev.yml

Lines changed: 95 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Dev 分支推送部署预览
2-
## 部署 Windows
32
name: Build Dev
43

54
on:
@@ -19,17 +18,26 @@ on:
1918
- ".env.example"
2019
- "Dockerfile"
2120
- "docker-compose.yml"
21+
workflow_dispatch:
2222

2323
env:
2424
NODE_VERSION: 22.x
2525
PNPM_VERSION: 8
2626

2727
jobs:
28-
# Windows x64 架构
29-
build-win:
30-
name: Build Electron App for Windows
31-
runs-on: windows-latest
32-
28+
# ===================================================================
29+
# 并行构建所有平台和架构
30+
# ===================================================================
31+
build:
32+
name: Build on ${{ matrix.os }}
33+
runs-on: ${{ matrix.os }}
34+
strategy:
35+
# 矩阵策略
36+
# 即使一个矩阵任务失败,其他任务也会继续运行
37+
fail-fast: false
38+
matrix:
39+
os: [macos-latest, windows-latest, ubuntu-latest]
40+
# 开始步骤
3341
steps:
3442
# 检出 Git 仓库
3543
- name: Check out git repository
@@ -40,41 +48,98 @@ jobs:
4048
with:
4149
version: ${{ env.PNPM_VERSION }}
4250
# 安装 Node.js
43-
- name: Install Node.js
51+
- name: Setup Node.js
4452
uses: actions/setup-node@v6
4553
with:
4654
node-version: ${{ env.NODE_VERSION }}
4755
cache: "pnpm"
56+
# 清理旧的构建产物
57+
- name: Clean workspace on Windows
58+
if: runner.os == 'Windows'
59+
run: |
60+
Write-Host "🧹 Cleaning workspace, node_modules, and Electron caches..."
61+
if (Test-Path dist) { Remove-Item -Recurse -Force dist }
62+
if (Test-Path out) { Remove-Item -Recurse -Force out }
63+
if (Test-Path node_modules) { Remove-Item -Recurse -Force node_modules }
64+
65+
if (Test-Path "$env:LOCALAPPDATA\electron-builder") {
66+
Remove-Item "$env:LOCALAPPDATA\electron-builder" -Recurse -Force -ErrorAction SilentlyContinue
67+
}
68+
if (Test-Path "$env:LOCALAPPDATA\electron") {
69+
Remove-Item "$env:LOCALAPPDATA\electron" -Recurse -Force -ErrorAction SilentlyContinue
70+
}
71+
- name: Clean workspace on macOS & Linux
72+
if: runner.os == 'macOS' || runner.os == 'Linux'
73+
run: |
74+
echo "🧹 Cleaning workspace, node_modules, and Electron caches..."
75+
rm -rf dist out node_modules ~/.cache/electron-builder ~/.cache/electron
76+
# 安装项目依赖
77+
- name: Install dependencies
78+
run: pnpm install
4879
# 复制环境变量文件
49-
- name: Copy .env.example
80+
- name: Copy .env file on Windows
81+
if: runner.os == 'Windows'
5082
run: |
5183
if (-not (Test-Path .env)) {
5284
Copy-Item .env.example .env
5385
} else {
5486
Write-Host ".env file already exists. Skipping the copy step."
5587
}
56-
# 安装项目依赖
57-
- name: Install Dependencies
58-
run: pnpm install
59-
# 清理旧的构建产物
60-
- name: Clean dist folder
88+
- name: Copy .env file on macOS & Linux
89+
if: runner.os == 'macOS' || runner.os == 'Linux'
6190
run: |
62-
if (Test-Path dist) {
63-
Remove-Item -Recurse -Force dist
64-
}
65-
# 构建 Electron App (x64)
66-
- name: Build Electron App for Windows x64
67-
# 仅 x64
68-
run: pnpm run build:win -- --x64
91+
if [ ! -f .env ]; then
92+
cp .env.example .env
93+
else
94+
echo ".env file already exists. Skipping the copy step."
95+
fi
96+
# 更新 Ubuntu 软件源
97+
- name: Ubuntu Update with sudo
98+
if: runner.os == 'Linux'
99+
run: sudo apt-get update
100+
# 安装依赖
101+
- name: Install RPM & Pacman
102+
if: runner.os == 'Linux'
103+
run: |
104+
sudo apt-get install --no-install-recommends -y rpm &&
105+
sudo apt-get install --no-install-recommends -y libarchive-tools &&
106+
sudo apt-get install --no-install-recommends -y libopenjp2-tools
107+
# 构建 Electron App
108+
- name: Build Windows x64 & ARM64 App
109+
if: runner.os == 'Windows'
110+
run: pnpm build:win -- --x64 --arm64 || true
69111
env:
70112
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71-
# 清理不必要的构建产物(保留 .exe 和 .blockmap 文件)
72-
- name: Cleanup Artifacts
73-
run: npx del-cli "dist/**/*.yaml" "dist/**/*.yml"
74-
# 上传构建产物(仅上传 x64 架构的 .exe 文件)
75-
- name: Upload artifacts
76-
uses: actions/upload-artifact@v4
77-
with:
78-
name: SPlayer-dev
79-
path: |
80-
dist/**.exe
113+
- name: Build macOS Universal App
114+
if: runner.os == 'macOS'
115+
run: pnpm build:mac -- --x64 --arm64 || true
116+
shell: bash
117+
env:
118+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119+
- name: Build Linux x64 & ARM64 App
120+
if: runner.os == 'Linux'
121+
run: pnpm build:linux -- --x64 --arm64 || true
122+
shell: bash
123+
env:
124+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125+
126+
# 分别上传
127+
- { name: Upload Artifacts - Windows Setup x64, if: runner.os == 'Windows', uses: actions/upload-artifact@v4, with: { name: SPlayer-Windows-setup-x64, path: dist/*-x64-setup.exe } }
128+
- { name: Upload Artifacts - Windows Setup arm64, if: runner.os == 'Windows', uses: actions/upload-artifact@v4, with: { name: SPlayer-Windows-setup-arm64, path: dist/*-arm64-setup.exe } }
129+
- { name: Upload Artifacts - Windows Portable x64, if: runner.os == 'Windows', uses: actions/upload-artifact@v4, with: { name: SPlayer-Windows-portable-x64, path: dist/*-x64-portable.exe } }
130+
- { name: Upload Artifacts - Windows Portable arm64, if: runner.os == 'Windows', uses: actions/upload-artifact@v4, with: { name: SPlayer-Windows-portable-arm64, path: dist/*-arm64-portable.exe } }
131+
- { name: Upload Artifacts - macOS DMG x64, if: runner.os == 'macOS', uses: actions/upload-artifact@v4, with: { name: SPlayer-macOS-dmg-x64, path: dist/*-x64.dmg } }
132+
- { name: Upload Artifacts - macOS DMG arm64, if: runner.os == 'macOS', uses: actions/upload-artifact@v4, with: { name: SPlayer-macOS-dmg-arm64, path: dist/*-arm64.dmg } }
133+
- { name: Upload Artifacts - macOS Zip x64, if: runner.os == 'macOS', uses: actions/upload-artifact@v4, with: { name: SPlayer-macOS-zip-x64, path: dist/*-x64.zip } }
134+
- { name: Upload Artifacts - macOS Zip arm64 , if: runner.os == 'macOS', uses: actions/upload-artifact@v4, with: { name: SPlayer-macOS-zip-arm64, path: dist/*-arm64.zip } }
135+
- { name: Upload Artifacts - Linux AppImage x64, if: runner.os == 'Linux', uses: actions/upload-artifact@v4, with: { name: SPlayer-Linux-appimage-x64, path: dist/*-x86_64.AppImage } }
136+
- { name: Upload Artifacts - Linux AppImage arm64, if: runner.os == 'Linux', uses: actions/upload-artifact@v4, with: { name: SPlayer-Linux-appimage-arm64, path: dist/*-arm64.AppImage } }
137+
- { name: Upload Artifacts - Linux Pacman x64, if: runner.os == 'Linux', uses: actions/upload-artifact@v4, with: { name: SPlayer-Linux-pacman-x64, path: dist/*-x64.pacman } }
138+
- { name: Upload Artifacts - Linux Pacman arm64, if: runner.os == 'Linux', uses: actions/upload-artifact@v4, with: { name: SPlayer-Linux-pacman-arm64, path: dist/*-aarch64.pacman } }
139+
- { name: Upload Artifacts - Linux DEB x64, if: runner.os == 'Linux', uses: actions/upload-artifact@v4, with: { name: SPlayer-Linux-deb-x64, path: dist/*-amd64.deb } }
140+
- { name: Upload Artifacts - Linux DEB arm64, if: runner.os == 'Linux', uses: actions/upload-artifact@v4, with: { name: SPlayer-Linux-deb-arm64, path: dist/*-arm64.deb } }
141+
- { name: Upload Artifacts - Linux RPM x64, if: runner.os == 'Linux', uses: actions/upload-artifact@v4, with: { name: SPlayer-Linux-rpm-x64, path: dist/*-x86_64.rpm } }
142+
- { name: Upload Artifacts - Linux RPM arm64, if: runner.os == 'Linux', uses: actions/upload-artifact@v4, with: { name: SPlayer-Linux-rpm-arm64, path: dist/*-aarch64.rpm } }
143+
- { name: Upload Artifacts - Linux Tar x64, if: runner.os == 'Linux', uses: actions/upload-artifact@v4, with: { name: SPlayer-Linux-tar-x64, path: dist/*-x64.tar.gz } }
144+
- { name: Upload Artifacts - Linux Tar arm64, if: runner.os == 'Linux', uses: actions/upload-artifact@v4, with: { name: SPlayer-Linux-tar-arm64, path: dist/*-arm64.tar.gz } }
145+
- { name: Upload Artifacts - Linux Snap x64, if: runner.os == 'Linux', uses: actions/upload-artifact@v4, with: { name: SPlayer-Linux-snap-x64, path: dist/*-amd64.snap } }

electron-builder.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ const config: Configuration = {
3737
// 安装版
3838
{
3939
target: "nsis",
40+
arch: ["x64", "arm64"],
4041
},
4142
// 打包版
4243
{
4344
target: "portable",
45+
arch: ["x64", "arm64"],
4446
},
4547
],
4648
},
@@ -97,10 +99,12 @@ const config: Configuration = {
9799
// DMG 安装版
98100
{
99101
target: "dmg",
102+
arch: ["x64", "arm64"],
100103
},
101104
// 压缩包安装版
102105
{
103106
target: "zip",
107+
arch: ["x64", "arm64"],
104108
},
105109
],
106110
},
@@ -117,18 +121,22 @@ const config: Configuration = {
117121
// Pacman 包管理器
118122
{
119123
target: "pacman",
124+
arch: ["x64", "arm64"],
120125
},
121126
// AppImage 格式
122127
{
123128
target: "AppImage",
129+
arch: ["x64", "arm64"],
124130
},
125131
// Debian 包管理器
126132
{
127133
target: "deb",
134+
arch: ["x64", "arm64"],
128135
},
129136
// RPM 包管理器
130137
{
131138
target: "rpm",
139+
arch: ["x64", "arm64"],
132140
},
133141
// Snap 包管理器(仅支持 x64 架构)
134142
{
@@ -138,6 +146,7 @@ const config: Configuration = {
138146
// 压缩包格式
139147
{
140148
target: "tar.gz",
149+
arch: ["x64", "arm64"],
141150
},
142151
],
143152
// 维护者信息

0 commit comments

Comments
 (0)