The best way to control Claude Code, Codex and more from any computer or phone

main
yml 935 lines 42.6 KB
Raw
1 name: 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
9 on:
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.
122 env:
123 UNPACKED_DIR: ${{ inputs.platform }}-${{ inputs.arch != 'x64' && format('{0}-', inputs.arch) || '' }}unpacked
124
125 permissions:
126 # Windows builds read this run's artifact list to wait for the Linux CLI archive.
127 actions: read
128 contents: read
129
130 jobs:
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/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: Install cargo-xwin
285 if: inputs.platform == 'win' && steps.resource_monitor_cache.outputs.cache-hit != 'true'
286 uses: taiki-e/install-action@cfdb7ed4ccc7c7dce37759eae89dc5674b469b39 # v2.90.3
287 with:
288 tool: cargo-xwin@0.23.1
289
290 # Built here rather than inside the desktop build so the CLI archive,
291 # which bundles the same binary, can be built and uploaded first.
292 - name: Build resource monitor
293 if: steps.resource_monitor_cache.outputs.cache-hit != 'true'
294 shell: bash
295 run: cargo ${{ inputs.platform == 'win' && 'xwin build' || 'build' }} --locked --release --manifest-path native/resource-monitor/Cargo.toml --target "${{ inputs.rust_target }}"
296
297 # Off Windows, scripts/lib/windows-jsign.ts signs through jsign instead of
298 # the TrustedSigning PowerShell module.
299 - name: Install jsign
300 if: inputs.platform == 'win'
301 shell: bash
302 run: |
303 set -euo pipefail
304 dir="$RUNNER_TEMP/jsign"
305 mkdir -p "$dir"
306 curl -fsSL --retry 3 -o "$dir/jsign.jar" https://github.com/ebourg/jsign/releases/download/7.6/jsign-7.6.jar
307 echo "6cf58aa080e7ff82656f320cff8d4a3bff30408df8766806dcba3740dd839fa5 $dir/jsign.jar" | sha256sum -c -
308 printf '#!/bin/sh\nexec java -jar "%s" "$@"\n' "$dir/jsign.jar" > "$dir/jsign"
309 chmod +x "$dir/jsign"
310 echo "T3CODE_JSIGN=$dir/jsign" >> "$GITHUB_ENV"
311
312 # The desktop build applies the same branding to apps/server/dist/client
313 # (resolveDesktopWebAssetBrand in scripts/build-desktop-artifact.ts); the
314 # CLI archive below ships that client and is now built first.
315 - name: Apply web client branding
316 if: inputs.cli_archive
317 shell: bash
318 run: |
319 brand=production
320 if [[ "${{ inputs.version }}" =~ -nightly\.[0-9]{8}\.[0-9]+$ ]]; then brand=nightly; fi
321 node scripts/apply-web-brand-assets.ts "$brand" apps/server/dist/client
322
323 - name: Resolve target Node.js for the CLI executable
324 id: target_node
325 if: inputs.cli_archive && inputs.platform == 'win'
326 shell: bash
327 run: echo "version=$(node -p 'require("./package.json").engines.node')" >> "$GITHUB_OUTPUT"
328
329 # The download only changes with engines.node, so a cached copy keeps
330 # releases off nodejs.org, which stalls on the runners some days.
331 - name: Restore target Node.js for the CLI executable
332 id: target_node_cache
333 if: inputs.cli_archive && inputs.platform == 'win'
334 uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
335 with:
336 path: ${{ runner.temp }}/node-download
337 key: node-download-v${{ steps.target_node.outputs.version }}-win-${{ inputs.arch }}
338
339 # tsdown downloads the target Node with one fetch and no retry, and
340 # nodejs.org drops that download often enough to fail releases. Seed
341 # tsdown's cache with a retried, checksum-verified copy instead. A transfer
342 # under 100 KB/s for 30s counts as failed, so a stall retries.
343 - name: Download target Node.js for the CLI executable
344 if: inputs.cli_archive && inputs.platform == 'win' && steps.target_node_cache.outputs.cache-hit != 'true'
345 shell: bash
346 env:
347 VERSION: ${{ steps.target_node.outputs.version }}
348 run: |
349 set -euo pipefail
350 name="node-v$VERSION-win-${{ inputs.arch }}"
351 dir="$RUNNER_TEMP/node-download"
352 mkdir -p "$dir"
353 fetch=(curl -fsSL --retry 5 --retry-all-errors --connect-timeout 10 --speed-limit 102400 --speed-time 30)
354 "${fetch[@]}" -o "$dir/$name.zip" "https://nodejs.org/dist/v$VERSION/$name.zip"
355 "${fetch[@]}" -o "$dir/SHASUMS256.txt" "https://nodejs.org/dist/v$VERSION/SHASUMS256.txt"
356 (cd "$dir" && grep " $name.zip\$" SHASUMS256.txt | sha256sum -c -)
357
358 # Saved right away so a later failure in this job still keeps the download.
359 - name: Save target Node.js for the CLI executable
360 if: inputs.cli_archive && inputs.platform == 'win' && steps.target_node_cache.outputs.cache-hit != 'true'
361 uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
362 with:
363 path: ${{ runner.temp }}/node-download
364 key: ${{ steps.target_node_cache.outputs.cache-primary-key }}
365
366 - name: Install target Node.js for the CLI executable
367 if: inputs.cli_archive && inputs.platform == 'win'
368 shell: bash
369 env:
370 VERSION: ${{ steps.target_node.outputs.version }}
371 run: |
372 set -euo pipefail
373 name="node-v$VERSION-win-${{ inputs.arch }}"
374 dir="$RUNNER_TEMP/node-download"
375 dest="${XDG_CACHE_HOME:-$HOME/.cache}/tsdown/node/v$VERSION/win-${{ inputs.arch }}"
376 mkdir -p "$dest"
377 (cd "$dir" && grep " $name.zip\$" SHASUMS256.txt | sha256sum -c -)
378 unzip -p "$dir/$name.zip" "$name/node.exe" > "$dest/node.exe"
379
380 # Setup Vite+ selects the exact engines.node version from package.json.
381 # Native builds embed that executable; cross-target builds download the
382 # same version for their target.
383 - name: Build CLI single-executable
384 if: inputs.cli_archive
385 shell: bash
386 env:
387 # The executable bundles the server again, so it needs the same stamp
388 # as release.yml's JS bundle.
389 T3CODE_TELEMETRY_CHANNEL: ${{ github.repository == 'pingdotgg/t3code' && inputs.release_channel || 'dev' }}
390 run: node apps/server/scripts/cli.ts build-exe --verbose ${{ inputs.platform == 'win' && format('--target win-{0}', inputs.arch) || '' }}
391
392 - name: Import macOS signing certificate for the CLI archive
393 if: inputs.cli_archive && inputs.platform == 'mac'
394 shell: bash
395 env:
396 CSC_LINK: ${{ secrets.CSC_LINK }}
397 CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
398 run: |
399 set -euo pipefail
400 if [[ -z "$CSC_LINK" || -z "$CSC_KEY_PASSWORD" ]]; then
401 echo "macOS CLI signing disabled (missing CSC_LINK); the archive is signed ad hoc."
402 exit 0
403 fi
404 keychain="$RUNNER_TEMP/t3-cli-signing.keychain-db"
405 keychain_password="$(openssl rand -hex 16)"
406 cert_path="$RUNNER_TEMP/t3-cli-signing.p12"
407 printf '%s' "$CSC_LINK" | base64 --decode > "$cert_path"
408 security create-keychain -p "$keychain_password" "$keychain"
409 security set-keychain-settings -lut 21600 "$keychain"
410 security unlock-keychain -p "$keychain_password" "$keychain"
411 security import "$cert_path" -k "$keychain" -P "$CSC_KEY_PASSWORD" -T /usr/bin/codesign
412 security set-key-partition-list -S apple-tool:,apple: -s -k "$keychain_password" "$keychain" >/dev/null
413 security list-keychains -d user -s "$keychain" $(security list-keychains -d user | tr -d '"')
414 identity="$(security find-identity -v -p codesigning "$keychain" | sed -n 's/.*"\(Developer ID Application: [^"]*\)".*/\1/p' | head -n 1)"
415 if [[ -z "$identity" ]]; then
416 echo "No Developer ID Application identity found in CSC_LINK." >&2
417 exit 1
418 fi
419 echo "::add-mask::$keychain_password"
420 echo "T3CODE_CLI_MAC_SIGN_IDENTITY=$identity" >> "$GITHUB_ENV"
421 echo "macOS CLI signing enabled."
422
423 - name: Stage resource monitor for the CLI archive
424 if: inputs.cli_archive
425 shell: bash
426 run: |
427 set -euo pipefail
428 binary_name="t3-resource-monitor"
429 if [[ "${{ inputs.platform }}" == "win" ]]; then
430 binary_name="${binary_name}.exe"
431 fi
432 target_dir="$RUNNER_TEMP/cli-resource-monitor/${{ inputs.resource_key }}"
433 mkdir -p "$target_dir"
434 cp "native/resource-monitor/target/${{ inputs.rust_target }}/release/${binary_name}" "$target_dir/$binary_name"
435
436 - uses: ./.github/actions/setup-apt-mirrors
437 if: inputs.platform == 'linux'
438
439 # The Linux archive ships libatomic.so.1 and points t3's RUNPATH at it.
440 - name: Install patchelf
441 if: inputs.cli_archive && inputs.platform == 'linux'
442 shell: bash
443 run: command -v patchelf || { sudo apt-get update && sudo apt-get install -y patchelf; }
444
445 - name: Build CLI archive
446 id: build_cli
447 if: inputs.cli_archive
448 shell: bash
449 env:
450 pnpm_config_cache_dir: ${{ steps.stage_pnpm.outputs.dir }}/cache
451 pnpm_config_store_dir: ${{ steps.stage_pnpm.outputs.dir }}/store
452 pnpm_config_prefer_offline: "true"
453 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
454 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
455 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
456 AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
457 AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
458 AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
459 AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
460 AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
461 AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }}
462 run: |
463 set -euo pipefail
464 extra_args=()
465 if [[ "${{ inputs.platform }}" == "mac" ]]; then
466 if [[ -n "${APPLE_API_KEY:-}" ]]; then
467 key_dir="$(mktemp -d "$RUNNER_TEMP/t3-cli-notary.XXXXXXXX")"
468 trap 'rm -rf "$key_dir"' EXIT
469 key_path="$key_dir/AuthKey.p8"
470 (umask 077 && printf '%s' "$APPLE_API_KEY" > "$key_path")
471 export APPLE_API_KEY="$key_path"
472 fi
473 # Older release refs lack deferred notarization and still wait here.
474 cli_help="$(node scripts/build-cli-archive.ts --help)"
475 if [[ "$cli_help" == *--notary-submission-file* ]]; then
476 extra_args=(--notary-submission-file "$RUNNER_TEMP/t3-cli-notary-submission")
477 echo "deferred_notarization=true" >> "$GITHUB_OUTPUT"
478 fi
479 fi
480 node scripts/build-cli-archive.ts \
481 --platform "${{ inputs.platform }}" \
482 --arch "${{ inputs.arch }}" \
483 --version "${{ inputs.version }}" \
484 --resource-monitor-dir "$RUNNER_TEMP/cli-resource-monitor" \
485 --output-dir release-cli \
486 ${extra_args[@]+"${extra_args[@]}"}
487
488 - name: Smoke-test CLI archive
489 if: inputs.cli_archive && inputs.verify_runner == ''
490 shell: bash
491 run: node scripts/smoke-cli-archive.ts --archive release-cli/* --expect-version "${{ inputs.version }}"
492
493 # macOS uploads its archive after "Await CLI notarization" instead.
494 - name: Upload CLI archive
495 if: inputs.cli_archive && inputs.platform != 'mac'
496 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
497 with:
498 name: cli-${{ inputs.platform }}-${{ inputs.arch }}
499 path: release-cli/*
500 if-no-files-found: error
501 # The archive is already gzip or zip; deflating it again saves under 2%.
502 compression-level: 0
503
504 - name: Install Linux desktop build libraries
505 if: inputs.platform == 'linux'
506 shell: bash
507 run: |
508 sudo apt-get update
509 sudo apt-get install -y libsecret-1-dev pkg-config libgtk-3-0t64 libnss3 libasound2t64 libgbm1
510 if ! command -v magick >/dev/null 2>&1 && ! command -v convert >/dev/null 2>&1; then
511 sudo apt-get install -y imagemagick
512 fi
513
514 if command -v magick >/dev/null 2>&1; then
515 magick -version
516 else
517 convert -version
518 fi
519
520 # The WSL backend runs the Linux CLI archive inside the distro, so the
521 # Windows desktop embeds the same-arch archive the release attaches.
522 # This job starts alongside that Linux job instead of after it, and the
523 # Linux job uploads the archive partway through, so the wait is placed
524 # after all other setup. It stops early if the Linux job ended without
525 # uploading the archive.
526 - name: Wait for Linux CLI archive
527 if: inputs.platform == 'win'
528 shell: pwsh
529 timeout-minutes: 40
530 env:
531 GITHUB_TOKEN: ${{ github.token }}
532 ARTIFACT: cli-linux-${{ inputs.arch }}
533 LINUX_JOB: Build Linux ${{ inputs.arch }}
534 run: |
535 $headers = @{ Authorization = "Bearer $env:GITHUB_TOKEN"; Accept = "application/vnd.github+json" }
536 $run = "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID"
537 function Test-Archive {
538 (Invoke-RestMethod -Headers $headers -Uri "$run/artifacts?name=$env:ARTIFACT").total_count -gt 0
539 }
540 $missingSince = $null
541 while ($true) {
542 try {
543 if (Test-Archive) {
544 Write-Host "$env:ARTIFACT is ready."
545 exit 0
546 }
547 $jobs = Invoke-RestMethod -Headers $headers -Uri "$run/attempts/$env:GITHUB_RUN_ATTEMPT/jobs?per_page=100"
548 $linux = $jobs.jobs | Where-Object { $_.name.EndsWith($env:LINUX_JOB) } | Select-Object -First 1
549 if (-not $linux) {
550 # Both jobs start together, so a Linux job still missing after a
551 # few minutes means a renamed or skipped job, not a slow one.
552 if (-not $missingSince) {
553 $missingSince = Get-Date
554 } elseif (((Get-Date) - $missingSince).TotalMinutes -ge 5) {
555 Write-Host "::error::No job named '$env:LINUX_JOB' in this run, so $env:ARTIFACT will not arrive."
556 exit 1
557 }
558 } elseif ($linux.conclusion) {
559 # The upload may have landed between the two requests above.
560 if (Test-Archive) {
561 Write-Host "$env:ARTIFACT is ready."
562 exit 0
563 }
564 Write-Host "::error::$env:LINUX_JOB ended ($($linux.conclusion)) without uploading $env:ARTIFACT."
565 exit 1
566 }
567 } catch {
568 Write-Warning "Could not read this run's artifacts or jobs: $($_.Exception.Message)"
569 }
570 Write-Host "Waiting for $env:ARTIFACT..."
571 Start-Sleep -Seconds 10
572 }
573
574 - name: Download Linux CLI archive for WSL
575 if: inputs.platform == 'win'
576 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
577 with:
578 name: cli-linux-${{ inputs.arch }}
579 path: wsl-runtime
580
581 - name: Build desktop artifact
582 shell: bash
583 env:
584 # pnpm only goes to the registry for packages or versions the cache lacks.
585 pnpm_config_cache_dir: ${{ steps.stage_pnpm.outputs.dir }}/cache
586 pnpm_config_store_dir: ${{ steps.stage_pnpm.outputs.dir }}/store
587 pnpm_config_prefer_offline: "true"
588 T3CODE_DESKTOP_REUSE_RESOURCE_MONITOR: true
589 T3CODE_DESKTOP_REUSE_LINUX_CAPTURE_HELPERS: ${{ steps.capture_helper_cache.outputs.cache-hit == 'true' }}
590 T3CODE_DESKTOP_UNTRUSTED_BUNDLE: ${{ inputs.untrusted_bundle }}
591 CSC_LINK: ${{ secrets.CSC_LINK }}
592 CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
593 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
594 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
595 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
596 APPLE_TEAM_ID: ${{ vars.APPLE_TEAM_ID }}
597 MACOS_PROVISIONING_PROFILE: ${{ secrets.MACOS_PROVISIONING_PROFILE }}
598 T3CODE_CLERK_PASSKEY_RP_DOMAINS: ${{ vars.CLERK_PASSKEY_RP_DOMAINS }}
599 AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
600 AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
601 AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
602 AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
603 AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
604 AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }}
605 AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }}
606 run: |
607 args=(
608 --platform "${{ inputs.platform }}"
609 --target "${{ inputs.target }}"
610 --arch "${{ inputs.arch }}"
611 --build-version "${{ inputs.version }}"
612 --skip-build
613 --verbose
614 )
615 if [[ -n "${{ inputs.verify_runner }}" ]]; then
616 args+=(--keep-stage)
617 fi
618
619 has_all() {
620 for value in "$@"; do
621 if [[ -z "$value" ]]; then
622 return 1
623 fi
624 done
625 return 0
626 }
627
628 if [[ "${{ inputs.platform }}" == "mac" ]]; then
629 if has_all "$CSC_LINK" "$CSC_KEY_PASSWORD" "$APPLE_API_KEY" "$APPLE_API_KEY_ID" "$APPLE_API_ISSUER"; then
630 if ! has_all "$APPLE_TEAM_ID" "$MACOS_PROVISIONING_PROFILE"; then
631 echo "macOS signing is configured, but APPLE_TEAM_ID or MACOS_PROVISIONING_PROFILE is missing." >&2
632 exit 1
633 fi
634
635 key_path="$RUNNER_TEMP/AuthKey_${APPLE_API_KEY_ID}.p8"
636 printf '%s' "$APPLE_API_KEY" > "$key_path"
637 export APPLE_API_KEY="$key_path"
638
639 profile_path="$RUNNER_TEMP/t3code.provisionprofile"
640 printf '%s' "$MACOS_PROVISIONING_PROFILE" | base64 -D > "$profile_path"
641 security cms -D -i "$profile_path" >/dev/null
642 export T3CODE_APPLE_TEAM_ID="$APPLE_TEAM_ID"
643 export T3CODE_MACOS_PROVISIONING_PROFILE="$profile_path"
644
645 echo "macOS signing enabled."
646 args+=(--signed)
647 else
648 echo "macOS signing disabled (missing one or more Apple signing secrets)."
649 fi
650 elif [[ "${{ inputs.platform }}" == "win" ]]; then
651 # Embed the Linux CLI archive built by the same-arch Linux job as
652 # the WSL runtime. Required for a working WSL backend on Windows.
653 args+=(--wsl-runtime "$GITHUB_WORKSPACE"/wsl-runtime/t3-*-linux-${{ inputs.arch }}.tar.gz)
654 if has_all \
655 "$AZURE_TENANT_ID" \
656 "$AZURE_CLIENT_ID" \
657 "$AZURE_CLIENT_SECRET" \
658 "$AZURE_TRUSTED_SIGNING_ENDPOINT" \
659 "$AZURE_TRUSTED_SIGNING_ACCOUNT_NAME" \
660 "$AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME" \
661 "$AZURE_TRUSTED_SIGNING_PUBLISHER_NAME"; then
662 echo "Windows signing enabled (Azure Trusted Signing)."
663 args+=(--signed)
664 else
665 echo "Windows signing disabled (missing one or more Azure Trusted Signing secrets)."
666 fi
667 else
668 echo "Signing disabled for ${{ inputs.platform }}."
669 fi
670
671 vp run dist:desktop:artifact "${args[@]}"
672
673 # The CLI was submitted without waiting so Apple reviews it while the
674 # desktop builds. Notarization does not change the archive bytes, but
675 # nothing uploads them, so nothing publishes them, until Apple accepts.
676 # With signing configured, a missing submission id fails this step.
677 - name: Await CLI notarization
678 if: inputs.cli_archive && inputs.platform == 'mac' && steps.build_cli.outputs.deferred_notarization == 'true'
679 shell: bash
680 env:
681 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
682 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
683 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
684 run: |
685 set -euo pipefail
686 if [[ -n "${APPLE_API_KEY:-}" ]]; then
687 key_dir="$(mktemp -d "$RUNNER_TEMP/t3-cli-notary.XXXXXXXX")"
688 trap 'rm -rf "$key_dir"' EXIT
689 key_path="$key_dir/AuthKey.p8"
690 (umask 077 && printf '%s' "$APPLE_API_KEY" > "$key_path")
691 export APPLE_API_KEY="$key_path"
692 fi
693 node scripts/build-cli-archive.ts await-notarization \
694 --submission-file "$RUNNER_TEMP/t3-cli-notary-submission"
695
696 - name: Upload notarized CLI archive
697 if: inputs.cli_archive && inputs.platform == 'mac'
698 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
699 with:
700 name: cli-${{ inputs.platform }}-${{ inputs.arch }}
701 path: release-cli/*
702 if-no-files-found: error
703 # The archive is already gzip or zip; deflating it again saves under 2%.
704 compression-level: 0
705
706 # Warm installs only touch the store index, so new content means a fetch.
707 - name: Check staged install cache for new content
708 id: stage_pnpm_changed
709 shell: bash
710 run: |
711 dir="${{ steps.stage_pnpm.outputs.dir }}"
712 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 ' ')
713 echo "Staged installs added $new cached files."
714 echo "changed=$([[ "$new" -gt 0 ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"
715
716 - name: Save staged install cache
717 if: steps.stage_pnpm_changed.outputs.changed == 'true'
718 uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
719 with:
720 path: ${{ steps.stage_pnpm.outputs.dir }}
721 key: ${{ steps.stage_pnpm_cache.outputs.cache-primary-key }}
722
723 # A build can package fine and still not open (a missing module in the
724 # backend or the bundle). This launches the app from the shipped
725 # AppImage or DMG.
726 - name: Launch check
727 if: inputs.launch_check
728 shell: bash
729 run: |
730 set -euo pipefail
731 check=(node scripts/smoke-desktop-app.ts --artifacts-dir "$RUNNER_TEMP/desktop-launch-check")
732 if [[ "${{ inputs.platform }}" == "mac" ]]; then
733 mount="$RUNNER_TEMP/desktop-launch-dmg"
734 hdiutil attach -nobrowse -readonly -mountpoint "$mount" "$(ls "$GITHUB_WORKSPACE"/release/*.dmg)"
735 trap 'hdiutil detach "$mount" -force >/dev/null || true' EXIT
736 app=$(ls -d "$mount"/*.app)
737 executable=$(/usr/libexec/PlistBuddy -c "Print :CFBundleExecutable" "$app/Contents/Info.plist")
738 "${check[@]}" --executable "$app/Contents/MacOS/$executable"
739 else
740 sudo apt-get install -y xvfb
741 appimage=$(ls "$GITHUB_WORKSPACE"/release/*.AppImage)
742 chmod +x "$appimage"
743 (cd "$RUNNER_TEMP" && "$appimage" --appimage-extract >/dev/null)
744 xvfb-run -a "${check[@]}" --executable "$RUNNER_TEMP/squashfs-root/t3code"
745 fi
746
747 - name: Upload launch check output
748 if: failure() && inputs.launch_check
749 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
750 with:
751 name: desktop-launch-check-${{ inputs.platform }}-${{ inputs.arch }}
752 path: ${{ runner.temp }}/desktop-launch-check
753 if-no-files-found: ignore
754
755 # The verify job runs what this host could not: the packaged natives and
756 # the CLI. Its scripts are bundled so that job needs no install.
757 - name: Stage verification inputs
758 if: inputs.verify_runner != ''
759 shell: bash
760 run: |
761 set -euo pipefail
762 mkdir -p verify
763 unpacked=$(ls -d "${TMPDIR:-/tmp}"/t3code-desktop-${{ inputs.platform }}-stage-*/app/dist/"$UNPACKED_DIR")
764 tar -C "$(dirname "$unpacked")" -cf verify/unpacked.tar "$(basename "$unpacked")"
765 esbuild=scripts/node_modules/.bin/esbuild
766 banner="import{createRequire as __cr}from'node:module';const require=__cr(import.meta.url);"
767 # build-desktop-artifact.ts's own import.meta.main guard must not run
768 # its CLI inside the verify bundle.
769 "$esbuild" scripts/verify-windows-desktop-artifact.ts --bundle --platform=node --format=esm \
770 --target=node24 --define:import.meta.main=false --banner:js="$banner" \
771 --outfile=verify/verify-windows-desktop-artifact.mjs
772 "$esbuild" scripts/smoke-cli-archive.ts --bundle --platform=node --format=esm \
773 --target=node24 --banner:js="$banner" --outfile=verify/smoke-cli-archive.mjs
774
775 - name: Upload verification inputs
776 if: inputs.verify_runner != ''
777 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
778 with:
779 name: verify-${{ inputs.platform }}-${{ inputs.arch }}
780 path: verify/*
781 if-no-files-found: error
782 retention-days: 1
783 compression-level: 1
784
785 - name: Collect release assets
786 shell: bash
787 run: |
788 set -euo pipefail
789 mkdir -p release-publish
790
791 shopt -s nullglob
792 patterns=(
793 "release/*.dmg"
794 "release/*.zip"
795 "release/*.AppImage"
796 "release/*.deb"
797 "release/*.exe"
798 )
799 # Preview builds have no publish config, so electron-builder writes
800 # no feed manifest for them, but it still emits blockmaps beside the
801 # installers. Neither belongs on a release no updater may follow.
802 if [[ "${{ inputs.release_channel }}" != "preview" ]]; then
803 patterns+=("release/*.blockmap" "release/*.yml")
804 fi
805 for pattern in "${patterns[@]}"; do
806 for file in $pattern; do
807 cp "$file" release-publish/
808 done
809 done
810
811 if [[ "${{ inputs.platform }}" == "mac" && "${{ inputs.arch }}" != "arm64" ]]; then
812 shopt -s nullglob
813 for manifest in release-publish/*-mac.yml; do
814 mv "$manifest" "${manifest%.yml}-${{ inputs.arch }}.yml"
815 done
816 fi
817
818 # Windows updater metadata is channel-specific (for example
819 # "latest.yml" or "nightly.yml") and carries no arch, so the x64 and
820 # arm64 jobs would upload the same name. Suffix each per-arch copy;
821 # the release job merges them back into one manifest per channel.
822 # builder-debug.yml is electron-builder's config dump, not a feed.
823 if [[ "${{ inputs.platform }}" == "win" ]]; then
824 for manifest in release-publish/*.yml; do
825 [[ "$manifest" == */builder-debug.yml ]] && continue
826 mv "$manifest" "${manifest%.yml}-win-${{ inputs.arch }}.yml"
827 done
828 fi
829
830 - name: Collect resource monitor
831 shell: bash
832 run: |
833 set -euo pipefail
834 binary_name="t3-resource-monitor"
835 if [[ "${{ inputs.platform }}" == "win" ]]; then
836 binary_name="${binary_name}.exe"
837 fi
838 source_path="native/resource-monitor/target/${{ inputs.rust_target }}/release/${binary_name}"
839 target_dir="resource-monitor-publish/${{ inputs.resource_key }}"
840 mkdir -p "$target_dir"
841 cp "$source_path" "$target_dir/$binary_name"
842
843 - name: Upload build artifacts
844 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
845 with:
846 name: desktop-${{ inputs.platform }}-${{ inputs.arch }}
847 path: release-publish/*
848 if-no-files-found: error
849 # Installers, zips and blockmaps are already compressed; deflating them again saves under 0.3%.
850 compression-level: 0
851
852 - name: Upload resource monitor
853 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
854 with:
855 name: resource-monitor-${{ inputs.resource_key }}
856 path: resource-monitor-publish/${{ inputs.resource_key }}/*
857 if-no-files-found: error
858
859 verify:
860 name: Verify
861 needs: [build]
862 if: inputs.verify_runner != ''
863 runs-on: ${{ inputs.verify_runner }}
864 timeout-minutes: 15
865 steps:
866 - name: Download verification inputs
867 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
868 with:
869 name: verify-${{ inputs.platform }}-${{ inputs.arch }}
870 path: verify
871
872 - name: Download CLI archive
873 if: inputs.cli_archive
874 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
875 with:
876 name: cli-${{ inputs.platform }}-${{ inputs.arch }}
877 path: release-cli
878
879 - name: Verify packaged natives
880 shell: bash
881 run: |
882 set -euo pipefail
883 tar -C verify -xf verify/unpacked.tar
884 node verify/verify-windows-desktop-artifact.mjs \
885 --app-dir "$(cygpath -w "$PWD/verify/$UNPACKED_DIR")" \
886 --arch "${{ inputs.arch }}" --build-version "${{ inputs.version }}" --verbose
887
888 - name: Smoke-test CLI archive
889 if: inputs.cli_archive
890 shell: bash
891 run: node verify/smoke-cli-archive.mjs --archive release-cli/* --expect-version "${{ inputs.version }}"
892
893 # cargo-xwin links this binary on Linux, and nothing else runs it before users do.
894 # Node rather than pwsh: PowerShell on Windows ARM crashes intermittently
895 # (https://github.com/dotnet/runtime/issues/131636), which is why this
896 # target stopped building on Windows.
897 - name: Smoke-test resource monitor
898 shell: bash
899 env:
900 MONITOR: verify/${{ env.UNPACKED_DIR }}/resources/resource-monitor/t3-resource-monitor.exe
901 EXPECTED_ARCH: ${{ inputs.arch == 'arm64' && 'aarch64' || 'x86_64' }}
902 run: |
903 node --input-type=module <<'EOF'
904 import { spawn } from "node:child_process";
905 const monitor = spawn(process.env.MONITOR, { stdio: ["pipe", "pipe", "inherit"] });
906 monitor.stdout.setEncoding("utf8");
907 let output = "";
908 const exited = new Promise((resolve) => monitor.on("close", resolve));
909 const hello = await new Promise((resolve, reject) => {
910 monitor.on("error", reject);
911 monitor.on("close", () => reject(new Error(`Resource monitor exited before hello: ${output}`)));
912 monitor.stdout.on("data", (chunk) => {
913 output += chunk;
914 const end = output.indexOf("\n");
915 if (end !== -1) resolve(JSON.parse(output.slice(0, end)));
916 });
917 });
918 if (hello.type !== "hello" || hello.arch !== process.env.EXPECTED_ARCH) {
919 throw new Error(`Unexpected hello: ${JSON.stringify(hello)}`);
920 }
921 const send = (message) => monitor.stdin.write(`${JSON.stringify({ version: hello.version, ...message })}\n`);
922 send({ type: "configure", rootPid: process.pid, sampleIntervalMs: 1000 });
923 send({ type: "sampleNow", requestId: "verify" });
924 monitor.stdin.end();
925 const exitCode = await exited;
926 const sample = output
927 .split("\n")
928 .filter((line) => line.trim())
929 .map((line) => JSON.parse(line))
930 .find((message) => message.requestId === "verify");
931 if (exitCode !== 0 || sample?.type !== "snapshot" || !sample.processes.some((p) => p.pid === process.pid)) {
932 throw new Error(`Resource monitor exited ${exitCode} with: ${output}`);
933 }
934 console.log(`Resource monitor sampled ${sample.scannedProcessCount} processes.`);
935 EOF