mirror of
https://github.com/Minidoracat/mcp-feedback-enhanced.git
synced 2025-07-27 02:22:26 +08:00
233 lines
8.5 KiB
YAML
233 lines
8.5 KiB
YAML
name: Build Desktop Applications
|
|
|
|
on:
|
|
workflow_dispatch: # 手動觸發
|
|
inputs:
|
|
platforms:
|
|
description: '選擇要構建的平台'
|
|
required: true
|
|
default: 'all'
|
|
type: choice
|
|
options:
|
|
- all
|
|
- windows
|
|
- macos
|
|
- linux
|
|
upload_artifacts:
|
|
description: '是否上傳構建產物'
|
|
required: true
|
|
default: true
|
|
type: boolean
|
|
|
|
push:
|
|
paths:
|
|
- 'src-tauri/**' # 桌面應用代碼變更時自動觸發
|
|
- 'scripts/build_desktop.py'
|
|
branches:
|
|
- main
|
|
|
|
pull_request:
|
|
paths:
|
|
- 'src-tauri/**'
|
|
- 'scripts/build_desktop.py'
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
|
|
jobs:
|
|
# 多平台桌面應用構建
|
|
build-desktop:
|
|
strategy:
|
|
fail-fast: false # 允許部分平台失敗
|
|
matrix:
|
|
include:
|
|
- os: windows-latest
|
|
target: x86_64-pc-windows-msvc
|
|
binary: mcp-feedback-enhanced-desktop.exe
|
|
name: windows
|
|
enabled: ${{ github.event.inputs.platforms == 'all' || github.event.inputs.platforms == 'windows' || github.event.inputs.platforms == '' }}
|
|
- os: macos-latest
|
|
target: x86_64-apple-darwin
|
|
binary: mcp-feedback-enhanced-desktop
|
|
name: macos-intel
|
|
enabled: ${{ github.event.inputs.platforms == 'all' || github.event.inputs.platforms == 'macos' || github.event.inputs.platforms == '' }}
|
|
- os: macos-latest
|
|
target: aarch64-apple-darwin
|
|
binary: mcp-feedback-enhanced-desktop
|
|
name: macos-arm64
|
|
enabled: ${{ github.event.inputs.platforms == 'all' || github.event.inputs.platforms == 'macos' || github.event.inputs.platforms == '' }}
|
|
- os: ubuntu-latest
|
|
target: x86_64-unknown-linux-gnu
|
|
binary: mcp-feedback-enhanced-desktop
|
|
name: linux
|
|
enabled: ${{ github.event.inputs.platforms == 'all' || github.event.inputs.platforms == 'linux' || github.event.inputs.platforms == '' }}
|
|
|
|
runs-on: ${{ matrix.os }}
|
|
if: ${{ matrix.enabled != 'false' }}
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install Rust
|
|
uses: dtolnay/rust-toolchain@stable
|
|
with:
|
|
targets: ${{ matrix.target }}
|
|
|
|
- name: Install uv
|
|
uses: astral-sh/setup-uv@v4
|
|
with:
|
|
version: "latest"
|
|
|
|
- name: Set up Python
|
|
run: uv python install
|
|
|
|
- name: Install dependencies
|
|
run: uv sync --dev
|
|
|
|
- name: Cache Rust dependencies
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/.cargo/registry
|
|
~/.cargo/git
|
|
src-tauri/target
|
|
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-cargo-${{ matrix.target }}-
|
|
${{ runner.os }}-cargo-
|
|
|
|
- name: Install platform-specific dependencies (Linux)
|
|
if: matrix.os == 'ubuntu-latest'
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y \
|
|
libwebkit2gtk-4.1-dev \
|
|
libappindicator3-dev \
|
|
librsvg2-dev \
|
|
patchelf \
|
|
libgtk-3-dev \
|
|
libayatana-appindicator3-dev
|
|
|
|
- name: Build desktop application for ${{ matrix.name }}
|
|
run: |
|
|
cd src-tauri
|
|
echo "🔨 開始構建 ${{ matrix.name }} (${{ matrix.target }})..."
|
|
cargo build --release --target ${{ matrix.target }} --bin mcp-feedback-enhanced-desktop
|
|
echo "✅ 構建完成"
|
|
|
|
- name: Verify build output
|
|
run: |
|
|
echo "🔍 檢查構建產物..."
|
|
BINARY_PATH="src-tauri/target/${{ matrix.target }}/release/${{ matrix.binary }}"
|
|
|
|
if [ -f "$BINARY_PATH" ]; then
|
|
echo "✅ 找到二進制文件: $BINARY_PATH"
|
|
ls -la "$BINARY_PATH"
|
|
|
|
# 檢查文件大小
|
|
FILE_SIZE=$(stat -f%z "$BINARY_PATH" 2>/dev/null || stat -c%s "$BINARY_PATH" 2>/dev/null || echo "unknown")
|
|
echo "📏 文件大小: $FILE_SIZE bytes"
|
|
|
|
# 檢查文件類型 (僅在 Linux/macOS)
|
|
if [ "${{ matrix.os }}" != "windows-latest" ]; then
|
|
file "$BINARY_PATH" || echo "無法檢查文件類型"
|
|
fi
|
|
else
|
|
echo "❌ ${{ matrix.name }} 二進制文件不存在: $BINARY_PATH"
|
|
echo "🔍 檢查目標目錄內容:"
|
|
ls -la "src-tauri/target/${{ matrix.target }}/release/" || echo "目標目錄不存在"
|
|
exit 1
|
|
fi
|
|
shell: bash
|
|
|
|
- name: Upload desktop binary
|
|
if: ${{ github.event.inputs.upload_artifacts != 'false' }}
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: desktop-${{ matrix.name }}
|
|
path: src-tauri/target/${{ matrix.target }}/release/${{ matrix.binary }}
|
|
retention-days: 30 # 保留 30 天
|
|
compression-level: 6
|
|
if-no-files-found: error # 如果沒有找到文件則失敗
|
|
|
|
# 構建摘要和驗證
|
|
build-summary:
|
|
needs: build-desktop
|
|
runs-on: ubuntu-latest
|
|
if: always()
|
|
outputs:
|
|
build_success: ${{ steps.check_results.outputs.success }}
|
|
platforms_built: ${{ steps.check_results.outputs.platforms }}
|
|
|
|
steps:
|
|
- name: Check build results
|
|
id: check_results
|
|
run: |
|
|
echo "🔍 檢查構建結果..."
|
|
|
|
# 檢查構建狀態
|
|
BUILD_SUCCESS="false"
|
|
PLATFORMS_BUILT=""
|
|
|
|
if [ "${{ needs.build-desktop.result }}" = "success" ]; then
|
|
BUILD_SUCCESS="true"
|
|
PLATFORMS_BUILT="windows,macos-intel,macos-arm64,linux"
|
|
echo "✅ 所有平台構建成功"
|
|
else
|
|
echo "❌ 構建失敗或部分失敗"
|
|
fi
|
|
|
|
echo "success=$BUILD_SUCCESS" >> $GITHUB_OUTPUT
|
|
echo "platforms=$PLATFORMS_BUILT" >> $GITHUB_OUTPUT
|
|
|
|
- name: Generate build summary
|
|
run: |
|
|
echo "## 🖥️ 桌面應用構建摘要" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### 構建結果" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
|
|
# 檢查各平台構建狀態
|
|
if [ "${{ needs.build-desktop.result }}" = "success" ]; then
|
|
echo "✅ **所有平台構建成功**" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "| 平台 | 狀態 | 產物名稱 |" >> $GITHUB_STEP_SUMMARY
|
|
echo "|------|------|----------|" >> $GITHUB_STEP_SUMMARY
|
|
echo "| Windows x64 | ✅ 成功 | \`desktop-windows\` |" >> $GITHUB_STEP_SUMMARY
|
|
echo "| macOS Intel | ✅ 成功 | \`desktop-macos-intel\` |" >> $GITHUB_STEP_SUMMARY
|
|
echo "| macOS ARM64 | ✅ 成功 | \`desktop-macos-arm64\` |" >> $GITHUB_STEP_SUMMARY
|
|
echo "| Linux x64 | ✅ 成功 | \`desktop-linux\` |" >> $GITHUB_STEP_SUMMARY
|
|
elif [ "${{ needs.build-desktop.result }}" = "failure" ]; then
|
|
echo "❌ **部分平台構建失敗**" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "請檢查各平台的構建日誌以了解失敗原因。" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "⚠️ **構建狀態**: ${{ needs.build-desktop.result }}" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### 📦 產物信息" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **保留期限**: 30 天" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **下載位置**: GitHub Actions Artifacts" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **使用方式**: 在發佈工作流程中自動下載" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### 🚀 下一步" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
|
|
if [ "${{ needs.build-desktop.result }}" = "success" ]; then
|
|
echo "✅ **可以進行發佈**" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "1. 前往 [Auto Release to PyPI](../../actions/workflows/publish.yml)" >> $GITHUB_STEP_SUMMARY
|
|
echo "2. 點擊 'Run workflow'" >> $GITHUB_STEP_SUMMARY
|
|
echo "3. 設置 'include_desktop' 為 true" >> $GITHUB_STEP_SUMMARY
|
|
echo "4. 可選:指定此次構建的 Run ID: \`${{ github.run_id }}\`" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "❌ **請修復構建問題後重新運行**" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "- 檢查構建日誌中的錯誤信息" >> $GITHUB_STEP_SUMMARY
|
|
echo "- 修復問題後重新觸發此工作流程" >> $GITHUB_STEP_SUMMARY
|
|
echo "- 確保所有平台都能成功構建後再進行發佈" >> $GITHUB_STEP_SUMMARY
|
|
fi
|