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

release-desktop.yml

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