Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

release-desktop.yml

944 lines42.9 KB

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 - name: Download Linux CLI archive for WSL
584 if: inputs.platform == 'win'
585 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
586 with:
587 name: cli-linux-${{ inputs.arch }}
588 path: wsl-runtime
589​
590 - name: Build desktop artifact
591 shell: bash
592 env:
593 # pnpm only goes to the registry for packages or versions the cache lacks.
594 pnpm_config_cache_dir: ${{ steps.stage_pnpm.outputs.dir }}/cache
595 pnpm_config_store_dir: ${{ steps.stage_pnpm.outputs.dir }}/store
596 pnpm_config_prefer_offline: "true"
597 T3CODE_DESKTOP_REUSE_RESOURCE_MONITOR: true
598 T3CODE_DESKTOP_REUSE_LINUX_CAPTURE_HELPERS: ${{ steps.capture_helper_cache.outputs.cache-hit == 'true' }}
599 T3CODE_DESKTOP_UNTRUSTED_BUNDLE: ${{ inputs.untrusted_bundle }}
600 CSC_LINK: ${{ secrets.CSC_LINK }}
601 CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
602 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
603 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
604 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
605 APPLE_TEAM_ID: ${{ vars.APPLE_TEAM_ID }}
606 MACOS_PROVISIONING_PROFILE: ${{ secrets.MACOS_PROVISIONING_PROFILE }}
607 T3CODE_CLERK_PASSKEY_RP_DOMAINS: ${{ vars.CLERK_PASSKEY_RP_DOMAINS }}
608 AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
609 AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
610 AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
611 AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
612 AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
613 AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }}
614 AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }}
615 run: |
616 args=(
617 --platform "${{ inputs.platform }}"
618 --target "${{ inputs.target }}"
619 --arch "${{ inputs.arch }}"
620 --build-version "${{ inputs.version }}"
621 --skip-build
622 --verbose
623 )
624 if [[ -n "${{ inputs.verify_runner }}" ]]; then
625 args+=(--keep-stage)
626 fi
627​
628 has_all() {
629 for value in "$@"; do
630 if [[ -z "$value" ]]; then
631 return 1
632 fi
633 done
634 return 0
635 }
636​
637 if [[ "${{ inputs.platform }}" == "mac" ]]; then
638 if has_all "$CSC_LINK" "$CSC_KEY_PASSWORD" "$APPLE_API_KEY" "$APPLE_API_KEY_ID" "$APPLE_API_ISSUER"; then
639 if ! has_all "$APPLE_TEAM_ID" "$MACOS_PROVISIONING_PROFILE"; then
640 echo "macOS signing is configured, but APPLE_TEAM_ID or MACOS_PROVISIONING_PROFILE is missing." >&2
641 exit 1
642 fi
643​
644 key_path="$RUNNER_TEMP/AuthKey_${APPLE_API_KEY_ID}.p8"
645 printf '%s' "$APPLE_API_KEY" > "$key_path"
646 export APPLE_API_KEY="$key_path"
647​
648 profile_path="$RUNNER_TEMP/t3code.provisionprofile"
649 printf '%s' "$MACOS_PROVISIONING_PROFILE" | base64 -D > "$profile_path"
650 security cms -D -i "$profile_path" >/dev/null
651 export T3CODE_APPLE_TEAM_ID="$APPLE_TEAM_ID"
652 export T3CODE_MACOS_PROVISIONING_PROFILE="$profile_path"
653​
654 echo "macOS signing enabled."
655 args+=(--signed)
656 else
657 echo "macOS signing disabled (missing one or more Apple signing secrets)."
658 fi
659 elif [[ "${{ inputs.platform }}" == "win" ]]; then
660 # Embed the Linux CLI archive built by the same-arch Linux job as
661 # the WSL runtime. Required for a working WSL backend on Windows.
662 args+=(--wsl-runtime "$GITHUB_WORKSPACE"/wsl-runtime/t3-*-linux-${{ inputs.arch }}.tar.gz)
663 if has_all \
664 "$AZURE_TENANT_ID" \
665 "$AZURE_CLIENT_ID" \
666 "$AZURE_CLIENT_SECRET" \
667 "$AZURE_TRUSTED_SIGNING_ENDPOINT" \
668 "$AZURE_TRUSTED_SIGNING_ACCOUNT_NAME" \
669 "$AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME" \
670 "$AZURE_TRUSTED_SIGNING_PUBLISHER_NAME"; then
671 echo "Windows signing enabled (Azure Trusted Signing)."
672 args+=(--signed)
673 else
674 echo "Windows signing disabled (missing one or more Azure Trusted Signing secrets)."
675 fi
676 else
677 echo "Signing disabled for ${{ inputs.platform }}."
678 fi
679​
680 vp run dist:desktop:artifact "${args[@]}"
681​
682 # The CLI was submitted without waiting so Apple reviews it while the
683 # desktop builds. Notarization does not change the archive bytes, but
684 # nothing uploads them, so nothing publishes them, until Apple accepts.
685 # With signing configured, a missing submission id fails this step.
686 - name: Await CLI notarization
687 if: inputs.cli_archive && inputs.platform == 'mac' && steps.build_cli.outputs.deferred_notarization == 'true'
688 shell: bash
689 env:
690 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
691 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
692 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
693 run: |
694 set -euo pipefail
695 if [[ -n "${APPLE_API_KEY:-}" ]]; then
696 key_dir="$(mktemp -d "$RUNNER_TEMP/t3-cli-notary.XXXXXXXX")"
697 trap 'rm -rf "$key_dir"' EXIT
698 key_path="$key_dir/AuthKey.p8"
699 (umask 077 && printf '%s' "$APPLE_API_KEY" > "$key_path")
700 export APPLE_API_KEY="$key_path"
701 fi
702 node scripts/build-cli-archive.ts await-notarization \
703 --submission-file "$RUNNER_TEMP/t3-cli-notary-submission"
704​
705 - name: Upload notarized CLI archive
706 if: inputs.cli_archive && inputs.platform == 'mac'
707 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
708 with:
709 name: cli-${{ inputs.platform }}-${{ inputs.arch }}
710 path: release-cli/*
711 if-no-files-found: error
712 # The archive is already gzip or zip; deflating it again saves under 2%.
713 compression-level: 0
714​
715 # Warm installs only touch the store index, so new content means a fetch.
716 - name: Check staged install cache for new content
717 id: stage_pnpm_changed
718 shell: bash
719 run: |
720 dir="${{ steps.stage_pnpm.outputs.dir }}"
721 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 ' ')
722 echo "Staged installs added $new cached files."
723 echo "changed=$([[ "$new" -gt 0 ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"
724​
725 - name: Save staged install cache
726 if: steps.stage_pnpm_changed.outputs.changed == 'true'
727 uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
728 with:
729 path: ${{ steps.stage_pnpm.outputs.dir }}
730 key: ${{ steps.stage_pnpm_cache.outputs.cache-primary-key }}
731​
732 # A build can package fine and still not open (a missing module in the
733 # backend or the bundle). This launches the app from the shipped
734 # AppImage or DMG.
735 - name: Launch check
736 if: inputs.launch_check
737 shell: bash
738 run: |
739 set -euo pipefail
740 check=(node scripts/smoke-desktop-app.ts --artifacts-dir "$RUNNER_TEMP/desktop-launch-check")
741 if [[ "${{ inputs.platform }}" == "mac" ]]; then
742 mount="$RUNNER_TEMP/desktop-launch-dmg"
743 hdiutil attach -nobrowse -readonly -mountpoint "$mount" "$(ls "$GITHUB_WORKSPACE"/release/*.dmg)"
744 trap 'hdiutil detach "$mount" -force >/dev/null || true' EXIT
745 app=$(ls -d "$mount"/*.app)
746 executable=$(/usr/libexec/PlistBuddy -c "Print :CFBundleExecutable" "$app/Contents/Info.plist")
747 "${check[@]}" --executable "$app/Contents/MacOS/$executable"
748 else
749 sudo apt-get install -y xvfb
750 appimage=$(ls "$GITHUB_WORKSPACE"/release/*.AppImage)
751 chmod +x "$appimage"
752 (cd "$RUNNER_TEMP" && "$appimage" --appimage-extract >/dev/null)
753 xvfb-run -a "${check[@]}" --executable "$RUNNER_TEMP/squashfs-root/t3code"
754 fi
755​
756 - name: Upload launch check output
757 if: failure() && inputs.launch_check
758 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
759 with:
760 name: desktop-launch-check-${{ inputs.platform }}-${{ inputs.arch }}
761 path: ${{ runner.temp }}/desktop-launch-check
762 if-no-files-found: ignore
763​
764 # The verify job runs what this host could not: the packaged natives and
765 # the CLI. Its scripts are bundled so that job needs no install.
766 - name: Stage verification inputs
767 if: inputs.verify_runner != ''
768 shell: bash
769 run: |
770 set -euo pipefail
771 mkdir -p verify
772 unpacked=$(ls -d "${TMPDIR:-/tmp}"/t3code-desktop-${{ inputs.platform }}-stage-*/app/dist/"$UNPACKED_DIR")
773 tar -C "$(dirname "$unpacked")" -cf verify/unpacked.tar "$(basename "$unpacked")"
774 esbuild=scripts/node_modules/.bin/esbuild
775 banner="import{createRequire as __cr}from'node:module';const require=__cr(import.meta.url);"
776 # build-desktop-artifact.ts's own import.meta.main guard must not run
777 # its CLI inside the verify bundle.
778 "$esbuild" scripts/verify-windows-desktop-artifact.ts --bundle --platform=node --format=esm \
779 --target=node24 --define:import.meta.main=false --banner:js="$banner" \
780 --outfile=verify/verify-windows-desktop-artifact.mjs
781 "$esbuild" scripts/smoke-cli-archive.ts --bundle --platform=node --format=esm \
782 --target=node24 --banner:js="$banner" --outfile=verify/smoke-cli-archive.mjs
783​
784 - name: Upload verification inputs
785 if: inputs.verify_runner != ''
786 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
787 with:
788 name: verify-${{ inputs.platform }}-${{ inputs.arch }}
789 path: verify/*
790 if-no-files-found: error
791 retention-days: 1
792 compression-level: 1
793​
794 - name: Collect release assets
795 shell: bash
796 run: |
797 set -euo pipefail
798 mkdir -p release-publish
799​
800 shopt -s nullglob
801 patterns=(
802 "release/*.dmg"
803 "release/*.zip"
804 "release/*.AppImage"
805 "release/*.deb"
806 "release/*.exe"
807 )
808 # Preview builds have no publish config, so electron-builder writes
809 # no feed manifest for them, but it still emits blockmaps beside the
810 # installers. Neither belongs on a release no updater may follow.
811 if [[ "${{ inputs.release_channel }}" != "preview" ]]; then
812 patterns+=("release/*.blockmap" "release/*.yml")
813 fi
814 for pattern in "${patterns[@]}"; do
815 for file in $pattern; do
816 cp "$file" release-publish/
817 done
818 done
819​
820 if [[ "${{ inputs.platform }}" == "mac" && "${{ inputs.arch }}" != "arm64" ]]; then
821 shopt -s nullglob
822 for manifest in release-publish/*-mac.yml; do
823 mv "$manifest" "${manifest%.yml}-${{ inputs.arch }}.yml"
824 done
825 fi
826​
827 # Windows updater metadata is channel-specific (for example
828 # "latest.yml" or "nightly.yml") and carries no arch, so the x64 and
829 # arm64 jobs would upload the same name. Suffix each per-arch copy;
830 # the release job merges them back into one manifest per channel.
831 # builder-debug.yml is electron-builder's config dump, not a feed.
832 if [[ "${{ inputs.platform }}" == "win" ]]; then
833 for manifest in release-publish/*.yml; do
834 [[ "$manifest" == */builder-debug.yml ]] && continue
835 mv "$manifest" "${manifest%.yml}-win-${{ inputs.arch }}.yml"
836 done
837 fi
838​
839 - name: Collect resource monitor
840 shell: bash
841 run: |
842 set -euo pipefail
843 binary_name="t3-resource-monitor"
844 if [[ "${{ inputs.platform }}" == "win" ]]; then
845 binary_name="${binary_name}.exe"
846 fi
847 source_path="native/resource-monitor/target/${{ inputs.rust_target }}/release/${binary_name}"
848 target_dir="resource-monitor-publish/${{ inputs.resource_key }}"
849 mkdir -p "$target_dir"
850 cp "$source_path" "$target_dir/$binary_name"
851​
852 - name: Upload build artifacts
853 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
854 with:
855 name: desktop-${{ inputs.platform }}-${{ inputs.arch }}
856 path: release-publish/*
857 if-no-files-found: error
858 # Installers, zips and blockmaps are already compressed; deflating them again saves under 0.3%.
859 compression-level: 0
860​
861 - name: Upload resource monitor
862 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
863 with:
864 name: resource-monitor-${{ inputs.resource_key }}
865 path: resource-monitor-publish/${{ inputs.resource_key }}/*
866 if-no-files-found: error
867​
868 verify:
869 name: Verify
870 needs: [build]
871 if: inputs.verify_runner != ''
872 runs-on: ${{ inputs.verify_runner }}
873 timeout-minutes: 15
874 steps:
875 - name: Download verification inputs
876 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
877 with:
878 name: verify-${{ inputs.platform }}-${{ inputs.arch }}
879 path: verify
880​
881 - name: Download CLI archive
882 if: inputs.cli_archive
883 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
884 with:
885 name: cli-${{ inputs.platform }}-${{ inputs.arch }}
886 path: release-cli
887​
888 - name: Verify packaged natives
889 shell: bash
890 run: |
891 set -euo pipefail
892 tar -C verify -xf verify/unpacked.tar
893 node verify/verify-windows-desktop-artifact.mjs \
894 --app-dir "$(cygpath -w "$PWD/verify/$UNPACKED_DIR")" \
895 --arch "${{ inputs.arch }}" --build-version "${{ inputs.version }}" --verbose
896​
897 - name: Smoke-test CLI archive
898 if: inputs.cli_archive
899 shell: bash
900 run: node verify/smoke-cli-archive.mjs --archive release-cli/* --expect-version "${{ inputs.version }}"
901​
902 # cargo-xwin links this binary on Linux, and nothing else runs it before users do.
903 # Node rather than pwsh: PowerShell on Windows ARM crashes intermittently
904 # (https://github.com/dotnet/runtime/issues/131636), which is why this
905 # target stopped building on Windows.
906 - name: Smoke-test resource monitor
907 shell: bash
908 env:
909 MONITOR: verify/${{ env.UNPACKED_DIR }}/resources/resource-monitor/t3-resource-monitor.exe
910 EXPECTED_ARCH: ${{ inputs.arch == 'arm64' && 'aarch64' || 'x86_64' }}
911 run: |
912 node --input-type=module <<'EOF'
913 import { spawn } from "node:child_process";
914 const monitor = spawn(process.env.MONITOR, { stdio: ["pipe", "pipe", "inherit"] });
915 monitor.stdout.setEncoding("utf8");
916 let output = "";
917 const exited = new Promise((resolve) => monitor.on("close", resolve));
918 const hello = await new Promise((resolve, reject) => {
919 monitor.on("error", reject);
920 monitor.on("close", () => reject(new Error(`Resource monitor exited before hello: ${output}`)));
921 monitor.stdout.on("data", (chunk) => {
922 output += chunk;
923 const end = output.indexOf("\n");
924 if (end !== -1) resolve(JSON.parse(output.slice(0, end)));
925 });
926 });
927 if (hello.type !== "hello" || hello.arch !== process.env.EXPECTED_ARCH) {
928 throw new Error(`Unexpected hello: ${JSON.stringify(hello)}`);
929 }
930 const send = (message) => monitor.stdin.write(`${JSON.stringify({ version: hello.version, ...message })}\n`);
931 send({ type: "configure", rootPid: process.pid, sampleIntervalMs: 1000 });
932 send({ type: "sampleNow", requestId: "verify" });
933 monitor.stdin.end();
934 const exitCode = await exited;
935 const sample = output
936 .split("\n")
937 .filter((line) => line.trim())
938 .map((line) => JSON.parse(line))
939 .find((message) => message.requestId === "verify");
940 if (exitCode !== 0 || sample?.type !== "snapshot" || !sample.processes.some((p) => p.pid === process.pid)) {
941 throw new Error(`Resource monitor exited ${exitCode} with: ${output}`);
942 }
943 console.log(`Resource monitor sampled ${sample.scannedProcessCount} processes.`);
944 EOF