@@ -163,6 +163,29 @@ jobs:
163163 env :
164164 pnpm_config_cache_dir : ${{ runner.temp }}/pnpm-metadata
165165
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+
166189 - name : Cache resource monitor
167190 id : resource_monitor_cache
168191 uses : actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
@@ -254,21 +277,60 @@ jobs:
254277 if [[ "${{ inputs.version }}" =~ -nightly\.[0-9]{8}\.[0-9]+$ ]]; then brand=nightly; fi
255278 node scripts/apply-web-brand-assets.ts "$brand" apps/server/dist/client
256279
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+
257296 # tsdown downloads the target Node with one fetch and no retry, and
258297 # nodejs.org drops that download often enough to fail releases. Seed
259- # tsdown's cache with a retried, checksum-verified copy instead.
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.
260300 - 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
261324 if : inputs.cli_archive && inputs.platform == 'win'
262325 shell : bash
326+ env :
327+ VERSION : ${{ steps.target_node.outputs.version }}
263328 run : |
264329 set -euo pipefail
265- version="$(node -p 'require("./package.json").engines.node')"
266- name="node-v$version-win-${{ inputs.arch }}"
267- dest="${XDG_CACHE_HOME:-$HOME/.cache}/tsdown/node/v$version/win-${{ inputs.arch }}"
330+ name="node-v$VERSION-win-${{ inputs.arch }}"
268331 dir="$RUNNER_TEMP/node-download"
269- mkdir -p "$dir" "$dest"
270- curl -fsSL --retry 5 --retry-all-errors -o "$dir/$name.zip" "https://nodejs.org/dist/v$version/$name.zip"
271- curl -fsSL --retry 5 --retry-all-errors -o "$dir/SHASUMS256.txt" "https://nodejs.org/dist/v$version/SHASUMS256.txt"
332+ dest="${XDG_CACHE_HOME:-$HOME/.cache}/tsdown/node/v$VERSION/win-${{ inputs.arch }}"
333+ mkdir -p "$dest"
272334 (cd "$dir" && grep " $name.zip\$" SHASUMS256.txt | sha256sum -c -)
273335 unzip -p "$dir/$name.zip" "$name/node.exe" > "$dest/node.exe"
274336
@@ -332,6 +394,9 @@ jobs:
332394 if : inputs.cli_archive
333395 shell : bash
334396 env :
397+ pnpm_config_cache_dir : ${{ steps.stage_pnpm.outputs.dir }}/cache
398+ pnpm_config_store_dir : ${{ steps.stage_pnpm.outputs.dir }}/store
399+ pnpm_config_prefer_offline : " true"
335400 APPLE_API_KEY : ${{ secrets.APPLE_API_KEY }}
336401 APPLE_API_KEY_ID : ${{ secrets.APPLE_API_KEY_ID }}
337402 APPLE_API_ISSUER : ${{ secrets.APPLE_API_ISSUER }}
@@ -451,7 +516,10 @@ jobs:
451516 - name : Build desktop artifact
452517 shell : bash
453518 env :
454- pnpm_config_cache_dir : ${{ runner.temp }}/pnpm-metadata
519+ # pnpm only goes to the registry for packages or versions the cache lacks.
520+ pnpm_config_cache_dir : ${{ steps.stage_pnpm.outputs.dir }}/cache
521+ pnpm_config_store_dir : ${{ steps.stage_pnpm.outputs.dir }}/store
522+ pnpm_config_prefer_offline : " true"
455523 T3CODE_DESKTOP_REUSE_RESOURCE_MONITOR : true
456524 T3CODE_DESKTOP_REUSE_LINUX_CAPTURE_HELPERS : ${{ steps.capture_helper_cache.outputs.cache-hit == 'true' }}
457525 CSC_LINK : ${{ secrets.CSC_LINK }}
@@ -536,6 +604,23 @@ jobs:
536604
537605 vp run dist:desktop:artifact "${args[@]}"
538606
607+ # Warm installs only touch the store index, so new content means a fetch.
608+ - name : Check staged install cache for new content
609+ id : stage_pnpm_changed
610+ shell : bash
611+ run : |
612+ dir="${{ steps.stage_pnpm.outputs.dir }}"
613+ 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 ' ')
614+ echo "Staged installs added $new cached files."
615+ echo "changed=$([[ "$new" -gt 0 ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"
616+
617+ - name : Save staged install cache
618+ if : steps.stage_pnpm_changed.outputs.changed == 'true'
619+ uses : actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
620+ with :
621+ path : ${{ steps.stage_pnpm.outputs.dir }}
622+ key : ${{ steps.stage_pnpm_cache.outputs.cache-primary-key }}
623+
539624 # A build can package fine and still not open (a missing module in the
540625 # backend or the bundle). This launches the app from the shipped
541626 # AppImage or DMG.
0 commit comments