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

release-desktop.yml

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