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

release-desktop.yml

852 lines38.2 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: 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 # The archive is already gzip or zip; deflating it again saves under 2%.
453 compression-level: 0
454​
455 - name: Install Linux desktop build libraries
456 if: inputs.platform == 'linux'
457 shell: bash
458 run: |
459 sudo apt-get update
460 sudo apt-get install -y libsecret-1-dev pkg-config
461 if ! command -v magick >/dev/null 2>&1 && ! command -v convert >/dev/null 2>&1; then
462 sudo apt-get install -y imagemagick
463 fi
464​
465 if command -v magick >/dev/null 2>&1; then
466 magick -version
467 else
468 convert -version
469 fi
470​
471 # The WSL backend runs the Linux CLI archive inside the distro, so the
472 # Windows desktop embeds the same-arch archive the release attaches.
473 # This job starts alongside that Linux job instead of after it, and the
474 # Linux job uploads the archive partway through, so the wait is placed
475 # after all other setup. It stops early if the Linux job ended without
476 # uploading the archive.
477 - name: Wait for Linux CLI archive
478 if: inputs.platform == 'win'
479 shell: pwsh
480 timeout-minutes: 40
481 env:
482 GITHUB_TOKEN: ${{ github.token }}
483 ARTIFACT: cli-linux-${{ inputs.arch }}
484 LINUX_JOB: Build Linux ${{ inputs.arch }}
485 run: |
486 $headers = @{ Authorization = "Bearer $env:GITHUB_TOKEN"; Accept = "application/vnd.github+json" }
487 $run = "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID"
488 function Test-Archive {
489 (Invoke-RestMethod -Headers $headers -Uri "$run/artifacts?name=$env:ARTIFACT").total_count -gt 0
490 }
491 $missingSince = $null
492 while ($true) {
493 try {
494 if (Test-Archive) {
495 Write-Host "$env:ARTIFACT is ready."
496 exit 0
497 }
498 $jobs = Invoke-RestMethod -Headers $headers -Uri "$run/attempts/$env:GITHUB_RUN_ATTEMPT/jobs?per_page=100"
499 $linux = $jobs.jobs | Where-Object { $_.name.EndsWith($env:LINUX_JOB) } | Select-Object -First 1
500 if (-not $linux) {
501 # Both jobs start together, so a Linux job still missing after a
502 # few minutes means a renamed or skipped job, not a slow one.
503 if (-not $missingSince) {
504 $missingSince = Get-Date
505 } elseif (((Get-Date) - $missingSince).TotalMinutes -ge 5) {
506 Write-Host "::error::No job named '$env:LINUX_JOB' in this run, so $env:ARTIFACT will not arrive."
507 exit 1
508 }
509 } elseif ($linux.conclusion) {
510 # The upload may have landed between the two requests above.
511 if (Test-Archive) {
512 Write-Host "$env:ARTIFACT is ready."
513 exit 0
514 }
515 Write-Host "::error::$env:LINUX_JOB ended ($($linux.conclusion)) without uploading $env:ARTIFACT."
516 exit 1
517 }
518 } catch {
519 Write-Warning "Could not read this run's artifacts or jobs: $($_.Exception.Message)"
520 }
521 Write-Host "Waiting for $env:ARTIFACT..."
522 Start-Sleep -Seconds 10
523 }
524​
525 - name: Download Linux CLI archive for WSL
526 if: inputs.platform == 'win'
527 uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
528 with:
529 name: cli-linux-${{ inputs.arch }}
530 path: wsl-runtime
531​
532 - name: Build desktop artifact
533 shell: bash
534 env:
535 # pnpm only goes to the registry for packages or versions the cache lacks.
536 pnpm_config_cache_dir: ${{ steps.stage_pnpm.outputs.dir }}/cache
537 pnpm_config_store_dir: ${{ steps.stage_pnpm.outputs.dir }}/store
538 pnpm_config_prefer_offline: "true"
539 T3CODE_DESKTOP_REUSE_RESOURCE_MONITOR: true
540 T3CODE_DESKTOP_REUSE_LINUX_CAPTURE_HELPERS: ${{ steps.capture_helper_cache.outputs.cache-hit == 'true' }}
541 CSC_LINK: ${{ secrets.CSC_LINK }}
542 CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
543 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
544 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
545 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
546 APPLE_TEAM_ID: ${{ vars.APPLE_TEAM_ID }}
547 MACOS_PROVISIONING_PROFILE: ${{ secrets.MACOS_PROVISIONING_PROFILE }}
548 T3CODE_CLERK_PASSKEY_RP_DOMAINS: ${{ vars.CLERK_PASSKEY_RP_DOMAINS }}
549 AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
550 AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
551 AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
552 AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
553 AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
554 AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }}
555 AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }}
556 run: |
557 args=(
558 --platform "${{ inputs.platform }}"
559 --target "${{ inputs.target }}"
560 --arch "${{ inputs.arch }}"
561 --build-version "${{ inputs.version }}"
562 --skip-build
563 --verbose
564 )
565 if [[ -n "${{ inputs.verify_runner }}" ]]; then
566 args+=(--keep-stage)
567 fi
568​
569 has_all() {
570 for value in "$@"; do
571 if [[ -z "$value" ]]; then
572 return 1
573 fi
574 done
575 return 0
576 }
577​
578 if [[ "${{ inputs.platform }}" == "mac" ]]; then
579 if has_all "$CSC_LINK" "$CSC_KEY_PASSWORD" "$APPLE_API_KEY" "$APPLE_API_KEY_ID" "$APPLE_API_ISSUER"; then
580 if ! has_all "$APPLE_TEAM_ID" "$MACOS_PROVISIONING_PROFILE"; then
581 echo "macOS signing is configured, but APPLE_TEAM_ID or MACOS_PROVISIONING_PROFILE is missing." >&2
582 exit 1
583 fi
584​
585 key_path="$RUNNER_TEMP/AuthKey_${APPLE_API_KEY_ID}.p8"
586 printf '%s' "$APPLE_API_KEY" > "$key_path"
587 export APPLE_API_KEY="$key_path"
588​
589 profile_path="$RUNNER_TEMP/t3code.provisionprofile"
590 printf '%s' "$MACOS_PROVISIONING_PROFILE" | base64 -D > "$profile_path"
591 security cms -D -i "$profile_path" >/dev/null
592 export T3CODE_APPLE_TEAM_ID="$APPLE_TEAM_ID"
593 export T3CODE_MACOS_PROVISIONING_PROFILE="$profile_path"
594​
595 echo "macOS signing enabled."
596 args+=(--signed)
597 else
598 echo "macOS signing disabled (missing one or more Apple signing secrets)."
599 fi
600 elif [[ "${{ inputs.platform }}" == "win" ]]; then
601 # Embed the Linux CLI archive built by the same-arch Linux job as
602 # the WSL runtime. Required for a working WSL backend on Windows.
603 args+=(--wsl-runtime "$GITHUB_WORKSPACE"/wsl-runtime/t3-*-linux-${{ inputs.arch }}.tar.gz)
604 if has_all \
605 "$AZURE_TENANT_ID" \
606 "$AZURE_CLIENT_ID" \
607 "$AZURE_CLIENT_SECRET" \
608 "$AZURE_TRUSTED_SIGNING_ENDPOINT" \
609 "$AZURE_TRUSTED_SIGNING_ACCOUNT_NAME" \
610 "$AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME" \
611 "$AZURE_TRUSTED_SIGNING_PUBLISHER_NAME"; then
612 echo "Windows signing enabled (Azure Trusted Signing)."
613 args+=(--signed)
614 else
615 echo "Windows signing disabled (missing one or more Azure Trusted Signing secrets)."
616 fi
617 else
618 echo "Signing disabled for ${{ inputs.platform }}."
619 fi
620​
621 vp run dist:desktop:artifact "${args[@]}"
622​
623 # Warm installs only touch the store index, so new content means a fetch.
624 - name: Check staged install cache for new content
625 id: stage_pnpm_changed
626 shell: bash
627 run: |
628 dir="${{ steps.stage_pnpm.outputs.dir }}"
629 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 ' ')
630 echo "Staged installs added $new cached files."
631 echo "changed=$([[ "$new" -gt 0 ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"
632​
633 - name: Save staged install cache
634 if: steps.stage_pnpm_changed.outputs.changed == 'true'
635 uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
636 with:
637 path: ${{ steps.stage_pnpm.outputs.dir }}
638 key: ${{ steps.stage_pnpm_cache.outputs.cache-primary-key }}
639​
640 # A build can package fine and still not open (a missing module in the
641 # backend or the bundle). This launches the app from the shipped
642 # AppImage or DMG.
643 - name: Launch check
644 if: inputs.launch_check
645 shell: bash
646 run: |
647 set -euo pipefail
648 check=(node scripts/smoke-desktop-app.ts --artifacts-dir "$RUNNER_TEMP/desktop-launch-check")
649 if [[ "${{ inputs.platform }}" == "mac" ]]; then
650 mount="$RUNNER_TEMP/desktop-launch-dmg"
651 hdiutil attach -nobrowse -readonly -mountpoint "$mount" "$(ls "$GITHUB_WORKSPACE"/release/*.dmg)"
652 trap 'hdiutil detach "$mount" -force >/dev/null || true' EXIT
653 app=$(ls -d "$mount"/*.app)
654 executable=$(/usr/libexec/PlistBuddy -c "Print :CFBundleExecutable" "$app/Contents/Info.plist")
655 "${check[@]}" --executable "$app/Contents/MacOS/$executable"
656 else
657 sudo apt-get install -y xvfb
658 appimage=$(ls "$GITHUB_WORKSPACE"/release/*.AppImage)
659 chmod +x "$appimage"
660 (cd "$RUNNER_TEMP" && "$appimage" --appimage-extract >/dev/null)
661 xvfb-run -a "${check[@]}" --executable "$RUNNER_TEMP/squashfs-root/t3code"
662 fi
663​
664 - name: Upload launch check output
665 if: failure() && inputs.launch_check
666 uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
667 with:
668 name: desktop-launch-check-${{ inputs.platform }}-${{ inputs.arch }}
669 path: ${{ runner.temp }}/desktop-launch-check
670 if-no-files-found: ignore
671​
672 # The verify job runs what this host could not: the packaged natives and
673 # the CLI. Its scripts are bundled so that job needs no install.
674 - name: Stage verification inputs
675 if: inputs.verify_runner != ''
676 shell: bash
677 run: |
678 set -euo pipefail
679 mkdir -p verify
680 unpacked=$(ls -d "${TMPDIR:-/tmp}"/t3code-desktop-${{ inputs.platform }}-stage-*/app/dist/"$UNPACKED_DIR")
681 tar -C "$(dirname "$unpacked")" -cf verify/unpacked.tar "$(basename "$unpacked")"
682 esbuild=scripts/node_modules/.bin/esbuild
683 banner="import{createRequire as __cr}from'node:module';const require=__cr(import.meta.url);"
684 # build-desktop-artifact.ts's own import.meta.main guard must not run
685 # its CLI inside the verify bundle.
686 "$esbuild" scripts/verify-windows-desktop-artifact.ts --bundle --platform=node --format=esm \
687 --target=node24 --define:import.meta.main=false --banner:js="$banner" \
688 --outfile=verify/verify-windows-desktop-artifact.mjs
689 "$esbuild" scripts/smoke-cli-archive.ts --bundle --platform=node --format=esm \
690 --target=node24 --banner:js="$banner" --outfile=verify/smoke-cli-archive.mjs
691​
692 - name: Upload verification inputs
693 if: inputs.verify_runner != ''
694 uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
695 with:
696 name: verify-${{ inputs.platform }}-${{ inputs.arch }}
697 path: verify/*
698 if-no-files-found: error
699 retention-days: 1
700 compression-level: 1
701​
702 - name: Collect release assets
703 shell: bash
704 run: |
705 set -euo pipefail
706 mkdir -p release-publish
707​
708 shopt -s nullglob
709 patterns=(
710 "release/*.dmg"
711 "release/*.zip"
712 "release/*.AppImage"
713 "release/*.deb"
714 "release/*.exe"
715 )
716 # Preview builds have no publish config, so electron-builder writes
717 # no feed manifest for them, but it still emits blockmaps beside the
718 # installers. Neither belongs on a release no updater may follow.
719 if [[ "${{ inputs.release_channel }}" != "preview" ]]; then
720 patterns+=("release/*.blockmap" "release/*.yml")
721 fi
722 for pattern in "${patterns[@]}"; do
723 for file in $pattern; do
724 cp "$file" release-publish/
725 done
726 done
727​
728 if [[ "${{ inputs.platform }}" == "mac" && "${{ inputs.arch }}" != "arm64" ]]; then
729 shopt -s nullglob
730 for manifest in release-publish/*-mac.yml; do
731 mv "$manifest" "${manifest%.yml}-${{ inputs.arch }}.yml"
732 done
733 fi
734​
735 # Windows updater metadata is channel-specific (for example
736 # "latest.yml" or "nightly.yml") and carries no arch, so the x64 and
737 # arm64 jobs would upload the same name. Suffix each per-arch copy;
738 # the release job merges them back into one manifest per channel.
739 # builder-debug.yml is electron-builder's config dump, not a feed.
740 if [[ "${{ inputs.platform }}" == "win" ]]; then
741 for manifest in release-publish/*.yml; do
742 [[ "$manifest" == */builder-debug.yml ]] && continue
743 mv "$manifest" "${manifest%.yml}-win-${{ inputs.arch }}.yml"
744 done
745 fi
746​
747 - name: Collect resource monitor
748 shell: bash
749 run: |
750 set -euo pipefail
751 binary_name="t3-resource-monitor"
752 if [[ "${{ inputs.platform }}" == "win" ]]; then
753 binary_name="${binary_name}.exe"
754 fi
755 source_path="native/resource-monitor/target/${{ inputs.rust_target }}/release/${binary_name}"
756 target_dir="resource-monitor-publish/${{ inputs.resource_key }}"
757 mkdir -p "$target_dir"
758 cp "$source_path" "$target_dir/$binary_name"
759​
760 - name: Upload build artifacts
761 uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
762 with:
763 name: desktop-${{ inputs.platform }}-${{ inputs.arch }}
764 path: release-publish/*
765 if-no-files-found: error
766 # Installers, zips and blockmaps are already compressed; deflating them again saves under 0.3%.
767 compression-level: 0
768​
769 - name: Upload resource monitor
770 uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
771 with:
772 name: resource-monitor-${{ inputs.resource_key }}
773 path: resource-monitor-publish/${{ inputs.resource_key }}/*
774 if-no-files-found: error
775​
776 verify:
777 name: Verify
778 needs: [build]
779 if: inputs.verify_runner != ''
780 runs-on: ${{ inputs.verify_runner }}
781 timeout-minutes: 15
782 steps:
783 - name: Download verification inputs
784 uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
785 with:
786 name: verify-${{ inputs.platform }}-${{ inputs.arch }}
787 path: verify
788​
789 - name: Download CLI archive
790 if: inputs.cli_archive
791 uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
792 with:
793 name: cli-${{ inputs.platform }}-${{ inputs.arch }}
794 path: release-cli
795​
796 - name: Verify packaged natives
797 shell: bash
798 run: |
799 set -euo pipefail
800 tar -C verify -xf verify/unpacked.tar
801 node verify/verify-windows-desktop-artifact.mjs \
802 --app-dir "$(cygpath -w "$PWD/verify/$UNPACKED_DIR")" \
803 --arch "${{ inputs.arch }}" --build-version "${{ inputs.version }}" --verbose
804​
805 - name: Smoke-test CLI archive
806 if: inputs.cli_archive
807 shell: bash
808 run: node verify/smoke-cli-archive.mjs --archive release-cli/* --expect-version "${{ inputs.version }}"
809​
810 # cargo-xwin links this binary on Linux, and nothing else runs it before users do.
811 # Node rather than pwsh: PowerShell on Windows ARM crashes intermittently
812 # (https://github.com/dotnet/runtime/issues/131636), which is why this
813 # target stopped building on Windows.
814 - name: Smoke-test resource monitor
815 shell: bash
816 env:
817 MONITOR: verify/${{ env.UNPACKED_DIR }}/resources/resource-monitor/t3-resource-monitor.exe
818 EXPECTED_ARCH: ${{ inputs.arch == 'arm64' && 'aarch64' || 'x86_64' }}
819 run: |
820 node --input-type=module <<'EOF'
821 import { spawn } from "node:child_process";
822 const monitor = spawn(process.env.MONITOR, { stdio: ["pipe", "pipe", "inherit"] });
823 monitor.stdout.setEncoding("utf8");
824 let output = "";
825 const exited = new Promise((resolve) => monitor.on("close", resolve));
826 const hello = await new Promise((resolve, reject) => {
827 monitor.on("error", reject);
828 monitor.on("close", () => reject(new Error(`Resource monitor exited before hello: ${output}`)));
829 monitor.stdout.on("data", (chunk) => {
830 output += chunk;
831 const end = output.indexOf("\n");
832 if (end !== -1) resolve(JSON.parse(output.slice(0, end)));
833 });
834 });
835 if (hello.type !== "hello" || hello.arch !== process.env.EXPECTED_ARCH) {
836 throw new Error(`Unexpected hello: ${JSON.stringify(hello)}`);
837 }
838 const send = (message) => monitor.stdin.write(`${JSON.stringify({ version: hello.version, ...message })}\n`);
839 send({ type: "configure", rootPid: process.pid, sampleIntervalMs: 1000 });
840 send({ type: "sampleNow", requestId: "verify" });
841 monitor.stdin.end();
842 const exitCode = await exited;
843 const sample = output
844 .split("\n")
845 .filter((line) => line.trim())
846 .map((line) => JSON.parse(line))
847 .find((message) => message.requestId === "verify");
848 if (exitCode !== 0 || sample?.type !== "snapshot" || !sample.processes.some((p) => p.pid === process.pid)) {
849 throw new Error(`Resource monitor exited ${exitCode} with: ${output}`);
850 }
851 console.log(`Resource monitor sampled ${sample.scannedProcessCount} processes.`);
852 EOF