|
| 1 | +name: Build Desktop App |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'desktop-v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: 'Version (e.g., 1.0.0)' |
| 11 | + required: false |
| 12 | + type: string |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + create-release: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + release_id: ${{ steps.create_release.outputs.id }} |
| 22 | + version: ${{ steps.get_version.outputs.version }} |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Get version |
| 27 | + id: get_version |
| 28 | + run: | |
| 29 | + if [ "${{ github.event.inputs.version }}" != "" ]; then |
| 30 | + VERSION="${{ github.event.inputs.version }}" |
| 31 | + elif [[ "${{ github.ref }}" == refs/tags/desktop-v* ]]; then |
| 32 | + VERSION="${{ github.ref_name }}" |
| 33 | + VERSION="${VERSION#desktop-v}" |
| 34 | + else |
| 35 | + VERSION="0.0.0-dev" |
| 36 | + fi |
| 37 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 38 | + echo "Version: $VERSION" |
| 39 | +
|
| 40 | + - name: Create Release |
| 41 | + id: create_release |
| 42 | + uses: softprops/action-gh-release@v1 |
| 43 | + with: |
| 44 | + tag_name: desktop-v${{ steps.get_version.outputs.version }} |
| 45 | + name: OpenContext Desktop v${{ steps.get_version.outputs.version }} |
| 46 | + body: | |
| 47 | + ## OpenContext Desktop v${{ steps.get_version.outputs.version }} |
| 48 | + |
| 49 | + ### 下载 |
| 50 | + - **macOS**: 下载 `.dmg` 文件,双击安装 |
| 51 | + - **Windows**: 下载 `.msi` 或 `.exe` 文件安装 |
| 52 | + |
| 53 | + ### 更新日志 |
| 54 | + 请查看 [CHANGELOG](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) |
| 55 | + draft: true |
| 56 | + prerelease: false |
| 57 | + |
| 58 | + build: |
| 59 | + needs: create-release |
| 60 | + strategy: |
| 61 | + fail-fast: false |
| 62 | + matrix: |
| 63 | + include: |
| 64 | + - platform: macos-latest |
| 65 | + target: universal-apple-darwin |
| 66 | + artifact_name: macos |
| 67 | + - platform: windows-latest |
| 68 | + target: x86_64-pc-windows-msvc |
| 69 | + artifact_name: windows |
| 70 | + |
| 71 | + runs-on: ${{ matrix.platform }} |
| 72 | + |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + |
| 76 | + - name: Setup Node.js |
| 77 | + uses: actions/setup-node@v4 |
| 78 | + with: |
| 79 | + node-version: 20 |
| 80 | + cache: 'npm' |
| 81 | + |
| 82 | + - name: Install Rust |
| 83 | + uses: dtolnay/rust-toolchain@stable |
| 84 | + with: |
| 85 | + targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }} |
| 86 | + |
| 87 | + - name: Cache Rust |
| 88 | + uses: Swatinem/rust-cache@v2 |
| 89 | + with: |
| 90 | + workspaces: src-tauri -> target |
| 91 | + |
| 92 | + - name: Install Protobuf (macOS) |
| 93 | + if: matrix.platform == 'macos-latest' |
| 94 | + run: brew install protobuf |
| 95 | + |
| 96 | + - name: Install Protobuf (Windows) |
| 97 | + if: matrix.platform == 'windows-latest' |
| 98 | + run: choco install protoc -y |
| 99 | + |
| 100 | + - name: Install npm dependencies |
| 101 | + run: npm ci --omit=optional |
| 102 | + |
| 103 | + - name: Update version in tauri.conf.json |
| 104 | + run: | |
| 105 | + node -e " |
| 106 | + const fs = require('fs'); |
| 107 | + const conf = JSON.parse(fs.readFileSync('src-tauri/tauri.conf.json', 'utf8')); |
| 108 | + conf.version = '${{ needs.create-release.outputs.version }}'; |
| 109 | + fs.writeFileSync('src-tauri/tauri.conf.json', JSON.stringify(conf, null, 2)); |
| 110 | + " |
| 111 | +
|
| 112 | + - name: Build Tauri app (macOS) |
| 113 | + if: matrix.platform == 'macos-latest' |
| 114 | + run: npm run tauri build -- --target universal-apple-darwin |
| 115 | + |
| 116 | + - name: Build Tauri app (Windows) |
| 117 | + if: matrix.platform == 'windows-latest' |
| 118 | + run: npm run tauri build |
| 119 | + |
| 120 | + - name: Upload to Release (macOS) |
| 121 | + if: matrix.platform == 'macos-latest' |
| 122 | + uses: softprops/action-gh-release@v1 |
| 123 | + with: |
| 124 | + tag_name: desktop-v${{ needs.create-release.outputs.version }} |
| 125 | + files: | |
| 126 | + src-tauri/target/universal-apple-darwin/release/bundle/dmg/*.dmg |
| 127 | +
|
| 128 | + - name: Upload to Release (Windows) |
| 129 | + if: matrix.platform == 'windows-latest' |
| 130 | + uses: softprops/action-gh-release@v1 |
| 131 | + with: |
| 132 | + tag_name: desktop-v${{ needs.create-release.outputs.version }} |
| 133 | + files: | |
| 134 | + src-tauri/target/release/bundle/msi/*.msi |
| 135 | + src-tauri/target/release/bundle/nsis/*.exe |
| 136 | +
|
| 137 | + publish-release: |
| 138 | + needs: [create-release, build] |
| 139 | + runs-on: ubuntu-latest |
| 140 | + steps: |
| 141 | + - name: Publish Release |
| 142 | + uses: softprops/action-gh-release@v1 |
| 143 | + with: |
| 144 | + tag_name: desktop-v${{ needs.create-release.outputs.version }} |
| 145 | + draft: false |
0 commit comments