🐳 chore: 测试构建

This commit is contained in:
底层用户
2025-10-17 10:25:49 +08:00
parent e18828cd08
commit c4bd94daae
2 changed files with 64 additions and 166 deletions

View File

@@ -10,13 +10,17 @@ env:
NODE_VERSION: 22.x
jobs:
# ---------------- Windows 构建 ----------------
build-windows:
name: Build Windows (x64 + ARM64)
runs-on: windows-latest
# ===================================================================
# 并行构建所有平台和架构
# ===================================================================
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
# 矩阵策略
matrix:
arch: [x64, arm64]
os: [macos-latest, windows-latest, ubuntu-latest]
# 开始步骤
steps:
# 检出 Git 仓库
- name: Check out git repository
@@ -26,177 +30,76 @@ jobs:
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
# 安装 pnpm
- name: Install pnpm
run: npm install -g pnpm
# 复制环境变量文件
- name: Copy .env.example
run: |
if (-not (Test-Path .env)) {
Copy-Item .env.example .env
} else {
Write-Host ".env file already exists. Skipping the copy step."
}
# 安装项目依赖
- name: Install dependencies
run: pnpm install
# 清理旧的构建产物
- name: Clean dist folder
run: |
if (Test-Path dist) {
Remove-Item -Recurse -Force dist
}
# 构建 Electron App
- name: Build Electron App (Windows)
run: pnpm run build:win -- --${{ matrix.arch }} || true
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
# 合并所有 Windows 构建
- name: Upload Windows artifacts
uses: actions/upload-artifact@v4
with:
name: SPlayer-Windows
if-no-files-found: ignore
path: |
dist/*.exe
dist/*.exe.blockmap
dist/*.yml
dist/*.zip
# ---------------- macOS 构建 ----------------
build-macos:
name: Build macOS (x64 + ARM64)
runs-on: macos-13
strategy:
matrix:
arch: [x64, arm64]
steps:
# 检出 Git 仓库
- name: Check out git repository
uses: actions/checkout@v5
# 安装 Node.js
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
# 安装 pnpm
- name: Install pnpm
run: npm install -g pnpm
run: pnpm install --frozen-lockfile
# 复制环境变量文件
- name: Copy .env.example
run: |
if [ ! -f .env ]; then
cp .env.example .env
else
echo ".env file already exists. Skipping the copy step."
fi
# 安装项目依赖
- name: Install dependencies
run: pnpm install
- name: Copy .env file on Windows
if: runner.os == 'Windows'
run: Copy-Item .env.example .env -ErrorAction SilentlyContinue
- name: Copy .env file on macOS & Linux
if: runner.os == 'macOS' || runner.os == 'Linux'
run: cp -n .env.example .env
# 清理旧的构建产物
- name: Clean dist folder
- name: Clean dist folder on Windows
if: runner.os == 'Windows'
run: if (Test-Path dist) { Remove-Item -Recurse -Force dist }
- name: Clean dist folder on macOS & Linux
if: runner.os == 'macOS' || runner.os == 'Linux'
run: rm -rf dist
# 构建 Electron App
- name: Build Electron App (macOS)
run: pnpm run build:mac -- --${{ matrix.arch }} || true
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
# 上传构建产物
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: SPlayer-macOS
if-no-files-found: ignore
path: |
dist/*.dmg
dist/*.zip
dist/*.yml
# ---------------- Linux 构建 ----------------
build-linux:
name: Build Linux (x64 + ARM64)
runs-on: ubuntu-22.04
strategy:
matrix:
arch: [x64, arm64]
steps:
# 检出 Git 仓库
- name: Check out git repository
uses: actions/checkout@v5
# 安装 Node.js
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
# 安装 pnpm
- name: Install pnpm
run: npm install -g pnpm
# 更新 Ubuntu 软件源
- name: Ubuntu Update with sudo
run: sudo apt-get update
# 安装依赖
- name: Install RPM & Pacman
# 安装 Linux 依赖
- name: Install Linux Dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get install --no-install-recommends -y rpm &&
sudo apt-get install --no-install-recommends -y libarchive-tools &&
sudo apt-get install --no-install-recommends -y libopenjp2-tools
# 安装 Snapcraft
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
# 8. 安裝 Snapcraft (僅 Linux)
- name: Install Snapcraft
if: runner.os == 'Linux'
uses: samuelmeuli/action-snapcraft@v2
# 复制环境变量文件
- name: Copy .env.example
run: |
if [ ! -f .env ]; then
cp .env.example .env
else
echo ".env file already exists. Skipping the copy step."
fi
# 安装项目依赖
- name: Install Dependencies
run: pnpm install
# 清理旧的构建产物
- name: Clean dist folder
run: rm -rf dist
# 构建 Electron App
- name: Build Electron App (Linux)
run: pnpm run build:linux -- --${{ matrix.arch }} || true
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: Build macOS Universal App
if: runner.os == 'macOS'
run: pnpm run build:mac -- --universal
- name: Build Windows x64 & ARM64 App
if: runner.os == 'Windows'
run: pnpm run build:win -- --x64 --arm64
- name: Build Linux x64 & ARM64 App
if: runner.os == 'Linux'
run: pnpm run build:linux -- --x64 --arm64
# 上传 Snap 包到 Snapcraft 商店
- name: Publish Snap to Snap Store
run: |
if [ -f dist/*.snap ]; then
snapcraft upload dist/*.snap --release stable || echo "Snap upload failed or not configured"
fi
if: runner.os == 'Linux'
# 即使发布失败,也继续执行后续步骤
continue-on-error: true
run: |
snap_file=$(find dist -name "*.snap" -print -quit)
if [ -n "$snap_file" ]; then
snapcraft upload "$snap_file" --release stable
else
echo "No .snap file found to upload."
fi
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }}
# 上传构建产物
- name: Upload artifacts
# 合并所有构建
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: SPlayer-Linux
if-no-files-found: ignore
path: |
dist/*.AppImage
dist/*.deb
dist/*.rpm
dist/*.snap
dist/*.tar.gz
dist/*.yml
name: SPlayer-${{ runner.os }}
path: dist/
# ---------------- 统一 Release ----------------
# ===================================================================
# 收集并发布 Release
# ===================================================================
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
needs:
- build-windows
- build-macos
- build-linux
if: startsWith(github.ref, 'refs/tags/v')
# 需要写入权限才能创建 Release 和上传产物
# 需要写入权限
permissions:
contents: write
steps:
@@ -212,18 +115,13 @@ jobs:
- name: Create GitHub Release and Upload Assets
uses: softprops/action-gh-release@v2
with:
# 生成发布说明
token: ${{ secrets.GITHUB_TOKEN }}
# 自动生成 Release 说明
generate_release_notes: true
# 发布为草稿
draft: false
# 发布为预发布
prerelease: false
# 全部上传
files: |
artifacts/SPlayer-Windows/!(builder-debug).yml
artifacts/SPlayer-macOS/!(builder-debug).yml
artifacts/SPlayer-Linux/!(builder-debug).yml
artifacts/**/*.exe
artifacts/**/*.dmg
artifacts/**/*.zip
artifacts/**/*.tar.gz
artifacts/**/*.deb
artifacts/**/*.rpm
artifacts/**/*.AppImage
artifacts/**/*.snap
artifacts/**/*