|
| 1 | +name: Build Tauri |
| 2 | + |
| 3 | +# Reusable build for the desktop app across all platforms. Shared by the |
| 4 | +# stable release flow, the per-merge pre-release flow, and the promote flow so |
| 5 | +# every channel is built with identical logic (no drift). |
| 6 | +on: |
| 7 | + workflow_call: |
| 8 | + inputs: |
| 9 | + ref: |
| 10 | + description: 'Git ref to build (empty = the caller ref)' |
| 11 | + type: string |
| 12 | + default: '' |
| 13 | + set_version: |
| 14 | + description: 'If set, stamp this version onto the working tree before building' |
| 15 | + type: string |
| 16 | + default: '' |
| 17 | + release_id: |
| 18 | + description: 'Upload artifacts to this existing release id (stable flow)' |
| 19 | + type: string |
| 20 | + default: '' |
| 21 | + tag_name: |
| 22 | + description: 'Create/append to a release with this tag (pre-release / promote flow)' |
| 23 | + type: string |
| 24 | + default: '' |
| 25 | + release_name: |
| 26 | + description: 'Release title when creating via tag_name' |
| 27 | + type: string |
| 28 | + default: '' |
| 29 | + release_body: |
| 30 | + description: 'Release body when creating via tag_name' |
| 31 | + type: string |
| 32 | + default: '' |
| 33 | + prerelease: |
| 34 | + description: 'Mark the created release as a pre-release' |
| 35 | + type: boolean |
| 36 | + default: false |
| 37 | + draft: |
| 38 | + description: 'Create the release as a draft' |
| 39 | + type: boolean |
| 40 | + default: false |
| 41 | + apple_full_signing: |
| 42 | + description: 'Import the Apple Developer cert (true) or ad-hoc sign (false)' |
| 43 | + type: boolean |
| 44 | + default: true |
| 45 | + |
| 46 | +env: |
| 47 | + CARGO_TERM_COLOR: always |
| 48 | + |
| 49 | +jobs: |
| 50 | + build: |
| 51 | + strategy: |
| 52 | + fail-fast: false |
| 53 | + matrix: |
| 54 | + include: |
| 55 | + - os: ubuntu-latest |
| 56 | + target: x86_64-unknown-linux-gnu |
| 57 | + artifact: linux |
| 58 | + - os: windows-latest |
| 59 | + target: x86_64-pc-windows-msvc |
| 60 | + artifact: windows |
| 61 | + - os: macos-latest |
| 62 | + target: aarch64-apple-darwin |
| 63 | + artifact: macos-arm |
| 64 | + - os: macos-15-intel |
| 65 | + target: x86_64-apple-darwin |
| 66 | + artifact: macos-intel |
| 67 | + |
| 68 | + runs-on: ${{ matrix.os }} |
| 69 | + permissions: |
| 70 | + contents: write |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v4 |
| 73 | + with: |
| 74 | + ref: ${{ inputs.ref }} |
| 75 | + |
| 76 | + # Stamp a pre-release / promote version onto the working tree (transient, |
| 77 | + # never committed) so the binary, bundle, and latest.json all agree. |
| 78 | + - name: Set build version |
| 79 | + if: inputs.set_version != '' |
| 80 | + shell: bash |
| 81 | + run: node scripts/set-version.mjs "${{ inputs.set_version }}" |
| 82 | + |
| 83 | + - name: Install Linux deps |
| 84 | + if: matrix.os == 'ubuntu-latest' |
| 85 | + uses: ./.github/actions/install-linux-deps |
| 86 | + with: |
| 87 | + verify_glib: 'false' |
| 88 | + |
| 89 | + - uses: dtolnay/rust-toolchain@stable |
| 90 | + with: |
| 91 | + targets: ${{ matrix.target }} |
| 92 | + env: |
| 93 | + PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig |
| 94 | + |
| 95 | + - uses: Swatinem/rust-cache@v2 |
| 96 | + with: |
| 97 | + key: ${{ matrix.target }}-release |
| 98 | + env: |
| 99 | + PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig |
| 100 | + |
| 101 | + - uses: pnpm/action-setup@v4 |
| 102 | + - uses: actions/setup-node@v4 |
| 103 | + with: |
| 104 | + node-version: 20 |
| 105 | + cache: 'pnpm' |
| 106 | + |
| 107 | + - run: pnpm install --frozen-lockfile |
| 108 | + |
| 109 | + # Import Apple certificate ourselves, then DON'T pass APPLE_CERTIFICATE |
| 110 | + # to tauri-action. Tauri's bundler uses var_os() which treats empty |
| 111 | + # strings as present (Some("")), so we must completely omit the env var. |
| 112 | + # Instead we import the cert here and only pass APPLE_SIGNING_IDENTITY. |
| 113 | + # When apple_full_signing is false (pre-releases), we ad-hoc sign ("-"). |
| 114 | + - name: Import Apple certificate |
| 115 | + if: runner.os == 'macOS' |
| 116 | + id: apple-cert |
| 117 | + env: |
| 118 | + APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }} |
| 119 | + APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }} |
| 120 | + KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} |
| 121 | + run: | |
| 122 | + if [ "${{ inputs.apple_full_signing }}" != "true" ]; then |
| 123 | + echo "Ad-hoc signing requested (pre-release build)" |
| 124 | + echo "identity=-" >> "$GITHUB_OUTPUT" |
| 125 | + exit 0 |
| 126 | + fi |
| 127 | + if [ -z "$APPLE_CERTIFICATE" ] || [ -z "$KEYCHAIN_PASSWORD" ]; then |
| 128 | + echo "No Apple certificate configured — using ad-hoc signing" |
| 129 | + echo "identity=-" >> "$GITHUB_OUTPUT" |
| 130 | + exit 0 |
| 131 | + fi |
| 132 | + echo "$APPLE_CERTIFICATE" | base64 --decode > certificate.p12 |
| 133 | + if [ ! -s certificate.p12 ]; then |
| 134 | + echo "Certificate decode produced empty file — using ad-hoc signing" |
| 135 | + rm -f certificate.p12 |
| 136 | + echo "identity=-" >> "$GITHUB_OUTPUT" |
| 137 | + exit 0 |
| 138 | + fi |
| 139 | + security create-keychain -p "$KEYCHAIN_PASSWORD" build.keychain |
| 140 | + security default-keychain -s build.keychain |
| 141 | + security unlock-keychain -p "$KEYCHAIN_PASSWORD" build.keychain |
| 142 | + if ! security import certificate.p12 -k build.keychain -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign; then |
| 143 | + echo "Certificate import failed — using ad-hoc signing" |
| 144 | + rm -f certificate.p12 |
| 145 | + echo "identity=-" >> "$GITHUB_OUTPUT" |
| 146 | + exit 0 |
| 147 | + fi |
| 148 | + security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" build.keychain |
| 149 | + rm certificate.p12 |
| 150 | + echo "identity=${{ secrets.APPLE_SIGNING_IDENTITY }}" >> "$GITHUB_OUTPUT" |
| 151 | + echo "cert_ok=true" >> "$GITHUB_OUTPUT" |
| 152 | +
|
| 153 | + # IMPORTANT: Do NOT pass APPLE_CERTIFICATE, APPLE_ID, APPLE_PASSWORD, |
| 154 | + # or APPLE_TEAM_ID to tauri-action. Tauri's bundler uses var_os() which |
| 155 | + # treats empty strings as "present" and attempts certificate import / |
| 156 | + # notarization even when values are empty, causing build failures. |
| 157 | + # We handle cert import ourselves above and only pass APPLE_SIGNING_IDENTITY. |
| 158 | + # |
| 159 | + # Two variants so each path passes EXACTLY the inputs it needs: |
| 160 | + # • release_id set → upload to the pre-created (draft) release by id. |
| 161 | + # Pass ONLY releaseId — never tagName/draft/prerelease, which could |
| 162 | + # flip the draft early or mismatch its state. (Stable + promote.) |
| 163 | + # • release_id empty → create/append to a tagged release. (Pre-release.) |
| 164 | + - name: Build Tauri app (upload to existing release) |
| 165 | + if: inputs.release_id != '' |
| 166 | + uses: tauri-apps/tauri-action@v0 |
| 167 | + env: |
| 168 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 169 | + TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }} |
| 170 | + TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} |
| 171 | + PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig |
| 172 | + APPLE_SIGNING_IDENTITY: ${{ runner.os == 'macOS' && steps.apple-cert.outputs.identity || '' }} |
| 173 | + VITE_POSTHOG_KEY: ${{ secrets.VITE_POSTHOG_KEY }} |
| 174 | + VITE_POSTHOG_HOST: ${{ secrets.VITE_POSTHOG_HOST }} |
| 175 | + with: |
| 176 | + projectPath: apps/desktop |
| 177 | + releaseId: ${{ inputs.release_id }} |
| 178 | + updaterJsonKeepUniversal: true |
| 179 | + args: --target ${{ matrix.target }} |
| 180 | + |
| 181 | + - name: Build Tauri app (create tagged release) |
| 182 | + if: inputs.release_id == '' |
| 183 | + uses: tauri-apps/tauri-action@v0 |
| 184 | + env: |
| 185 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 186 | + TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }} |
| 187 | + TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} |
| 188 | + PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig |
| 189 | + APPLE_SIGNING_IDENTITY: ${{ runner.os == 'macOS' && steps.apple-cert.outputs.identity || '' }} |
| 190 | + VITE_POSTHOG_KEY: ${{ secrets.VITE_POSTHOG_KEY }} |
| 191 | + VITE_POSTHOG_HOST: ${{ secrets.VITE_POSTHOG_HOST }} |
| 192 | + with: |
| 193 | + projectPath: apps/desktop |
| 194 | + tagName: ${{ inputs.tag_name }} |
| 195 | + releaseName: ${{ inputs.release_name }} |
| 196 | + releaseBody: ${{ inputs.release_body }} |
| 197 | + releaseDraft: ${{ inputs.draft }} |
| 198 | + prerelease: ${{ inputs.prerelease }} |
| 199 | + updaterJsonKeepUniversal: true |
| 200 | + args: --target ${{ matrix.target }} |
0 commit comments