统一服务默认端口为 59188,完善 Windows 服务权限与 macOS LaunchAgent 管理。 实现 Windows 与 macOS 托盘状态机、服务启停等待、单实例保护、日志目录入口和退出前清理后台服务。 统一 Linux、Windows、macOS 与 Docker 的 Playwright Chromium runtime 构建流程,增加缓存、架构校验和 Linux 原生 runner,避免 QEMU。 完善 Windows、macOS、Linux 安装包及签名打包脚本,修正 Chromium 嵌入、服务注册和安装卸载流程。 同步 README、AGENTS、官网首页、Wiki 与前端开发文档,统一端口、初始化、服务、日志、托盘和安装说明。
401 lines
17 KiB
YAML
401 lines
17 KiB
YAML
name: 构建桌面端安装包
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- codex/desktop-packaging
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: desktop-cd-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
APP_VERSION: 0.0.0-${{ github.run_number }}
|
|
|
|
jobs:
|
|
linux:
|
|
name: Linux 安装包 (${{ matrix.arch }})
|
|
if: github.ref == 'refs/heads/codex/desktop-packaging'
|
|
runs-on: ${{ matrix.runner }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- arch: amd64
|
|
runner: ubuntu-24.04
|
|
playwright_platform: ubuntu24.04-x64
|
|
- arch: arm64
|
|
runner: ubuntu-24.04-arm
|
|
playwright_platform: ubuntu24.04-arm64
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v6
|
|
|
|
- name: 配置 Go
|
|
uses: actions/setup-go@v7
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: true
|
|
|
|
- name: 配置 Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: 22
|
|
cache: npm
|
|
cache-dependency-path: frontend/package-lock.json
|
|
|
|
- name: 构建嵌入式前端
|
|
run: npm ci --prefix frontend && npm run build --prefix frontend
|
|
|
|
- name: 编译 Linux 二进制
|
|
env:
|
|
GOOS: linux
|
|
GOARCH: ${{ matrix.arch }}
|
|
CGO_ENABLED: 0
|
|
run: |
|
|
package_dir="dist/ydisks-xianyu-helper-linux-${GOARCH}"
|
|
mkdir -p "$package_dir"
|
|
go build -trimpath -ldflags='-s -w' -o "$package_dir/xianyu-server" ./cmd/server
|
|
go build -trimpath -ldflags='-s -w' -o "$package_dir/browser-install" ./cmd/browser-install
|
|
|
|
- name: 缓存 Linux Chromium runtime
|
|
id: cache-linux-playwright
|
|
uses: actions/cache/restore@v5
|
|
with:
|
|
path: dist/ydisks-xianyu-helper-linux-${{ matrix.arch }}/playwright-runtime
|
|
key: ydisks-playwright-runtime-v4-linux-${{ matrix.arch }}-${{ hashFiles('go.mod', 'go.sum', 'cmd/browser-install/main.go') }}
|
|
|
|
- name: 在原生架构 runner 预下载 Linux Chromium runtime
|
|
if: steps.cache-linux-playwright.outputs.cache-hit != 'true'
|
|
env:
|
|
GOARCH: ${{ matrix.arch }}
|
|
PLAYWRIGHT_HOST_PLATFORM_OVERRIDE: ${{ matrix.playwright_platform }}
|
|
run: |
|
|
set -Eeuo pipefail
|
|
case "$(uname -m)" in
|
|
x86_64) runner_arch=amd64 ;;
|
|
aarch64|arm64) runner_arch=arm64 ;;
|
|
*) echo "不支持的 runner 架构:$(uname -m)" >&2; exit 1 ;;
|
|
esac
|
|
if [ "$runner_arch" != "$GOARCH" ]; then
|
|
echo "runner 架构 $runner_arch 与目标架构 $GOARCH 不一致,拒绝使用模拟器构建。" >&2
|
|
exit 1
|
|
fi
|
|
package_dir="dist/ydisks-xianyu-helper-linux-${GOARCH}"
|
|
runtime_dir="$package_dir/playwright-runtime/$GOARCH"
|
|
mkdir -p "$runtime_dir/playwright-driver" "$runtime_dir/playwright-browsers"
|
|
"$package_dir/browser-install" \
|
|
-driver-dir "$PWD/$runtime_dir/playwright-driver" \
|
|
-browser-dir "$PWD/$runtime_dir/playwright-browsers"
|
|
|
|
- name: 保存 Linux Chromium runtime 缓存
|
|
if: steps.cache-linux-playwright.outputs.cache-hit != 'true'
|
|
uses: actions/cache/save@v5
|
|
with:
|
|
path: dist/ydisks-xianyu-helper-linux-${{ matrix.arch }}/playwright-runtime
|
|
key: ydisks-playwright-runtime-v4-linux-${{ matrix.arch }}-${{ hashFiles('go.mod', 'go.sum', 'cmd/browser-install/main.go') }}
|
|
|
|
- name: 校验 Linux Chromium runtime 架构
|
|
env:
|
|
GOARCH: ${{ matrix.arch }}
|
|
run: |
|
|
set -Eeuo pipefail
|
|
runtime_dir="dist/ydisks-xianyu-helper-linux-${GOARCH}/playwright-runtime/${GOARCH}"
|
|
node_path="$runtime_dir/playwright-driver/node"
|
|
test -x "$node_path"
|
|
"$node_path" --version
|
|
node_type="$(file -b "$node_path")"
|
|
case "$GOARCH:$node_type" in
|
|
amd64:*x86-64*) ;;
|
|
arm64:*aarch64*|arm64:*ARM64*) ;;
|
|
*) echo "Playwright driver 架构错误:$node_type" >&2; exit 1 ;;
|
|
esac
|
|
chromium_path="$(find "$runtime_dir/playwright-browsers" -type f \
|
|
\( -name chrome -o -name headless_shell \) -perm -111 -print -quit)"
|
|
test -n "$chromium_path"
|
|
chromium_type="$(file -b "$chromium_path")"
|
|
case "$GOARCH:$chromium_type" in
|
|
amd64:*x86-64*) ;;
|
|
arm64:*aarch64*|arm64:*ARM64*) ;;
|
|
*) echo "Chromium 架构错误:$chromium_type" >&2; exit 1 ;;
|
|
esac
|
|
|
|
- name: 组装 Linux 安装目录
|
|
run: |
|
|
set -Eeuo pipefail
|
|
package_dir="dist/ydisks-xianyu-helper-linux-${{ matrix.arch }}"
|
|
cp icon/linux/icon.png "$package_dir/icon.png"
|
|
cp packaging/linux/install.sh packaging/linux/uninstall.sh packaging/linux/ydisks-xianyu-helper.service "$package_dir/"
|
|
chmod +x "$package_dir/install.sh" "$package_dir/uninstall.sh"
|
|
tar -C dist -czf "dist/ydisks-xianyu-helper-linux-${{ matrix.arch }}-${APP_VERSION}.tar.gz" "$(basename "$package_dir")"
|
|
|
|
- name: 上传 Linux 安装包
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: ydisks-xianyu-helper-linux-${{ matrix.arch }}-${{ env.APP_VERSION }}
|
|
path: dist/ydisks-xianyu-helper-linux-${{ matrix.arch }}-${{ env.APP_VERSION }}.tar.gz
|
|
if-no-files-found: error
|
|
|
|
windows:
|
|
name: Windows 安装包
|
|
if: github.ref == 'refs/heads/codex/desktop-packaging'
|
|
runs-on: windows-latest
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v6
|
|
|
|
- name: 配置 Go
|
|
uses: actions/setup-go@v7
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: true
|
|
|
|
- name: 配置 Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: 22
|
|
cache: npm
|
|
cache-dependency-path: frontend/package-lock.json
|
|
|
|
- name: 构建嵌入式前端
|
|
shell: pwsh
|
|
run: npm ci --prefix frontend; npm run build --prefix frontend
|
|
|
|
- name: 验证 Windows 托盘逻辑与安装脚本
|
|
shell: pwsh
|
|
run: |
|
|
go test ./cmd/tray
|
|
$tokens = $null
|
|
$parseErrors = $null
|
|
[void][System.Management.Automation.Language.Parser]::ParseFile(
|
|
(Resolve-Path 'packaging/windows/service-control.ps1'),
|
|
[ref]$tokens,
|
|
[ref]$parseErrors
|
|
)
|
|
if ($parseErrors.Count -gt 0) {
|
|
$parseErrors | ForEach-Object { Write-Error $_.Message }
|
|
throw 'Windows 服务安装脚本语法检查失败'
|
|
}
|
|
|
|
- name: 编译 Windows 桌面程序
|
|
shell: pwsh
|
|
run: |
|
|
New-Item -ItemType Directory -Force -Path dist/windows | Out-Null
|
|
go build -trimpath -ldflags "-s -w" -o dist/windows/xianyu-server.exe ./cmd/server
|
|
go build -trimpath -ldflags "-s -w" -o dist/windows/browser-install.exe ./cmd/browser-install
|
|
go build -trimpath -ldflags "-s -w -H=windowsgui" -o dist/windows/xianyu-tray.exe ./cmd/tray
|
|
|
|
- name: 缓存 Windows Chromium runtime
|
|
id: cache-windows-playwright
|
|
uses: actions/cache@v5
|
|
with:
|
|
path: dist/windows/playwright-runtime/amd64
|
|
key: ydisks-playwright-runtime-v2-windows-amd64-${{ hashFiles('go.mod', 'go.sum', 'cmd/browser-install/main.go') }}
|
|
|
|
- name: 预下载 Windows Chromium runtime
|
|
if: steps.cache-windows-playwright.outputs.cache-hit != 'true'
|
|
shell: pwsh
|
|
run: |
|
|
New-Item -ItemType Directory -Force -Path dist/windows/playwright-runtime/amd64/playwright-driver | Out-Null
|
|
New-Item -ItemType Directory -Force -Path dist/windows/playwright-runtime/amd64/playwright-browsers | Out-Null
|
|
& dist/windows/browser-install.exe `
|
|
-driver-dir "$PWD/dist/windows/playwright-runtime/amd64/playwright-driver" `
|
|
-browser-dir "$PWD/dist/windows/playwright-runtime/amd64/playwright-browsers"
|
|
if ($LASTEXITCODE -ne 0) { throw 'Windows Playwright runtime 下载失败' }
|
|
|
|
- name: 导入 Windows 签名证书
|
|
shell: pwsh
|
|
env:
|
|
WINDOWS_SIGNING_PFX_BASE64: ${{ secrets.WINDOWS_SIGNING_PFX_BASE64 }}
|
|
WINDOWS_SIGNING_PFX_PASSWORD: ${{ secrets.WINDOWS_SIGNING_PFX_PASSWORD }}
|
|
WINDOWS_SIGNING_IDENTITY: ${{ secrets.WINDOWS_SIGNING_IDENTITY }}
|
|
run: |
|
|
$pfxPath = Join-Path $env:RUNNER_TEMP 'ydisks-windows-signing.pfx'
|
|
[IO.File]::WriteAllBytes($pfxPath, [Convert]::FromBase64String($env:WINDOWS_SIGNING_PFX_BASE64))
|
|
if (-not (Test-Path -LiteralPath $pfxPath -PathType Leaf)) { throw 'Windows PFX 文件写入失败' }
|
|
"WINDOWS_SIGNING_PFX_PATH=$pfxPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
|
|
|
- name: 签名 Windows 桌面程序
|
|
shell: pwsh
|
|
env:
|
|
WINDOWS_SIGNING_PFX_PASSWORD: ${{ secrets.WINDOWS_SIGNING_PFX_PASSWORD }}
|
|
WINDOWS_SIGNING_IDENTITY: ${{ secrets.WINDOWS_SIGNING_IDENTITY }}
|
|
run: |
|
|
& packaging/windows/sign.ps1 `
|
|
-PfxPath $env:WINDOWS_SIGNING_PFX_PATH `
|
|
-Files 'dist/windows/xianyu-server.exe','dist/windows/xianyu-tray.exe'
|
|
|
|
- name: 安装 Inno Setup
|
|
shell: pwsh
|
|
run: choco install innosetup --no-progress --yes
|
|
|
|
- name: 构建 Windows 安装器
|
|
shell: pwsh
|
|
env:
|
|
APP_VERSION: ${{ env.APP_VERSION }}
|
|
run: |
|
|
& 'C:\Program Files (x86)\Inno Setup 6\ISCC.exe' /Qp /O"dist\windows" packaging\windows\installer.iss
|
|
$installer = Get-ChildItem -Path dist/windows -Filter 'Ydisks-Xianyu-Helper-Setup.exe' -Recurse | Select-Object -First 1
|
|
if ($null -eq $installer) { throw 'Inno Setup 未生成安装器' }
|
|
$target = Join-Path (Resolve-Path dist/windows) 'Ydisks-Xianyu-Helper-Setup.exe'
|
|
if ($installer.FullName -ne $target) { Copy-Item $installer.FullName $target -Force }
|
|
|
|
- name: 签名 Windows 安装器
|
|
shell: pwsh
|
|
env:
|
|
WINDOWS_SIGNING_PFX_PASSWORD: ${{ secrets.WINDOWS_SIGNING_PFX_PASSWORD }}
|
|
WINDOWS_SIGNING_IDENTITY: ${{ secrets.WINDOWS_SIGNING_IDENTITY }}
|
|
run: |
|
|
& packaging/windows/sign.ps1 `
|
|
-PfxPath $env:WINDOWS_SIGNING_PFX_PATH `
|
|
-Files 'dist/windows/Ydisks-Xianyu-Helper-Setup.exe'
|
|
|
|
- name: 打包 Windows 二进制归档
|
|
shell: pwsh
|
|
env:
|
|
APP_VERSION: ${{ env.APP_VERSION }}
|
|
run: |
|
|
Compress-Archive -Path dist/windows/xianyu-server.exe,dist/windows/xianyu-tray.exe,dist/windows/playwright-runtime -DestinationPath "dist/windows/Ydisks-Xianyu-Helper-${env:APP_VERSION}-binaries.zip"
|
|
|
|
- name: 上传 Windows 安装包
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: ydisks-xianyu-helper-windows-${{ env.APP_VERSION }}
|
|
path: |
|
|
dist/windows/Ydisks-Xianyu-Helper-Setup.exe
|
|
dist/windows/Ydisks-Xianyu-Helper-${{ env.APP_VERSION }}-binaries.zip
|
|
if-no-files-found: error
|
|
|
|
macos:
|
|
name: macOS 安装包
|
|
if: github.ref == 'refs/heads/codex/desktop-packaging'
|
|
runs-on: macos-14
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v6
|
|
|
|
- name: 配置 Go
|
|
uses: actions/setup-go@v7
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: true
|
|
|
|
- name: 配置 Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: 22
|
|
cache: npm
|
|
cache-dependency-path: frontend/package-lock.json
|
|
|
|
- name: 构建嵌入式前端
|
|
run: npm ci --prefix frontend && npm run build --prefix frontend
|
|
|
|
- name: 验证 macOS 托盘逻辑
|
|
run: go test ./cmd/tray
|
|
|
|
- name: 编译 macOS 桌面程序
|
|
run: |
|
|
mkdir -p dist/macos/arm64 dist/macos/amd64
|
|
for arch in arm64 amd64; do
|
|
GOOS=darwin GOARCH="$arch" CGO_ENABLED=1 go build -trimpath -ldflags='-s -w' -o "dist/macos/$arch/xianyu-server" ./cmd/server
|
|
GOOS=darwin GOARCH="$arch" CGO_ENABLED=1 go build -trimpath -ldflags='-s -w' -o "dist/macos/$arch/browser-install" ./cmd/browser-install
|
|
GOOS=darwin GOARCH="$arch" CGO_ENABLED=1 go build -trimpath -ldflags='-s -w' -o "dist/macos/$arch/xianyu-tray" ./cmd/tray
|
|
done
|
|
|
|
- name: 缓存 macOS Chromium runtime
|
|
id: cache-macos-playwright
|
|
uses: actions/cache/restore@v5
|
|
with:
|
|
path: |
|
|
dist/macos/playwright-runtime/arm64
|
|
dist/macos/playwright-runtime/amd64
|
|
key: ydisks-playwright-runtime-v2-macos-universal-${{ hashFiles('go.mod', 'go.sum', 'cmd/browser-install/main.go') }}
|
|
|
|
- name: 预下载 macOS Chromium runtime
|
|
if: steps.cache-macos-playwright.outputs.cache-hit != 'true'
|
|
run: |
|
|
set -Eeuo pipefail
|
|
mkdir -p dist/macos/playwright-runtime/arm64/playwright-driver
|
|
mkdir -p dist/macos/playwright-runtime/arm64/playwright-browsers
|
|
mkdir -p dist/macos/playwright-runtime/amd64/playwright-driver
|
|
mkdir -p dist/macos/playwright-runtime/amd64/playwright-browsers
|
|
PLAYWRIGHT_HOST_PLATFORM_OVERRIDE=mac14-arm64 \
|
|
dist/macos/arm64/browser-install \
|
|
-driver-dir "$PWD/dist/macos/playwright-runtime/arm64/playwright-driver" \
|
|
-browser-dir "$PWD/dist/macos/playwright-runtime/arm64/playwright-browsers"
|
|
PLAYWRIGHT_HOST_PLATFORM_OVERRIDE=mac14 \
|
|
arch -x86_64 dist/macos/amd64/browser-install \
|
|
-driver-dir "$PWD/dist/macos/playwright-runtime/amd64/playwright-driver" \
|
|
-browser-dir "$PWD/dist/macos/playwright-runtime/amd64/playwright-browsers"
|
|
|
|
- name: 保存 macOS Chromium runtime 缓存
|
|
if: steps.cache-macos-playwright.outputs.cache-hit != 'true'
|
|
uses: actions/cache/save@v5
|
|
with:
|
|
path: |
|
|
dist/macos/playwright-runtime/arm64
|
|
dist/macos/playwright-runtime/amd64
|
|
key: ${{ steps.cache-macos-playwright.outputs.cache-primary-key }}
|
|
|
|
- name: 导入 macOS 签名证书
|
|
env:
|
|
MACOS_SIGNING_P12_BASE64: ${{ secrets.MACOS_SIGNING_P12_BASE64 }}
|
|
MACOS_INSTALLER_SIGNING_P12_BASE64: ${{ secrets.MACOS_INSTALLER_SIGNING_P12_BASE64 }}
|
|
MACOS_SIGNING_P12_PASSWORD: ${{ secrets.MACOS_SIGNING_P12_PASSWORD }}
|
|
MACOS_SIGNING_IDENTITY: ${{ secrets.MACOS_SIGNING_IDENTITY }}
|
|
MACOS_INSTALLER_SIGNING_IDENTITY: ${{ secrets.MACOS_INSTALLER_SIGNING_IDENTITY }}
|
|
run: |
|
|
set -Eeuo pipefail
|
|
keychain_path="$RUNNER_TEMP/ydisks-signing.keychain-db"
|
|
keychain_password="$(uuidgen)"
|
|
app_p12_path="$RUNNER_TEMP/ydisks-signing-app.p12"
|
|
app_cert_path="$RUNNER_TEMP/ydisks-signing-app.pem"
|
|
installer_p12_path="$RUNNER_TEMP/ydisks-signing-installer.p12"
|
|
installer_cert_path="$RUNNER_TEMP/ydisks-signing-installer.pem"
|
|
printf '%s' "$MACOS_SIGNING_P12_BASE64" | base64 --decode > "$app_p12_path"
|
|
printf '%s' "$MACOS_INSTALLER_SIGNING_P12_BASE64" | base64 --decode > "$installer_p12_path"
|
|
security create-keychain -p "$keychain_password" "$keychain_path"
|
|
security set-keychain-settings -lut 21600 "$keychain_path"
|
|
security unlock-keychain -p "$keychain_password" "$keychain_path"
|
|
# 临时 CI 钥匙串使用 -A 授权签名工具,避免 set-key-partition-list 触发交互确认。
|
|
security import "$app_p12_path" -k "$keychain_path" -P "$MACOS_SIGNING_P12_PASSWORD" -A
|
|
security import "$installer_p12_path" -k "$keychain_path" -P "$MACOS_SIGNING_P12_PASSWORD" -A
|
|
security find-certificate -c "$MACOS_SIGNING_IDENTITY" -p "$keychain_path" > "$app_cert_path"
|
|
security find-certificate -c "$MACOS_INSTALLER_SIGNING_IDENTITY" -p "$keychain_path" > "$installer_cert_path"
|
|
# GitHub macOS hosted runner 提供免密码 sudo;只修改 admin Trust Settings,避免弹认证对话框。
|
|
# 不传 -k,避免 sudo 以 root 身份把同一张证书重复写入临时钥匙串,破坏私钥匹配。
|
|
sudo -n security add-trusted-cert -d -r trustRoot -p codeSign "$app_cert_path"
|
|
sudo -n security add-trusted-cert -d -r trustRoot -p basic "$installer_cert_path"
|
|
security list-keychains -d user -s "$keychain_path"
|
|
security unlock-keychain -p "$keychain_password" "$keychain_path"
|
|
echo "MACOS_SIGNING_KEYCHAIN=$keychain_path" >> "$GITHUB_ENV"
|
|
|
|
- name: 构建 macOS arm64 与 amd64 安装包
|
|
env:
|
|
MACOS_SIGNING_IDENTITY: ${{ secrets.MACOS_SIGNING_IDENTITY }}
|
|
MACOS_INSTALLER_SIGNING_IDENTITY: ${{ secrets.MACOS_INSTALLER_SIGNING_IDENTITY }}
|
|
run: |
|
|
set -Eeuo pipefail
|
|
chmod +x packaging/macos/build-pkg.sh
|
|
for arch in arm64 amd64; do
|
|
packaging/macos/build-pkg.sh "$APP_VERSION" "$PWD/dist/macos" "$arch"
|
|
done
|
|
|
|
- name: 上传 macOS arm64 安装包
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: ydisks-xianyu-helper-macos-arm64-${{ env.APP_VERSION }}
|
|
path: dist/macos/Ydisks-Xianyu-Helper-${{ env.APP_VERSION }}-arm64.pkg
|
|
if-no-files-found: error
|
|
|
|
- name: 上传 macOS amd64 安装包
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: ydisks-xianyu-helper-macos-amd64-${{ env.APP_VERSION }}
|
|
path: dist/macos/Ydisks-Xianyu-Helper-${{ env.APP_VERSION }}-amd64.pkg
|
|
if-no-files-found: error
|