|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + # 新发布触发 |
| 5 | + release: |
| 6 | + types: [ published ] |
| 7 | + |
| 8 | + # 手动触发 |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + tag: |
| 12 | + description: 'Release tag (e.g., v1.0.0)' |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +env: |
| 17 | + CARGO_TERM_COLOR: always |
| 18 | + NODE_VERSION: '18' |
| 19 | + RUST_VERSION: '1.85.0' |
| 20 | + PNPM_VERSION: '8' |
| 21 | + |
| 22 | +jobs: |
| 23 | + # 构建发布版本 |
| 24 | + build-release: |
| 25 | + name: Build Release |
| 26 | + runs-on: ${{ matrix.platform }} |
| 27 | + |
| 28 | + strategy: |
| 29 | + fail-fast: false |
| 30 | + matrix: |
| 31 | + platform: [ macos-latest, windows-latest ] |
| 32 | + include: |
| 33 | + - platform: macos-latest |
| 34 | + os: macos |
| 35 | + target: universal-apple-darwin |
| 36 | + - platform: windows-latest |
| 37 | + os: windows |
| 38 | + target: x86_64-pc-windows-msvc |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Checkout repository |
| 42 | + uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - name: Setup Node.js |
| 45 | + uses: actions/setup-node@v4 |
| 46 | + with: |
| 47 | + node-version: ${{ env.NODE_VERSION }} |
| 48 | + |
| 49 | + - name: Setup pnpm |
| 50 | + uses: pnpm/action-setup@v2 |
| 51 | + with: |
| 52 | + version: ${{ env.PNPM_VERSION }} |
| 53 | + |
| 54 | + - name: Setup Rust |
| 55 | + uses: dtolnay/rust-toolchain@stable |
| 56 | + with: |
| 57 | + toolchain: ${{ env.RUST_VERSION }} |
| 58 | + |
| 59 | + - name: Add Rust targets (macOS) |
| 60 | + if: matrix.platform == 'macos-latest' |
| 61 | + run: | |
| 62 | + rustup target add aarch64-apple-darwin |
| 63 | + rustup target add x86_64-apple-darwin |
| 64 | +
|
| 65 | + - name: Rust Cache |
| 66 | + uses: Swatinem/rust-cache@v2 |
| 67 | + with: |
| 68 | + workspaces: src-tauri |
| 69 | + |
| 70 | + - name: Install frontend dependencies |
| 71 | + run: | |
| 72 | + if [ -f "pnpm-lock.yaml" ]; then |
| 73 | + pnpm install --frozen-lockfile |
| 74 | + else |
| 75 | + pnpm install |
| 76 | + fi |
| 77 | + shell: bash |
| 78 | + |
| 79 | + - name: Build application |
| 80 | + run: pnpm tauri build --target ${{ matrix.target }} |
| 81 | + |
| 82 | + - name: List build output (debug) |
| 83 | + run: | |
| 84 | + echo "=== Build output structure ===" |
| 85 | + find src-tauri/target -name "*.dmg" -o -name "*.app" -o -name "*.msi" -o -name "*.exe" | grep -E "\.(dmg|app|msi)$|CodeForge.*\.exe$" | head -20 |
| 86 | + echo "=== Target directories ===" |
| 87 | + ls -la src-tauri/target/ || echo "Target directory not found" |
| 88 | + echo "=== Bundle directories ===" |
| 89 | + find src-tauri/target -name "bundle" -type d | head -10 |
| 90 | + shell: bash |
| 91 | + |
| 92 | + - name: Upload build artifacts (macOS) |
| 93 | + if: matrix.platform == 'macos-latest' |
| 94 | + uses: actions/upload-artifact@v4 |
| 95 | + with: |
| 96 | + name: release-${{ matrix.os }} |
| 97 | + path: | |
| 98 | + src-tauri/target/universal-apple-darwin/release/bundle/dmg/*.dmg |
| 99 | + src-tauri/target/universal-apple-darwin/release/bundle/macos/*.app |
| 100 | + retention-days: 30 |
| 101 | + |
| 102 | + - name: Upload build artifacts (Windows) |
| 103 | + if: matrix.platform == 'windows-latest' |
| 104 | + uses: actions/upload-artifact@v4 |
| 105 | + with: |
| 106 | + name: release-${{ matrix.os }} |
| 107 | + path: | |
| 108 | + src-tauri/target/x86_64-pc-windows-msvc/release/bundle/msi/*.msi |
| 109 | + src-tauri/target/x86_64-pc-windows-msvc/release/bundle/nsis/*.exe |
| 110 | + retention-days: 30 |
| 111 | + |
| 112 | + # 创建或更新 GitHub Release |
| 113 | + create-release: |
| 114 | + name: Create Release |
| 115 | + needs: build-release |
| 116 | + runs-on: ubuntu-latest |
| 117 | + if: github.event_name == 'workflow_dispatch' |
| 118 | + |
| 119 | + steps: |
| 120 | + - name: Download all artifacts |
| 121 | + uses: actions/download-artifact@v4 |
| 122 | + with: |
| 123 | + path: artifacts |
| 124 | + |
| 125 | + - name: Prepare release assets |
| 126 | + run: | |
| 127 | + mkdir -p release-assets |
| 128 | + find artifacts -name "*.dmg" -exec cp {} release-assets/ \; |
| 129 | + find artifacts -name "*.msi" -exec cp {} release-assets/ \; |
| 130 | + find artifacts -name "*.exe" -exec cp {} release-assets/ \; |
| 131 | +
|
| 132 | + - name: Create Release |
| 133 | + uses: softprops/action-gh-release@v1 |
| 134 | + with: |
| 135 | + tag_name: ${{ github.event.inputs.tag }} |
| 136 | + name: Release ${{ github.event.inputs.tag }} |
| 137 | + files: release-assets/* |
| 138 | + env: |
| 139 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 140 | + |
| 141 | + # 更新现有 Release |
| 142 | + update-release: |
| 143 | + name: Update Release |
| 144 | + needs: build-release |
| 145 | + runs-on: ubuntu-latest |
| 146 | + if: github.event_name == 'release' |
| 147 | + |
| 148 | + steps: |
| 149 | + - name: Download all artifacts |
| 150 | + uses: actions/download-artifact@v4 |
| 151 | + with: |
| 152 | + path: artifacts |
| 153 | + |
| 154 | + - name: Prepare release assets |
| 155 | + run: | |
| 156 | + mkdir -p release-assets |
| 157 | + find artifacts -name "*.dmg" -exec cp {} release-assets/ \; |
| 158 | + find artifacts -name "*.msi" -exec cp {} release-assets/ \; |
| 159 | + find artifacts -name "*.exe" -exec cp {} release-assets/ \; |
| 160 | +
|
| 161 | + - name: Upload to existing release |
| 162 | + uses: softprops/action-gh-release@v1 |
| 163 | + with: |
| 164 | + tag_name: ${{ github.event.release.tag_name }} |
| 165 | + files: release-assets/* |
| 166 | + env: |
| 167 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
0 commit comments