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