248 lines
11 KiB
YAML
248 lines
11 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 安装包
|
|
if: github.ref == 'refs/heads/codex/desktop-packaging'
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
arch: [amd64, 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
|
|
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-${GOARCH}-${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: |
|
|
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 签名证书
|
|
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/browser-install.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/browser-install.exe,dist/windows/xianyu-tray.exe -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: |
|
|
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
|
|
lipo -create dist/macos/arm64/xianyu-server dist/macos/amd64/xianyu-server -output dist/macos/xianyu-server
|
|
lipo -create dist/macos/arm64/browser-install dist/macos/amd64/browser-install -output dist/macos/browser-install
|
|
lipo -create dist/macos/arm64/xianyu-tray dist/macos/amd64/xianyu-tray -output dist/macos/xianyu-tray
|
|
|
|
- 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 pkg
|
|
env:
|
|
MACOS_SIGNING_IDENTITY: ${{ secrets.MACOS_SIGNING_IDENTITY }}
|
|
MACOS_INSTALLER_SIGNING_IDENTITY: ${{ secrets.MACOS_INSTALLER_SIGNING_IDENTITY }}
|
|
run: |
|
|
chmod +x packaging/macos/build-pkg.sh
|
|
packaging/macos/build-pkg.sh "$APP_VERSION" "$PWD/dist/macos"
|
|
|
|
- name: 上传 macOS 安装包
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: ydisks-xianyu-helper-macos-${{ env.APP_VERSION }}
|
|
path: dist/macos/Ydisks-Xianyu-Helper-${{ env.APP_VERSION }}.pkg
|
|
if-no-files-found: error
|