ci(release): generate macOS zip, Windows installer + portable, Linux deb; split per-OS build and asset steps

This commit is contained in:
Jason
2025-08-29 14:57:33 +08:00
parent a05fefb54c
commit 49d8787ab9

View File

@@ -30,6 +30,11 @@ jobs:
- name: Setup Rust - name: Setup Rust
uses: dtolnay/rust-toolchain@stable uses: dtolnay/rust-toolchain@stable
- name: Add macOS targets
if: runner.os == 'macOS'
run: |
rustup target add aarch64-apple-darwin x86_64-apple-darwin
- name: Install Linux system deps - name: Install Linux system deps
if: runner.os == 'Linux' if: runner.os == 'Linux'
shell: bash shell: bash
@@ -78,74 +83,102 @@ jobs:
- name: Install frontend deps - name: Install frontend deps
run: pnpm install --frozen-lockfile run: pnpm install --frozen-lockfile
- name: Build Tauri App - name: Build Tauri App (macOS)
shell: bash if: runner.os == 'macOS'
run: | run: pnpm tauri build --target universal-apple-darwin
if [ "${{ runner.os }}" == "macOS" ]; then
# macOS: 只构建 app bundle (用于创建 zip)
pnpm tauri build --target aarch64-apple-darwin
elif [ "${{ runner.os }}" == "Windows" ]; then
# Windows: 构建 NSIS 安装器
pnpm tauri build --target x86_64-pc-windows-msvc
else
# Linux: 构建 AppImage 和 deb
pnpm tauri build
fi
- name: Prepare Release Assets - name: Build Tauri App (Windows)
id: prepare if: runner.os == 'Windows'
run: pnpm tauri build
- name: Build Tauri App (Linux)
if: runner.os == 'Linux'
run: pnpm tauri build
- name: Prepare macOS Assets
if: runner.os == 'macOS'
shell: bash shell: bash
run: | run: |
set -euxo pipefail
mkdir -p release-assets mkdir -p release-assets
echo "Looking for .app bundle..."
if [ "${{ runner.os }}" == "macOS" ]; then APP_PATH=""
# macOS: 创建 zip 包 for path in \
APP_PATH=$(find src-tauri/target/release/bundle/macos -name "*.app" -type d | head -1) "src-tauri/target/release/bundle/macos" \
if [ -n "$APP_PATH" ]; then "src-tauri/target/universal-apple-darwin/release/bundle/macos" \
"src-tauri/target/aarch64-apple-darwin/release/bundle/macos" \
"src-tauri/target/x86_64-apple-darwin/release/bundle/macos"; do
if [ -d "$path" ]; then
APP_PATH=$(find "$path" -name "*.app" -type d | head -1)
[ -n "$APP_PATH" ] && break
fi
done
if [ -z "$APP_PATH" ]; then
echo "No .app found" >&2
exit 1
fi
APP_DIR=$(dirname "$APP_PATH")
APP_NAME=$(basename "$APP_PATH") APP_NAME=$(basename "$APP_PATH")
cd "$(dirname "$APP_PATH")" cd "$APP_DIR"
zip -r "CC-Switch-macOS.zip" "$APP_NAME" # 使用 ditto 打包更兼容资源分叉
ditto -c -k --sequesterRsrc --keepParent "$APP_NAME" "CC-Switch-macOS.zip"
mv "CC-Switch-macOS.zip" "$GITHUB_WORKSPACE/release-assets/" mv "CC-Switch-macOS.zip" "$GITHUB_WORKSPACE/release-assets/"
echo "Created macOS zip" echo "macOS zip ready"
fi
elif [ "${{ runner.os }}" == "Windows" ]; then - name: Prepare Windows Assets
# Windows: 复制 NSIS 安装器 if: runner.os == 'Windows'
NSIS_PATH=$(find src-tauri/target/release/bundle/nsis -name "*.exe" | head -1) shell: pwsh
if [ -n "$NSIS_PATH" ]; then run: |
cp "$NSIS_PATH" "release-assets/CC-Switch-Setup.exe" $ErrorActionPreference = 'Stop'
echo "Copied Windows installer" New-Item -ItemType Directory -Force -Path release-assets | Out-Null
fi # 安装器(优先 NSIS其次 MSI
$installer = Get-ChildItem -Path 'src-tauri/target/release/bundle' -Recurse -Include *.exe,*.msi -ErrorAction SilentlyContinue |
# Windows: 创建绿色版 (portable) Where-Object { $_.FullName -match '\\bundle\\(nsis|msi)\\' } |
EXE_PATH="src-tauri/target/release/cc-switch.exe" Select-Object -First 1
if [ -f "$EXE_PATH" ]; then if ($null -ne $installer) {
mkdir -p "release-assets/CC-Switch-Portable" $dest = if ($installer.Extension -ieq '.msi') { 'CC-Switch-Setup.msi' } else { 'CC-Switch-Setup.exe' }
cp "$EXE_PATH" "release-assets/CC-Switch-Portable/" Copy-Item $installer.FullName (Join-Path release-assets $dest)
cd release-assets Write-Host "Installer copied: $dest"
zip -r "CC-Switch-Windows-Portable.zip" "CC-Switch-Portable" } else {
rm -rf "CC-Switch-Portable" Write-Warning 'No Windows installer found'
cd .. }
echo "Created Windows portable version" # 绿色版portable仅可执行文件
fi $exeCandidates = @(
'src-tauri/target/release/cc-switch.exe',
else 'src-tauri/target/x86_64-pc-windows-msvc/release/cc-switch.exe'
# Linux: 复制 AppImage 和 deb )
APPIMAGE=$(find src-tauri/target/release/bundle -name "*.AppImage" | head -1) $exePath = $exeCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
DEB=$(find src-tauri/target/release/bundle -name "*.deb" | head -1) if ($null -ne $exePath) {
$portableDir = 'release-assets/CC-Switch-Portable'
if [ -n "$APPIMAGE" ]; then New-Item -ItemType Directory -Force -Path $portableDir | Out-Null
cp "$APPIMAGE" "release-assets/CC-Switch.AppImage" Copy-Item $exePath $portableDir
echo "Copied AppImage" Compress-Archive -Path "$portableDir/*" -DestinationPath 'release-assets/CC-Switch-Windows-Portable.zip' -Force
fi Remove-Item -Recurse -Force $portableDir
Write-Host 'Windows portable zip created'
} else {
Write-Warning 'Portable exe not found'
}
- name: Prepare Linux Assets
if: runner.os == 'Linux'
shell: bash
run: |
set -euxo pipefail
mkdir -p release-assets
# 仅上传安装包deb
DEB=$(find src-tauri/target/release/bundle -name "*.deb" | head -1 || true)
if [ -n "$DEB" ]; then if [ -n "$DEB" ]; then
cp "$DEB" "release-assets/" cp "$DEB" release-assets/
echo "Copied deb package" echo "Deb package copied"
fi else
echo "No .deb found" >&2
exit 1
fi fi
ls -la release-assets/ - name: List prepared assets
shell: bash
run: |
ls -la release-assets || true
- name: Upload Release Assets - name: Upload Release Assets
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
@@ -157,22 +190,14 @@ jobs:
Claude Code 供应商切换工具 Claude Code 供应商切换工具
### 下载说明 ### 下载
#### macOS - macOS: `CC-Switch-macOS.zip`(解压即用)
- `CC-Switch-macOS.zip` - 解压即用(推荐 - Windows: `CC-Switch-Setup.exe` 或 `CC-Switch-Setup.msi`(安装版);`CC-Switch-Windows-Portable.zip`(绿色版
- Linux: `*.deb`Debian/Ubuntu 安装包)
#### Windows
- `CC-Switch-Setup.exe` - 安装版
- `CC-Switch-Windows-Portable.zip` - 绿色版,解压即用
#### Linux
- `CC-Switch.AppImage` - AppImage 格式
- `*.deb` - Debian/Ubuntu 安装包
--- ---
提示macOS 如遇“已损坏”提示,可在终端执行:`xattr -cr "/Applications/CC Switch.app"`
**macOS 签名问题**:如遇"已损坏"提示,请在终端运行 `xattr -cr "/Applications/CC Switch.app"`
files: release-assets/* files: release-assets/*
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}