Open History to see the last commit
1name: Release desktop build
2
3# One desktop platform/arch build, called once per target from release.yml so
4# each target is its own job with its own `needs`. The JS bundle (server, web
5# client, Electron main) comes from the `js-bundle` artifact that build_bundle
6# produced; this job only packages it, builds the native helpers, and, where
7# `cli_archive` is set, the self-contained CLI archive for its platform.
8
9on:
10 workflow_call:
11 secrets:
12 CSC_LINK:
13 required: false
14 CSC_KEY_PASSWORD:
15 required: false
16 APPLE_API_KEY:
17 required: false
18 APPLE_API_KEY_ID:
19 required: false
20 APPLE_API_ISSUER:
21 required: false
22 MACOS_PROVISIONING_PROFILE:
23 required: false
24 AZURE_TENANT_ID:
25 required: false
26 AZURE_CLIENT_ID:
27 required: false
28 AZURE_CLIENT_SECRET:
29 required: false
30 AZURE_TRUSTED_SIGNING_ENDPOINT:
31 required: false
32 AZURE_TRUSTED_SIGNING_ACCOUNT_NAME:
33 required: false
34 AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME:
35 required: false
36 AZURE_TRUSTED_SIGNING_PUBLISHER_NAME:
37 required: false
38 inputs:
39 label:
40 required: true
41 type: string
42 runner:
43 required: true
44 type: string
45 platform:
46 required: true
47 type: string
48 target:
49 required: true
50 type: string
51 arch:
52 required: true
53 type: string
54 rust_target:
55 required: true
56 type: string
57 resource_key:
58 required: true
59 type: string
60 # Whether the job also builds the self-contained CLI archive for its own
61 # platform/arch, on this runner, and smoke-tests it here. Every archive
62 # is built on hardware of its own architecture.
63 cli_archive:
64 required: false
65 default: false
66 type: boolean
67 # Whether the job opens the packaged app against a seeded database and
68 # opens a thread before uploading it. Linux AppImage or macOS DMG.
69 launch_check:
70 required: false
71 default: false
72 type: boolean
73 # Whether the JS bundle came from a pull request. This job holds the
74 # signing secrets, so packaging then skips every step that runs the bundle.
75 untrusted_bundle:
76 required: false
77 default: false
78 type: boolean
79 # A runner of the target's own platform and architecture, for a `runner`
80 # that cannot execute the target. The build job skips everything that
81 # runs the packaged binaries, and a second job runs it there.
82 verify_runner:
83 required: false
84 default: ""
85 type: string
86 # Whether this job saves the workspace pnpm store. Release's two Macs
87 # install the same store on the same runner type, so only one saves it.
88 save_pnpm_store:
89 required: false
90 default: true
91 type: boolean
92 version:
93 required: true
94 type: string
95 ref:
96 required: true
97 type: string
98 release_channel:
99 required: true
100 type: string
101 # Whether a `relay-client-tracing-config` artifact from the production
102 # relay state is expected. PR previews carry no tracing config.
103 relay_client_tracing:
104 required: false
105 default: true
106 type: boolean
107 clerk_publishable_key:
108 required: true
109 type: string
110 clerk_jwt_template:
111 required: true
112 type: string
113 clerk_cli_oauth_client_id:
114 required: true
115 type: string
116 relay_url:
117 required: true
118 type: string
119
120# electron-builder leaves the default arch (x64) out of the unpacked app's
121# directory name.
122env:
123 UNPACKED_DIR: ${{ inputs.platform }}-${{ inputs.arch != 'x64' && format('{0}-', inputs.arch) || '' }}unpacked
124
125permissions:
126 # Windows builds read this run's artifact list to wait for the Linux CLI archive.
127 actions: read
128 contents: read
129
130jobs:
131 build:
132 name: Build ${{ inputs.label }}
133 runs-on: ${{ inputs.runner }}
134 # Windows waits for the Linux CLI archive inside its own budget (see
135 # "Wait for Linux CLI archive"), so it gets that wait on top of the usual 30.
136 timeout-minutes: ${{ inputs.platform == 'win' && 70 || 30 }}
137 env:
138 T3CODE_CLERK_PUBLISHABLE_KEY: ${{ inputs.clerk_publishable_key }}
139 T3CODE_CLERK_JWT_TEMPLATE: ${{ inputs.clerk_jwt_template }}
140 T3CODE_CLERK_CLI_OAUTH_CLIENT_ID: ${{ inputs.clerk_cli_oauth_client_id }}
141 T3CODE_RELAY_URL: ${{ inputs.relay_url }}
142 steps:
143 # The launch check and the CLI archive smoke test both run the bundle.
144 - name: Reject running an untrusted bundle
145 if: inputs.untrusted_bundle && (inputs.launch_check || inputs.cli_archive)
146 shell: bash
147 run: |
148 echo "::error::untrusted_bundle cannot be combined with launch_check or cli_archive, which run the bundle."
149 exit 1
150
151 # This repository is public, so Git needs no credentials. checkout's
152 # credential cleanup runs submodule foreach even with submodules disabled,
153 # which fails on the orphaned gitlinks in our vendored .repos tree.
154 # checkout.workers=0 writes the files on every core. Alternating both ways
155 # in one job on the Windows runners, it wrote the files about 10s faster
156 # (about 40% on arm64).
157 - name: Checkout
158 shell: bash
159 env:
160 CHECKOUT_REF: ${{ inputs.ref }}
161 GIT_TERMINAL_PROMPT: "0"
162 run: |
163 set -euo pipefail
164 git init .
165 git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
166 git fetch --no-tags --depth=1 origin "$CHECKOUT_REF"
167 git sparse-checkout set --no-cone '/*' '!/.repos/'
168 git -c checkout.workers=0 checkout --detach FETCH_HEAD
169
170 # pnpm checks the lockfile and policy before reusing this result. A missing
171 # artifact leaves the cache empty, so installation runs the checks again.
172 - name: Download dependency verification
173 continue-on-error: true
174 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
175 with:
176 name: release-dependency-verification
177 path: ${{ runner.temp }}/pnpm-metadata
178
179 - name: Setup dependencies
180 uses: ./.github/actions/setup-ci-deps
181 with:
182 install-args: --filter=@t3tools/desktop... --filter=t3... --filter=@t3tools/scripts...
183 save-pnpm-store: ${{ inputs.save_pnpm_store }}
184 env:
185 pnpm_config_cache_dir: ${{ runner.temp }}/pnpm-metadata
186
187 # The CLI archive and the staged app install without a lockfile, so they
188 # ask the registry about every package and fetch platform packages the
189 # workspace store lacks. They share this registry metadata and store. A
190 # new week starts cold, which bounds how stale cached ranges can get.
191 - name: Resolve staged install cache
192 id: stage_pnpm
193 shell: bash
194 run: |
195 echo "dir=$RUNNER_TEMP/desktop-stage-pnpm" >> "$GITHUB_OUTPUT"
196 echo "prefix=desktop-stage-pnpm-v2-${{ inputs.platform }}-${{ inputs.arch }}-$(date -u +%G-%V)-" >> "$GITHUB_OUTPUT"
197
198 - name: Restore staged install cache
199 id: stage_pnpm_cache
200 uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
201 with:
202 path: ${{ steps.stage_pnpm.outputs.dir }}
203 key: ${{ steps.stage_pnpm.outputs.prefix }}${{ github.run_id }}-${{ github.run_attempt }}
204 restore-keys: ${{ steps.stage_pnpm.outputs.prefix }}
205
206 - name: Mark staged install cache
207 shell: bash
208 run: mkdir -p "${{ steps.stage_pnpm.outputs.dir }}" && touch "$RUNNER_TEMP/desktop-stage-pnpm.marker"
209
210 - name: Cache resource monitor
211 id: resource_monitor_cache
212 uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
213 with:
214 path: native/resource-monitor/target/${{ inputs.rust_target }}/release/t3-resource-monitor${{ inputs.platform == 'win' && '.exe' || '' }}
215 key: resource-monitor-${{ inputs.rust_target }}-${{ hashFiles('.cargo/config.toml', 'native/resource-monitor/Cargo.lock', 'native/resource-monitor/Cargo.toml', 'native/resource-monitor/build.rs', 'native/resource-monitor/src/**') }}
216
217 - name: Cache Linux capture helpers
218 if: inputs.platform == 'linux'
219 id: capture_helper_cache
220 uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
221 with:
222 path: |
223 native/kde-snap-shot/target/${{ inputs.rust_target }}/release/t3-kde-snap-shot
224 native/hyprland-snap-shot/target/${{ inputs.rust_target }}/release/t3-hyprland-snap-shot
225 key: linux-capture-helpers-${{ inputs.rust_target }}-${{ hashFiles('native/kde-snap-shot/Cargo.lock', 'native/kde-snap-shot/Cargo.toml', 'native/kde-snap-shot/src/**', 'native/hyprland-snap-shot/Cargo.lock', 'native/hyprland-snap-shot/Cargo.toml', 'native/hyprland-snap-shot/src/**', 'native/hyprland-snap-shot/protocols/**') }}
226
227 # Every Linux build makes electron-builder fetch the AppImage runtime, FPM
228 # for the deb, and the 7-Zip that unpacks FPM from GitHub releases. It
229 # checks an archive found here against the SHA-256 pinned in those toolset
230 # files and downloads again on a mismatch, so only raw archives are cached.
231 - name: Cache Linux packaging tool archives
232 if: inputs.platform == 'linux'
233 uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
234 with:
235 path: |
236 ~/.cache/electron-builder/appimage@*/appimage-tools-runtime-*.tar.gz
237 ~/.cache/electron-builder/fpm@*/fpm-*.7z
238 ~/.cache/electron-builder/7zip@*/7zip-linux-*.tar.gz
239 key: electron-builder-linux-tools-${{ inputs.arch }}-${{ hashFiles('node_modules/.pnpm/app-builder-lib@*/node_modules/app-builder-lib/out/toolsets/linux.js', 'node_modules/.pnpm/app-builder-lib@*/node_modules/app-builder-lib/out/toolsets/7zip.js') }}
240
241 - name: Ensure Rosetta for macOS x64 bytecode generation
242 if: inputs.platform == 'mac' && inputs.arch == 'x64'
243 shell: bash
244 run: |
245 if [[ "$(uname -m)" == "arm64" ]] && ! /usr/bin/arch -x86_64 /usr/bin/true; then
246 sudo /usr/sbin/softwareupdate --install-rosetta --agree-to-license
247 fi
248
249 - name: Setup Rust
250 if: steps.resource_monitor_cache.outputs.cache-hit != 'true' || (inputs.platform == 'linux' && steps.capture_helper_cache.outputs.cache-hit != 'true')
251 uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master
252 with:
253 toolchain: stable
254 targets: ${{ inputs.rust_target }}
255
256 - name: Download relay client tracing config
257 if: inputs.relay_client_tracing
258 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
259 with:
260 name: relay-client-tracing-config
261 path: ${{ runner.temp }}/relay-client-tracing
262
263 - name: Load relay client tracing config
264 if: inputs.relay_client_tracing
265 shell: bash
266 run: |
267 config_path="$RUNNER_TEMP/relay-client-tracing/relay-client-tracing.env"
268 tracing_token="$(sed -n 's/^T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN=//p' "$config_path")"
269 echo "::add-mask::$tracing_token"
270 cat "$config_path" >> "$GITHUB_ENV"
271
272 - name: Align package versions to release version
273 run: node scripts/update-release-package-versions.ts "${{ inputs.version }}"
274
275 # The artifact root is `apps/` (upload-artifact keeps the least common
276 # ancestor of its paths), so extracting into `apps` restores
277 # apps/server/dist and apps/desktop/dist-electron at their build paths.
278 - name: Download JS bundle
279 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
280 with:
281 name: js-bundle
282 path: apps
283
284 - name: Restore web asset manifest
285 shell: bash
286 run: |
287 client=apps/server/dist/client
288 if [[ -f "$client/vite-manifest.release.json" ]]; then
289 mkdir -p "$client/.vite"
290 mv "$client/vite-manifest.release.json" "$client/.vite/manifest.json"
291 fi
292
293 - name: Install cargo-xwin
294 if: inputs.platform == 'win' && steps.resource_monitor_cache.outputs.cache-hit != 'true'
295 uses: taiki-e/install-action@cfdb7ed4ccc7c7dce37759eae89dc5674b469b39 # v2.90.3
296 with:
297 tool: cargo-xwin@0.23.1
298
299 # Built here rather than inside the desktop build so the CLI archive,
300 # which bundles the same binary, can be built and uploaded first.
301 - name: Build resource monitor
302 if: steps.resource_monitor_cache.outputs.cache-hit != 'true'
303 shell: bash
304 run: cargo ${{ inputs.platform == 'win' && 'xwin build' || 'build' }} --locked --release --manifest-path native/resource-monitor/Cargo.toml --target "${{ inputs.rust_target }}"
305
306 # Off Windows, scripts/lib/windows-jsign.ts signs through jsign instead of
307 # the TrustedSigning PowerShell module.
308 - name: Install jsign
309 if: inputs.platform == 'win'
310 shell: bash
311 run: |
312 set -euo pipefail
313 dir="$RUNNER_TEMP/jsign"
314 mkdir -p "$dir"
315 curl -fsSL --retry 3 -o "$dir/jsign.jar" https://github.com/ebourg/jsign/releases/download/7.6/jsign-7.6.jar
316 echo "6cf58aa080e7ff82656f320cff8d4a3bff30408df8766806dcba3740dd839fa5 $dir/jsign.jar" | sha256sum -c -
317 printf '#!/bin/sh\nexec java -jar "%s" "$@"\n' "$dir/jsign.jar" > "$dir/jsign"
318 chmod +x "$dir/jsign"
319 echo "T3CODE_JSIGN=$dir/jsign" >> "$GITHUB_ENV"
320
321 # The desktop build applies the same branding to apps/server/dist/client
322 # (resolveDesktopWebAssetBrand in scripts/build-desktop-artifact.ts); the
323 # CLI archive below ships that client and is now built first.
324 - name: Apply web client branding
325 if: inputs.cli_archive
326 shell: bash
327 run: |
328 brand=production
329 if [[ "${{ inputs.version }}" =~ -nightly\.[0-9]{8}\.[0-9]+$ ]]; then brand=nightly; fi
330 node scripts/apply-web-brand-assets.ts "$brand" apps/server/dist/client
331
332 - name: Resolve target Node.js for the CLI executable
333 id: target_node
334 if: inputs.cli_archive && inputs.platform == 'win'
335 shell: bash
336 run: echo "version=$(node -p 'require("./package.json").engines.node')" >> "$GITHUB_OUTPUT"
337
338 # The download only changes with engines.node, so a cached copy keeps
339 # releases off nodejs.org, which stalls on the runners some days.
340 - name: Restore target Node.js for the CLI executable
341 id: target_node_cache
342 if: inputs.cli_archive && inputs.platform == 'win'
343 uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
344 with:
345 path: ${{ runner.temp }}/node-download
346 key: node-download-v${{ steps.target_node.outputs.version }}-win-${{ inputs.arch }}
347
348 # tsdown downloads the target Node with one fetch and no retry, and
349 # nodejs.org drops that download often enough to fail releases. Seed
350 # tsdown's cache with a retried, checksum-verified copy instead. A transfer
351 # under 100 KB/s for 30s counts as failed, so a stall retries.
352 - name: Download target Node.js for the CLI executable
353 if: inputs.cli_archive && inputs.platform == 'win' && steps.target_node_cache.outputs.cache-hit != 'true'
354 shell: bash
355 env:
356 VERSION: ${{ steps.target_node.outputs.version }}
357 run: |
358 set -euo pipefail
359 name="node-v$VERSION-win-${{ inputs.arch }}"
360 dir="$RUNNER_TEMP/node-download"
361 mkdir -p "$dir"
362 fetch=(curl -fsSL --retry 5 --retry-all-errors --connect-timeout 10 --speed-limit 102400 --speed-time 30)
363 "${fetch[@]}" -o "$dir/$name.zip" "https://nodejs.org/dist/v$VERSION/$name.zip"
364 "${fetch[@]}" -o "$dir/SHASUMS256.txt" "https://nodejs.org/dist/v$VERSION/SHASUMS256.txt"
365 (cd "$dir" && grep " $name.zip\$" SHASUMS256.txt | sha256sum -c -)
366
367 # Saved right away so a later failure in this job still keeps the download.
368 - name: Save target Node.js for the CLI executable
369 if: inputs.cli_archive && inputs.platform == 'win' && steps.target_node_cache.outputs.cache-hit != 'true'
370 uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
371 with:
372 path: ${{ runner.temp }}/node-download
373 key: ${{ steps.target_node_cache.outputs.cache-primary-key }}
374
375 - name: Install target Node.js for the CLI executable
376 if: inputs.cli_archive && inputs.platform == 'win'
377 shell: bash
378 env:
379 VERSION: ${{ steps.target_node.outputs.version }}
380 run: |
381 set -euo pipefail
382 name="node-v$VERSION-win-${{ inputs.arch }}"
383 dir="$RUNNER_TEMP/node-download"
384 dest="${XDG_CACHE_HOME:-$HOME/.cache}/tsdown/node/v$VERSION/win-${{ inputs.arch }}"
385 mkdir -p "$dest"
386 (cd "$dir" && grep " $name.zip\$" SHASUMS256.txt | sha256sum -c -)
387 unzip -p "$dir/$name.zip" "$name/node.exe" > "$dest/node.exe"
388
389 # Setup Vite+ selects the exact engines.node version from package.json.
390 # Native builds embed that executable; cross-target builds download the
391 # same version for their target.
392 - name: Build CLI single-executable
393 if: inputs.cli_archive
394 shell: bash
395 env:
396 # The executable bundles the server again, so it needs the same stamp
397 # as release.yml's JS bundle.
398 T3CODE_TELEMETRY_CHANNEL: ${{ github.repository == 'pingdotgg/t3code' && inputs.release_channel || 'dev' }}
399 run: node apps/server/scripts/cli.ts build-exe --verbose ${{ inputs.platform == 'win' && format('--target win-{0}', inputs.arch) || '' }}
400
401 - name: Import macOS signing certificate for the CLI archive
402 if: inputs.cli_archive && inputs.platform == 'mac'
403 shell: bash
404 env:
405 CSC_LINK: ${{ secrets.CSC_LINK }}
406 CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
407 run: |
408 set -euo pipefail
409 if [[ -z "$CSC_LINK" || -z "$CSC_KEY_PASSWORD" ]]; then
410 echo "macOS CLI signing disabled (missing CSC_LINK); the archive is signed ad hoc."
411 exit 0
412 fi
413 keychain="$RUNNER_TEMP/t3-cli-signing.keychain-db"
414 keychain_password="$(openssl rand -hex 16)"
415 cert_path="$RUNNER_TEMP/t3-cli-signing.p12"
416 printf '%s' "$CSC_LINK" | base64 --decode > "$cert_path"
417 security create-keychain -p "$keychain_password" "$keychain"
418 security set-keychain-settings -lut 21600 "$keychain"
419 security unlock-keychain -p "$keychain_password" "$keychain"
420 security import "$cert_path" -k "$keychain" -P "$CSC_KEY_PASSWORD" -T /usr/bin/codesign
421 security set-key-partition-list -S apple-tool:,apple: -s -k "$keychain_password" "$keychain" >/dev/null
422 security list-keychains -d user -s "$keychain" $(security list-keychains -d user | tr -d '"')
423 identity="$(security find-identity -v -p codesigning "$keychain" | sed -n 's/.*"\(Developer ID Application: [^"]*\)".*/\1/p' | head -n 1)"
424 if [[ -z "$identity" ]]; then
425 echo "No Developer ID Application identity found in CSC_LINK." >&2
426 exit 1
427 fi
428 echo "::add-mask::$keychain_password"
429 echo "T3CODE_CLI_MAC_SIGN_IDENTITY=$identity" >> "$GITHUB_ENV"
430 echo "macOS CLI signing enabled."
431
432 - name: Stage resource monitor for the CLI archive
433 if: inputs.cli_archive
434 shell: bash
435 run: |
436 set -euo pipefail
437 binary_name="t3-resource-monitor"
438 if [[ "${{ inputs.platform }}" == "win" ]]; then
439 binary_name="${binary_name}.exe"
440 fi
441 target_dir="$RUNNER_TEMP/cli-resource-monitor/${{ inputs.resource_key }}"
442 mkdir -p "$target_dir"
443 cp "native/resource-monitor/target/${{ inputs.rust_target }}/release/${binary_name}" "$target_dir/$binary_name"
444
445 - uses: ./.github/actions/setup-apt-mirrors
446 if: inputs.platform == 'linux'
447
448 # The Linux archive ships libatomic.so.1 and points t3's RUNPATH at it.
449 - name: Install patchelf
450 if: inputs.cli_archive && inputs.platform == 'linux'
451 shell: bash
452 run: command -v patchelf || { sudo apt-get update && sudo apt-get install -y patchelf; }
453
454 - name: Build CLI archive
455 id: build_cli
456 if: inputs.cli_archive
457 shell: bash
458 env:
459 pnpm_config_cache_dir: ${{ steps.stage_pnpm.outputs.dir }}/cache
460 pnpm_config_store_dir: ${{ steps.stage_pnpm.outputs.dir }}/store
461 pnpm_config_prefer_offline: "true"
462 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
463 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
464 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
465 AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
466 AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
467 AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
468 AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
469 AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
470 AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }}
471 run: |
472 set -euo pipefail
473 extra_args=()
474 if [[ "${{ inputs.platform }}" == "mac" ]]; then
475 if [[ -n "${APPLE_API_KEY:-}" ]]; then
476 key_dir="$(mktemp -d "$RUNNER_TEMP/t3-cli-notary.XXXXXXXX")"
477 trap 'rm -rf "$key_dir"' EXIT
478 key_path="$key_dir/AuthKey.p8"
479 (umask 077 && printf '%s' "$APPLE_API_KEY" > "$key_path")
480 export APPLE_API_KEY="$key_path"
481 fi
482 # Older release refs lack deferred notarization and still wait here.
483 cli_help="$(node scripts/build-cli-archive.ts --help)"
484 if [[ "$cli_help" == *--notary-submission-file* ]]; then
485 extra_args=(--notary-submission-file "$RUNNER_TEMP/t3-cli-notary-submission")
486 echo "deferred_notarization=true" >> "$GITHUB_OUTPUT"
487 fi
488 fi
489 node scripts/build-cli-archive.ts \
490 --platform "${{ inputs.platform }}" \
491 --arch "${{ inputs.arch }}" \
492 --version "${{ inputs.version }}" \
493 --resource-monitor-dir "$RUNNER_TEMP/cli-resource-monitor" \
494 --output-dir release-cli \
495 ${extra_args[@]+"${extra_args[@]}"}
496
497 - name: Smoke-test CLI archive
498 if: inputs.cli_archive && inputs.verify_runner == ''
499 shell: bash
500 run: node scripts/smoke-cli-archive.ts --archive release-cli/* --expect-version "${{ inputs.version }}"
501
502 # macOS uploads its archive after "Await CLI notarization" instead.
503 - name: Upload CLI archive
504 if: inputs.cli_archive && inputs.platform != 'mac'
505 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
506 with:
507 name: cli-${{ inputs.platform }}-${{ inputs.arch }}
508 path: release-cli/*
509 if-no-files-found: error
510 # The archive is already gzip or zip; deflating it again saves under 2%.
511 compression-level: 0
512
513 - name: Install Linux desktop build libraries
514 if: inputs.platform == 'linux'
515 shell: bash
516 run: |
517 sudo apt-get update
518 sudo apt-get install -y libsecret-1-dev pkg-config libgtk-3-0t64 libnss3 libasound2t64 libgbm1
519 if ! command -v magick >/dev/null 2>&1 && ! command -v convert >/dev/null 2>&1; then
520 sudo apt-get install -y imagemagick
521 fi
522
523 if command -v magick >/dev/null 2>&1; then
524 magick -version
525 else
526 convert -version
527 fi
528
529 # The WSL backend runs the Linux CLI archive inside the distro, so the
530 # Windows desktop embeds the same-arch archive the release attaches.
531 # This job starts alongside that Linux job instead of after it, and the
532 # Linux job uploads the archive partway through, so the wait is placed
533 # after all other setup. It stops early if the Linux job ended without
534 # uploading the archive.
535 - name: Wait for Linux CLI archive
536 if: inputs.platform == 'win'
537 shell: pwsh
538 timeout-minutes: 40
539 env:
540 GITHUB_TOKEN: ${{ github.token }}
541 ARTIFACT: cli-linux-${{ inputs.arch }}
542 LINUX_JOB: Build Linux ${{ inputs.arch }}
543 run: |
544 $headers = @{ Authorization = "Bearer $env:GITHUB_TOKEN"; Accept = "application/vnd.github+json" }
545 $run = "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID"
546 function Test-Archive {
547 (Invoke-RestMethod -Headers $headers -Uri "$run/artifacts?name=$env:ARTIFACT").total_count -gt 0
548 }
549 $missingSince = $null
550 while ($true) {
551 try {
552 if (Test-Archive) {
553 Write-Host "$env:ARTIFACT is ready."
554 exit 0
555 }
556 $jobs = Invoke-RestMethod -Headers $headers -Uri "$run/attempts/$env:GITHUB_RUN_ATTEMPT/jobs?per_page=100"
557 $linux = $jobs.jobs | Where-Object { $_.name.EndsWith($env:LINUX_JOB) } | Select-Object -First 1
558 if (-not $linux) {
559 # Both jobs start together, so a Linux job still missing after a
560 # few minutes means a renamed or skipped job, not a slow one.
561 if (-not $missingSince) {
562 $missingSince = Get-Date
563 } elseif (((Get-Date) - $missingSince).TotalMinutes -ge 5) {
564 Write-Host "::error::No job named '$env:LINUX_JOB' in this run, so $env:ARTIFACT will not arrive."
565 exit 1
566 }
567 } elseif ($linux.conclusion) {
568 # The upload may have landed between the two requests above.
569 if (Test-Archive) {
570 Write-Host "$env:ARTIFACT is ready."
571 exit 0
572 }
573 Write-Host "::error::$env:LINUX_JOB ended ($($linux.conclusion)) without uploading $env:ARTIFACT."
574 exit 1
575 }
576 } catch {
577 Write-Warning "Could not read this run's artifacts or jobs: $($_.Exception.Message)"
578 }
579 Write-Host "Waiting for $env:ARTIFACT..."
580 Start-Sleep -Seconds 10
581 }
582
583 # The token makes the action look the artifact up through the REST API
584 # the wait above polls. Without it the runner's artifact service is used,
585 # which can lag that API by seconds and report the artifact missing.
586 - name: Download Linux CLI archive for WSL
587 if: inputs.platform == 'win'
588 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
589 with:
590 name: cli-linux-${{ inputs.arch }}
591 path: wsl-runtime
592 github-token: ${{ github.token }}
593
594 - name: Build desktop artifact
595 shell: bash
596 env:
597 # pnpm only goes to the registry for packages or versions the cache lacks.
598 pnpm_config_cache_dir: ${{ steps.stage_pnpm.outputs.dir }}/cache
599 pnpm_config_store_dir: ${{ steps.stage_pnpm.outputs.dir }}/store
600 pnpm_config_prefer_offline: "true"
601 T3CODE_DESKTOP_REUSE_RESOURCE_MONITOR: true
602 T3CODE_DESKTOP_REUSE_LINUX_CAPTURE_HELPERS: ${{ steps.capture_helper_cache.outputs.cache-hit == 'true' }}
603 T3CODE_DESKTOP_UNTRUSTED_BUNDLE: ${{ inputs.untrusted_bundle }}
604 CSC_LINK: ${{ secrets.CSC_LINK }}
605 CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
606 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
607 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
608 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
609 APPLE_TEAM_ID: ${{ vars.APPLE_TEAM_ID }}
610 MACOS_PROVISIONING_PROFILE: ${{ secrets.MACOS_PROVISIONING_PROFILE }}
611 T3CODE_CLERK_PASSKEY_RP_DOMAINS: ${{ vars.CLERK_PASSKEY_RP_DOMAINS }}
612 AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
613 AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
614 AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
615 AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
616 AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
617 AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }}
618 AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }}
619 run: |
620 args=(
621 --platform "${{ inputs.platform }}"
622 --target "${{ inputs.target }}"
623 --arch "${{ inputs.arch }}"
624 --build-version "${{ inputs.version }}"
625 --skip-build
626 --verbose
627 )
628 if [[ -n "${{ inputs.verify_runner }}" ]]; then
629 args+=(--keep-stage)
630 fi
631
632 has_all() {
633 for value in "$@"; do
634 if [[ -z "$value" ]]; then
635 return 1
636 fi
637 done
638 return 0
639 }
640
641 if [[ "${{ inputs.platform }}" == "mac" ]]; then
642 if has_all "$CSC_LINK" "$CSC_KEY_PASSWORD" "$APPLE_API_KEY" "$APPLE_API_KEY_ID" "$APPLE_API_ISSUER"; then
643 if ! has_all "$APPLE_TEAM_ID" "$MACOS_PROVISIONING_PROFILE"; then
644 echo "macOS signing is configured, but APPLE_TEAM_ID or MACOS_PROVISIONING_PROFILE is missing." >&2
645 exit 1
646 fi
647
648 key_path="$RUNNER_TEMP/AuthKey_${APPLE_API_KEY_ID}.p8"
649 printf '%s' "$APPLE_API_KEY" > "$key_path"
650 export APPLE_API_KEY="$key_path"
651
652 profile_path="$RUNNER_TEMP/t3code.provisionprofile"
653 printf '%s' "$MACOS_PROVISIONING_PROFILE" | base64 -D > "$profile_path"
654 security cms -D -i "$profile_path" >/dev/null
655 export T3CODE_APPLE_TEAM_ID="$APPLE_TEAM_ID"
656 export T3CODE_MACOS_PROVISIONING_PROFILE="$profile_path"
657
658 echo "macOS signing enabled."
659 args+=(--signed)
660 else
661 echo "macOS signing disabled (missing one or more Apple signing secrets)."
662 fi
663 elif [[ "${{ inputs.platform }}" == "win" ]]; then
664 # Embed the Linux CLI archive built by the same-arch Linux job as
665 # the WSL runtime. Required for a working WSL backend on Windows.
666 args+=(--wsl-runtime "$GITHUB_WORKSPACE"/wsl-runtime/t3-*-linux-${{ inputs.arch }}.tar.gz)
667 if has_all \
668 "$AZURE_TENANT_ID" \
669 "$AZURE_CLIENT_ID" \
670 "$AZURE_CLIENT_SECRET" \
671 "$AZURE_TRUSTED_SIGNING_ENDPOINT" \
672 "$AZURE_TRUSTED_SIGNING_ACCOUNT_NAME" \
673 "$AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME" \
674 "$AZURE_TRUSTED_SIGNING_PUBLISHER_NAME"; then
675 echo "Windows signing enabled (Azure Trusted Signing)."
676 args+=(--signed)
677 else
678 echo "Windows signing disabled (missing one or more Azure Trusted Signing secrets)."
679 fi
680 else
681 echo "Signing disabled for ${{ inputs.platform }}."
682 fi
683
684 vp run dist:desktop:artifact "${args[@]}"
685
686 # The CLI was submitted without waiting so Apple reviews it while the
687 # desktop builds. Notarization does not change the archive bytes, but
688 # nothing uploads them, so nothing publishes them, until Apple accepts.
689 # With signing configured, a missing submission id fails this step.
690 - name: Await CLI notarization
691 if: inputs.cli_archive && inputs.platform == 'mac' && steps.build_cli.outputs.deferred_notarization == 'true'
692 shell: bash
693 env:
694 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
695 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
696 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
697 run: |
698 set -euo pipefail
699 if [[ -n "${APPLE_API_KEY:-}" ]]; then
700 key_dir="$(mktemp -d "$RUNNER_TEMP/t3-cli-notary.XXXXXXXX")"
701 trap 'rm -rf "$key_dir"' EXIT
702 key_path="$key_dir/AuthKey.p8"
703 (umask 077 && printf '%s' "$APPLE_API_KEY" > "$key_path")
704 export APPLE_API_KEY="$key_path"
705 fi
706 node scripts/build-cli-archive.ts await-notarization \
707 --submission-file "$RUNNER_TEMP/t3-cli-notary-submission"
708
709 - name: Upload notarized CLI archive
710 if: inputs.cli_archive && inputs.platform == 'mac'
711 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
712 with:
713 name: cli-${{ inputs.platform }}-${{ inputs.arch }}
714 path: release-cli/*
715 if-no-files-found: error
716 # The archive is already gzip or zip; deflating it again saves under 2%.
717 compression-level: 0
718
719 # Warm installs only touch the store index, so new content means a fetch.
720 - name: Check staged install cache for new content
721 id: stage_pnpm_changed
722 shell: bash
723 run: |
724 dir="${{ steps.stage_pnpm.outputs.dir }}"
725 new=$(find "$dir/cache/v12" "$dir/store/v11/files" -type f -newer "$RUNNER_TEMP/desktop-stage-pnpm.marker" 2>/dev/null | wc -l | tr -d ' ')
726 echo "Staged installs added $new cached files."
727 echo "changed=$([[ "$new" -gt 0 ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"
728
729 - name: Save staged install cache
730 if: steps.stage_pnpm_changed.outputs.changed == 'true'
731 uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
732 with:
733 path: ${{ steps.stage_pnpm.outputs.dir }}
734 key: ${{ steps.stage_pnpm_cache.outputs.cache-primary-key }}
735
736 # A build can package fine and still not open (a missing module in the
737 # backend or the bundle). This launches the app from the shipped
738 # AppImage or DMG.
739 - name: Launch check
740 if: inputs.launch_check
741 shell: bash
742 run: |
743 set -euo pipefail
744 check=(node scripts/smoke-desktop-app.ts --artifacts-dir "$RUNNER_TEMP/desktop-launch-check")
745 if [[ "${{ inputs.platform }}" == "mac" ]]; then
746 mount="$RUNNER_TEMP/desktop-launch-dmg"
747 hdiutil attach -nobrowse -readonly -mountpoint "$mount" "$(ls "$GITHUB_WORKSPACE"/release/*.dmg)"
748 trap 'hdiutil detach "$mount" -force >/dev/null || true' EXIT
749 app=$(ls -d "$mount"/*.app)
750 executable=$(/usr/libexec/PlistBuddy -c "Print :CFBundleExecutable" "$app/Contents/Info.plist")
751 "${check[@]}" --executable "$app/Contents/MacOS/$executable"
752 else
753 sudo apt-get install -y xvfb
754 appimage=$(ls "$GITHUB_WORKSPACE"/release/*.AppImage)
755 chmod +x "$appimage"
756 (cd "$RUNNER_TEMP" && "$appimage" --appimage-extract >/dev/null)
757 xvfb-run -a "${check[@]}" --executable "$RUNNER_TEMP/squashfs-root/t3code"
758 fi
759
760 - name: Upload launch check output
761 if: failure() && inputs.launch_check
762 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
763 with:
764 name: desktop-launch-check-${{ inputs.platform }}-${{ inputs.arch }}
765 path: ${{ runner.temp }}/desktop-launch-check
766 if-no-files-found: ignore
767
768 # The verify job runs what this host could not: the packaged natives and
769 # the CLI. Its scripts are bundled so that job needs no install.
770 - name: Stage verification inputs
771 if: inputs.verify_runner != ''
772 shell: bash
773 run: |
774 set -euo pipefail
775 mkdir -p verify
776 unpacked=$(ls -d "${TMPDIR:-/tmp}"/t3code-desktop-${{ inputs.platform }}-stage-*/app/dist/"$UNPACKED_DIR")
777 tar -C "$(dirname "$unpacked")" -cf verify/unpacked.tar "$(basename "$unpacked")"
778 esbuild=scripts/node_modules/.bin/esbuild
779 banner="import{createRequire as __cr}from'node:module';const require=__cr(import.meta.url);"
780 # build-desktop-artifact.ts's own import.meta.main guard must not run
781 # its CLI inside the verify bundle.
782 "$esbuild" scripts/verify-windows-desktop-artifact.ts --bundle --platform=node --format=esm \
783 --target=node24 --define:import.meta.main=false --banner:js="$banner" \
784 --outfile=verify/verify-windows-desktop-artifact.mjs
785 "$esbuild" scripts/smoke-cli-archive.ts --bundle --platform=node --format=esm \
786 --target=node24 --banner:js="$banner" --outfile=verify/smoke-cli-archive.mjs
787
788 - name: Upload verification inputs
789 if: inputs.verify_runner != ''
790 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
791 with:
792 name: verify-${{ inputs.platform }}-${{ inputs.arch }}
793 path: verify/*
794 if-no-files-found: error
795 retention-days: 1
796 compression-level: 1
797
798 - name: Collect release assets
799 shell: bash
800 run: |
801 set -euo pipefail
802 mkdir -p release-publish
803
804 shopt -s nullglob
805 patterns=(
806 "release/*.dmg"
807 "release/*.zip"
808 "release/*.AppImage"
809 "release/*.deb"
810 "release/*.exe"
811 )
812 # Preview builds have no publish config, so electron-builder writes
813 # no feed manifest for them, but it still emits blockmaps beside the
814 # installers. Neither belongs on a release no updater may follow.
815 if [[ "${{ inputs.release_channel }}" != "preview" ]]; then
816 patterns+=("release/*.blockmap" "release/*.yml")
817 fi
818 for pattern in "${patterns[@]}"; do
819 for file in $pattern; do
820 cp "$file" release-publish/
821 done
822 done
823
824 if [[ "${{ inputs.platform }}" == "mac" && "${{ inputs.arch }}" != "arm64" ]]; then
825 shopt -s nullglob
826 for manifest in release-publish/*-mac.yml; do
827 mv "$manifest" "${manifest%.yml}-${{ inputs.arch }}.yml"
828 done
829 fi
830
831 # Windows updater metadata is channel-specific (for example
832 # "latest.yml" or "nightly.yml") and carries no arch, so the x64 and
833 # arm64 jobs would upload the same name. Suffix each per-arch copy;
834 # the release job merges them back into one manifest per channel.
835 # builder-debug.yml is electron-builder's config dump, not a feed.
836 if [[ "${{ inputs.platform }}" == "win" ]]; then
837 for manifest in release-publish/*.yml; do
838 [[ "$manifest" == */builder-debug.yml ]] && continue
839 mv "$manifest" "${manifest%.yml}-win-${{ inputs.arch }}.yml"
840 done
841 fi
842
843 - name: Collect resource monitor
844 shell: bash
845 run: |
846 set -euo pipefail
847 binary_name="t3-resource-monitor"
848 if [[ "${{ inputs.platform }}" == "win" ]]; then
849 binary_name="${binary_name}.exe"
850 fi
851 source_path="native/resource-monitor/target/${{ inputs.rust_target }}/release/${binary_name}"
852 target_dir="resource-monitor-publish/${{ inputs.resource_key }}"
853 mkdir -p "$target_dir"
854 cp "$source_path" "$target_dir/$binary_name"
855
856 - name: Upload build artifacts
857 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
858 with:
859 name: desktop-${{ inputs.platform }}-${{ inputs.arch }}
860 path: release-publish/*
861 if-no-files-found: error
862 # Installers, zips and blockmaps are already compressed; deflating them again saves under 0.3%.
863 compression-level: 0
864
865 - name: Upload resource monitor
866 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
867 with:
868 name: resource-monitor-${{ inputs.resource_key }}
869 path: resource-monitor-publish/${{ inputs.resource_key }}/*
870 if-no-files-found: error
871
872 verify:
873 name: Verify
874 needs: [build]
875 if: inputs.verify_runner != ''
876 runs-on: ${{ inputs.verify_runner }}
877 timeout-minutes: 15
878 steps:
879 - name: Download verification inputs
880 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
881 with:
882 name: verify-${{ inputs.platform }}-${{ inputs.arch }}
883 path: verify
884
885 - name: Download CLI archive
886 if: inputs.cli_archive
887 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
888 with:
889 name: cli-${{ inputs.platform }}-${{ inputs.arch }}
890 path: release-cli
891
892 - name: Verify packaged natives
893 shell: bash
894 run: |
895 set -euo pipefail
896 tar -C verify -xf verify/unpacked.tar
897 node verify/verify-windows-desktop-artifact.mjs \
898 --app-dir "$(cygpath -w "$PWD/verify/$UNPACKED_DIR")" \
899 --arch "${{ inputs.arch }}" --build-version "${{ inputs.version }}" --verbose
900
901 - name: Smoke-test CLI archive
902 if: inputs.cli_archive
903 shell: bash
904 run: node verify/smoke-cli-archive.mjs --archive release-cli/* --expect-version "${{ inputs.version }}"
905
906 # cargo-xwin links this binary on Linux, and nothing else runs it before users do.
907 # Node rather than pwsh: PowerShell on Windows ARM crashes intermittently
908 # (https://github.com/dotnet/runtime/issues/131636), which is why this
909 # target stopped building on Windows.
910 - name: Smoke-test resource monitor
911 shell: bash
912 env:
913 MONITOR: verify/${{ env.UNPACKED_DIR }}/resources/resource-monitor/t3-resource-monitor.exe
914 EXPECTED_ARCH: ${{ inputs.arch == 'arm64' && 'aarch64' || 'x86_64' }}
915 run: |
916 node --input-type=module <<'EOF'
917 import { spawn } from "node:child_process";
918 const monitor = spawn(process.env.MONITOR, { stdio: ["pipe", "pipe", "inherit"] });
919 monitor.stdout.setEncoding("utf8");
920 let output = "";
921 const exited = new Promise((resolve) => monitor.on("close", resolve));
922 const hello = await new Promise((resolve, reject) => {
923 monitor.on("error", reject);
924 monitor.on("close", () => reject(new Error(`Resource monitor exited before hello: ${output}`)));
925 monitor.stdout.on("data", (chunk) => {
926 output += chunk;
927 const end = output.indexOf("\n");
928 if (end !== -1) resolve(JSON.parse(output.slice(0, end)));
929 });
930 });
931 if (hello.type !== "hello" || hello.arch !== process.env.EXPECTED_ARCH) {
932 throw new Error(`Unexpected hello: ${JSON.stringify(hello)}`);
933 }
934 const send = (message) => monitor.stdin.write(`${JSON.stringify({ version: hello.version, ...message })}\n`);
935 send({ type: "configure", rootPid: process.pid, sampleIntervalMs: 1000 });
936 send({ type: "sampleNow", requestId: "verify" });
937 monitor.stdin.end();
938 const exitCode = await exited;
939 const sample = output
940 .split("\n")
941 .filter((line) => line.trim())
942 .map((line) => JSON.parse(line))
943 .find((message) => message.requestId === "verify");
944 if (exitCode !== 0 || sample?.type !== "snapshot" || !sample.processes.some((p) => p.pid === process.pid)) {
945 throw new Error(`Resource monitor exited ${exitCode} with: ${output}`);
946 }
947 console.log(`Resource monitor sampled ${sample.scannedProcessCount} processes.`);
948 EOF