Переглянути джерело

拆分为按平台的工作流

黄中银 2 тижнів тому
батько
коміт
31d2584bee

+ 55 - 0
.github/workflows/build-linux.yml

@@ -0,0 +1,55 @@
+name: Build Linux
+
+on:
+  workflow_dispatch:  # 手动触发,用于单独调试
+  workflow_call:      # 被其他工作流调用
+
+jobs:
+  build:
+    runs-on: ubuntu-22.04
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Setup Node.js
+        uses: actions/setup-node@v4
+        with:
+          node-version: '20'
+          cache: 'npm'
+
+      - name: Install Rust toolchain
+        uses: dtolnay/rust-toolchain@stable
+        with:
+          targets: x86_64-unknown-linux-gnu
+
+      - name: Cache Rust
+        uses: Swatinem/rust-cache@v2
+        with:
+          workspaces: src-tauri -> target
+          cache-targets: true
+          shared-key: x86_64-unknown-linux-gnu
+
+      - name: Install Linux dependencies (cached)
+        uses: awalsh128/cache-apt-pkgs-action@latest
+        with:
+          packages: libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf libgtk-3-dev
+          version: 1.0
+
+      - name: Install dependencies
+        run: npm ci
+
+      - name: Build application
+        env:
+          TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
+          TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ""
+        run: |
+          chmod +x build-linux.sh
+          node scripts/build.js --target x86_64-unknown-linux-gnu
+
+      - name: Upload artifacts
+        uses: actions/upload-artifact@v4
+        with:
+          name: artifacts-linux
+          path: built/*
+          if-no-files-found: error

+ 103 - 0
.github/workflows/build-macos.yml

@@ -0,0 +1,103 @@
+name: Build macOS
+
+on:
+  workflow_dispatch:  # 手动触发,用于单独调试
+    inputs:
+      target:
+        description: '构建目标'
+        type: choice
+        options:
+          - all
+          - arm64
+          - x64
+        default: 'all'
+  workflow_call:      # 被其他工作流调用
+
+jobs:
+  build-arm64:
+    if: ${{ github.event_name == 'workflow_call' || inputs.target == 'all' || inputs.target == 'arm64' }}
+    runs-on: macos-latest
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Setup Node.js
+        uses: actions/setup-node@v4
+        with:
+          node-version: '20'
+          cache: 'npm'
+
+      - name: Install Rust toolchain
+        uses: dtolnay/rust-toolchain@stable
+        with:
+          targets: aarch64-apple-darwin
+
+      - name: Cache Rust
+        uses: Swatinem/rust-cache@v2
+        with:
+          workspaces: src-tauri -> target
+          cache-targets: true
+          shared-key: aarch64-apple-darwin
+
+      - name: Install dependencies
+        run: npm ci
+
+      - name: Build application
+        env:
+          TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
+          TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ""
+        run: |
+          chmod +x build-mac.sh
+          node scripts/build.js --target aarch64-apple-darwin
+
+      - name: Upload artifacts
+        uses: actions/upload-artifact@v4
+        with:
+          name: artifacts-mac-arm64
+          path: built/*
+          if-no-files-found: error
+
+  build-x64:
+    if: ${{ github.event_name == 'workflow_call' || inputs.target == 'all' || inputs.target == 'x64' }}
+    runs-on: macos-latest
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Setup Node.js
+        uses: actions/setup-node@v4
+        with:
+          node-version: '20'
+          cache: 'npm'
+
+      - name: Install Rust toolchain
+        uses: dtolnay/rust-toolchain@stable
+        with:
+          targets: x86_64-apple-darwin
+
+      - name: Cache Rust
+        uses: Swatinem/rust-cache@v2
+        with:
+          workspaces: src-tauri -> target
+          cache-targets: true
+          shared-key: x86_64-apple-darwin
+
+      - name: Install dependencies
+        run: npm ci
+
+      - name: Build application
+        env:
+          TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
+          TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ""
+        run: |
+          chmod +x build-mac.sh
+          node scripts/build.js --target x86_64-apple-darwin
+
+      - name: Upload artifacts
+        uses: actions/upload-artifact@v4
+        with:
+          name: artifacts-mac-x64
+          path: built/*
+          if-no-files-found: error

+ 47 - 0
.github/workflows/build-windows.yml

@@ -0,0 +1,47 @@
+name: Build Windows
+
+on:
+  workflow_dispatch:  # 手动触发,用于单独调试
+  workflow_call:      # 被其他工作流调用
+
+jobs:
+  build:
+    runs-on: windows-latest
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Setup Node.js
+        uses: actions/setup-node@v4
+        with:
+          node-version: '20'
+          cache: 'npm'
+
+      - name: Install Rust toolchain
+        uses: dtolnay/rust-toolchain@stable
+        with:
+          targets: x86_64-pc-windows-msvc
+
+      - name: Cache Rust
+        uses: Swatinem/rust-cache@v2
+        with:
+          workspaces: src-tauri -> target
+          cache-targets: true
+          shared-key: x86_64-pc-windows-msvc
+
+      - name: Install dependencies
+        run: npm ci
+
+      - name: Build application
+        env:
+          TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
+          TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ""
+        run: node scripts/build.js --target x86_64-pc-windows-msvc
+
+      - name: Upload artifacts
+        uses: actions/upload-artifact@v4
+        with:
+          name: artifacts-win
+          path: built/*
+          if-no-files-found: error

+ 14 - 75
.github/workflows/release.yml

@@ -1,90 +1,28 @@
 name: Release
 
 on:
+  workflow_dispatch:  # 手动触发,用于集成测试
   push:
     tags:
       - 'v*'
 
 jobs:
-  # 第一步:并行构建所有平台
-  build:
-    strategy:
-      fail-fast: false
-      matrix:
-        include:
-          - os: windows-latest
-            platform: win
-            target: x86_64-pc-windows-msvc
-          - os: macos-latest
-            platform: mac
-            target: aarch64-apple-darwin
-          - os: macos-latest
-            platform: mac-intel
-            target: x86_64-apple-darwin
-          - os: ubuntu-22.04
-            platform: linux
-            target: x86_64-unknown-linux-gnu
+  # 调用各平台构建工作流
+  build-windows:
+    uses: ./.github/workflows/build-windows.yml
+    secrets: inherit
 
-    runs-on: ${{ matrix.os }}
+  build-macos:
+    uses: ./.github/workflows/build-macos.yml
+    secrets: inherit
 
-    steps:
-      - name: Checkout code
-        uses: actions/checkout@v4
-
-      - name: Setup Node.js
-        uses: actions/setup-node@v4
-        with:
-          node-version: '20'
-          cache: 'npm'
-
-      - name: Install Rust toolchain
-        uses: dtolnay/rust-toolchain@stable
-        with:
-          targets: ${{ matrix.target }}
-
-      - name: Cache Rust
-        uses: Swatinem/rust-cache@v2
-        with:
-          workspaces: src-tauri -> target
-          cache-targets: true
-          shared-key: ${{ matrix.target }}
-
-      - name: Install Linux dependencies (cached)
-        if: matrix.platform == 'linux'
-        uses: awalsh128/cache-apt-pkgs-action@latest
-        with:
-          packages: libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf libgtk-3-dev
-          version: 1.0
-
-      - name: Install dependencies
-        run: npm ci
-
-      - name: Build application (Windows)
-        if: matrix.platform == 'win'
-        env:
-          TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
-          TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ""
-        run: node scripts/build.js --target ${{ matrix.target }}
-
-      - name: Build application (macOS/Linux)
-        if: matrix.platform != 'win'
-        env:
-          TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
-          TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ""
-        run: |
-          chmod +x build-mac.sh build-linux.sh
-          node scripts/build.js --target ${{ matrix.target }}
-
-      - name: Upload artifacts
-        uses: actions/upload-artifact@v4
-        with:
-          name: artifacts-${{ matrix.platform }}
-          path: built/*
-          if-no-files-found: error
+  build-linux:
+    uses: ./.github/workflows/build-linux.yml
+    secrets: inherit
 
-  # 第二步:创建 Release 并上传所有产物
+  # 所有构建完成后创建 Release
   release:
-    needs: build
+    needs: [build-windows, build-macos, build-linux]
     runs-on: ubuntu-latest
     permissions:
       contents: write
@@ -117,6 +55,7 @@ jobs:
 
             ### Linux
             - `*-linux-x64.deb` - Debian/Ubuntu
+            - `*-linux-x64.rpm` - Fedora/RHEL/CentOS
             - `*-linux-x64.AppImage` - 通用 AppImage
           draft: false
           prerelease: false

+ 1 - 1
src-tauri/src/commands/install.rs

@@ -580,7 +580,7 @@ where
 async fn install_vscode<F, C>(
     _app: &tauri::AppHandle,
     _state: &State<'_, AppState>,
-    #[cfg_attr(target_os = "macos", allow(unused_variables))]
+    #[cfg_attr(any(target_os = "macos", target_os = "linux"), allow(unused_variables))]
     options: &InstallOptions,
     emit_status: F,
     is_cancelled: C,