11name : Setup CI dependencies
22description : Install Vite+ and the workspace dependencies from cache.
3+ inputs :
4+ task-cache-read-token :
5+ description : Read-only credential for the private maintainer task cache
6+ required : false
7+ default : " "
8+ install :
9+ description : Set to "false" to set up Vite+ only, with no pnpm store or install
10+ required : false
11+ default : " true"
12+ install-args :
13+ description : Arguments for `vp install`, such as filters. Empty installs the whole workspace.
14+ required : false
15+ default : " "
16+ save-pnpm-store :
17+ description : Set to "false" when a concurrent job with the same install args saves the pnpm store
18+ required : false
19+ default : " true"
320runs :
421 using : composite
522 steps :
@@ -14,10 +31,11 @@ runs:
1431 echo "node=$(jq -r '.engines.node' package.json)" >> "$GITHUB_OUTPUT"
1532 echo "pnpm=$(jq -r '.packageManager' package.json)" >> "$GITHUB_OUTPUT"
1633
34+ # Pinned because release-desktop.yml signs builds with this action in the job.
1735 - name : Cache Vite+
1836 id : vp_cache
1937 if : steps.vp.outputs.version != ''
20- uses : actions/cache@v6
38+ uses : actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
2139 with :
2240 path : ~/.vite-plus
2341 key : vite-plus-home-v2-${{ runner.os }}-${{ runner.arch }}-${{ steps.vp.outputs.version }}-node${{ steps.vp.outputs.node }}-${{ steps.vp.outputs.pnpm }}
@@ -33,35 +51,111 @@ runs:
3351 echo "$HOME/.vite-plus/bin" >> "$GITHUB_PATH"
3452 "$HOME/.vite-plus/bin/vp" env use "${{ steps.vp.outputs.node }}"
3553
54+ # vp gives each Node.js download attempt 10 minutes by default, so one
55+ # stalled stream holds the job that long. It retries 3 times and resumes
56+ # partial bytes, so a shorter limit costs a slow download only a retry.
3657 - name : Setup Vite+
3758 if : steps.vp_cache.outputs.cache-hit != 'true'
38- uses : voidzero-dev/setup-vp@v1
59+ uses : voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb # v1
60+ env :
61+ VP_DOWNLOAD_TIMEOUT : " 120"
3962 with :
4063 node-version-file : package.json
4164 cache : false
4265 run-install : false
4366
44- - name : Resolve pnpm store path
67+ # A shared key lets whichever install saves first, often a small filtered
68+ # one, become every job's store. Each set of install args gets its own.
69+ - name : Resolve pnpm store
4570 id : pnpm_store
71+ if : inputs.install == 'true'
4672 shell : bash
73+ env :
74+ INSTALL_ARGS : ${{ inputs.install-args }}
4775 run : |
48- store_path="$(vp pm cache dir)"
49- echo "path=$store_path" >> "$GITHUB_OUTPUT"
76+ echo "path=$(vp pm cache dir)" >> "$GITHUB_OUTPUT"
77+ metadata_dir="${pnpm_config_cache_dir:-$RUNNER_TEMP/pnpm-metadata}"
78+ echo "pnpm_config_cache_dir=$metadata_dir" >> "$GITHUB_ENV"
79+ echo "verified=$metadata_dir/lockfile-verified.jsonl" >> "$GITHUB_OUTPUT"
80+ if [[ -z "$INSTALL_ARGS" ]]; then
81+ echo "namespace=full" >> "$GITHUB_OUTPUT"
82+ else
83+ echo "namespace=filtered-$(printf '%s' "$INSTALL_ARGS" | cksum | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
84+ fi
5085
51- # setup-vp's shared cache key ignores install filters. Keep full installs in a
52- # separate namespace, including fallback restores .
86+ # Filtered installs prefer the current full store, which holds every package,
87+ # over an older store of their own .
5388 # The pnpm store stays a cache tarball on the runner's own disk. A store on a
5489 # Blacksmith sticky disk mounts in under a second, but pnpm then copies every
5590 # package across filesystems instead of hard-linking it: install took 28-49s
5691 # against 9s plus an 11s restore.
57- - name : Cache full pnpm store
58- uses : actions/cache@v6
92+ - name : Restore pnpm store
93+ id : pnpm_cache
94+ if : inputs.install == 'true'
95+ uses : actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
5996 with :
6097 path : ${{ steps.pnpm_store.outputs.path }}
61- key : pnpm-full -v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}
98+ key : pnpm-${{ steps.pnpm_store.outputs.namespace }} -v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}
6299 restore-keys : |
100+ pnpm-full-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}
101+ pnpm-${{ steps.pnpm_store.outputs.namespace }}-v1-${{ runner.os }}-${{ runner.arch }}-
63102 pnpm-full-v1-${{ runner.os }}-${{ runner.arch }}-
64103
104+ # pnpm accepts an earlier pass for the same lockfile and policy at any age, so
105+ # a cached record skips fetching registry metadata for every package.
106+ - name : Restore lockfile verification
107+ id : pnpm_verified
108+ if : inputs.install == 'true'
109+ uses : actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
110+ with :
111+ path : ${{ steps.pnpm_store.outputs.verified }}
112+ key : pnpm-verified-v1-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}
113+
65114 - name : Install dependencies
115+ if : inputs.install == 'true'
116+ shell : bash
117+ env :
118+ INSTALL_ARGS : ${{ inputs.install-args }}
119+ # Unquoted so each filter is its own argument.
120+ run : vp install $INSTALL_ARGS
121+
122+ - name : Save lockfile verification
123+ if : inputs.install == 'true' && steps.pnpm_verified.outputs.cache-hit != 'true'
124+ uses : actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
125+ with :
126+ path : ${{ steps.pnpm_store.outputs.verified }}
127+ key : ${{ steps.pnpm_verified.outputs.cache-primary-key }}
128+
129+ # A filtered install that started from the current full store adds nothing
130+ # worth a second copy of it. A stacked PR, based on a branch other than the
131+ # default, saves a ~1 GB store only its own reruns can read, so it only restores.
132+ # Concurrent jobs with the same install args reserve one key, so the losers
133+ # compress the store for nothing; all but one pass save-pnpm-store: false.
134+ - name : Save pnpm store
135+ if : >-
136+ inputs.install == 'true' && inputs.save-pnpm-store == 'true' &&
137+ (github.event_name != 'pull_request' || github.base_ref == github.event.repository.default_branch) &&
138+ steps.pnpm_cache.outputs.cache-hit != 'true' &&
139+ (steps.pnpm_store.outputs.namespace == 'full' ||
140+ steps.pnpm_cache.outputs.cache-matched-key != format('pnpm-full-v1-{0}-{1}-{2}', runner.os, runner.arch, hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json')))
141+ uses : actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
142+ with :
143+ path : ${{ steps.pnpm_store.outputs.path }}
144+ key : ${{ steps.pnpm_cache.outputs.cache-primary-key }}
145+
146+ - name : Enable shared task cache
147+ if : >-
148+ github.repository == 'pingdotgg/t3code' &&
149+ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) &&
150+ hashFiles('.task-cache.json') != '' &&
151+ inputs.task-cache-read-token != ''
66152 shell : bash
67- run : vp install
153+ env :
154+ T3_TASK_CACHE_READ_TOKEN : ${{ inputs.task-cache-read-token }}
155+ run : |
156+ node infra/task-cache/scripts/install-ci.ts
157+ if [[ ( "$GITHUB_EVENT_NAME" == pull_request && "$GITHUB_BASE_REF" == main ) || ( "$GITHUB_EVENT_NAME" == push && "$GITHUB_REF" == refs/heads/main ) ]]; then
158+ echo 'VP_REMOTE_CACHE=read-write' >> "$GITHUB_ENV"
159+ else
160+ echo 'VP_REMOTE_CACHE=read' >> "$GITHUB_ENV"
161+ fi
0 commit comments