The best way to control Claude Code, Codex and more from any computer or phone

main
yml 161 lines 7.56 KB
Raw
1 name: Setup CI dependencies
2 description: 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"
20 runs:
21 using: composite
22 steps:
23 # ~/.vite-plus holds vp, the Node.js runtime, and pnpm. A cache entry never
24 # updates, so the key names all three versions; otherwise a pnpm or Node.js
25 # bump makes every job download them from npm again.
26 - name: Resolve Vite+ version
27 id: vp
28 shell: bash
29 run: |
30 echo "version=$(sed -nE 's/^ vite-plus: ([0-9][^ ]*)$/\1/p' pnpm-workspace.yaml)" >> "$GITHUB_OUTPUT"
31 echo "node=$(jq -r '.engines.node' package.json)" >> "$GITHUB_OUTPUT"
32 echo "pnpm=$(jq -r '.packageManager' package.json)" >> "$GITHUB_OUTPUT"
33
34 # Pinned because release-desktop.yml signs builds with this action in the job.
35 - name: Cache Vite+
36 id: vp_cache
37 if: steps.vp.outputs.version != ''
38 uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
39 with:
40 path: ~/.vite-plus
41 key: vite-plus-home-v2-${{ runner.os }}-${{ runner.arch }}-${{ steps.vp.outputs.version }}-node${{ steps.vp.outputs.node }}-${{ steps.vp.outputs.pnpm }}
42
43 # setup-vp always runs the installer, which fetches vp from npm even when
44 # this exact version is installed. A cache hit already has everything, so
45 # skip setup-vp and do its remaining work here. This keeps npm outages from
46 # failing jobs.
47 - name: Use cached Vite+
48 if: steps.vp_cache.outputs.cache-hit == 'true'
49 shell: bash
50 run: |
51 echo "$HOME/.vite-plus/bin" >> "$GITHUB_PATH"
52 "$HOME/.vite-plus/bin/vp" env use "${{ steps.vp.outputs.node }}"
53
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.
57 - name: Setup Vite+
58 if: steps.vp_cache.outputs.cache-hit != 'true'
59 uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb # v1.15.0
60 env:
61 VP_DOWNLOAD_TIMEOUT: "120"
62 with:
63 node-version-file: package.json
64 cache: false
65 run-install: false
66
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
70 id: pnpm_store
71 if: inputs.install == 'true'
72 shell: bash
73 env:
74 INSTALL_ARGS: ${{ inputs.install-args }}
75 run: |
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
85
86 # Filtered installs prefer the current full store, which holds every package,
87 # over an older store of their own.
88 # The pnpm store stays a cache tarball on the runner's own disk. A store on a
89 # Blacksmith sticky disk mounts in under a second, but pnpm then copies every
90 # package across filesystems instead of hard-linking it: install took 28-49s
91 # against 9s plus an 11s restore.
92 - name: Restore pnpm store
93 id: pnpm_cache
94 if: inputs.install == 'true'
95 uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
96 with:
97 path: ${{ steps.pnpm_store.outputs.path }}
98 key: pnpm-${{ steps.pnpm_store.outputs.namespace }}-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}
99 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 }}-
102 pnpm-full-v1-${{ runner.os }}-${{ runner.arch }}-
103
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.1.0
110 with:
111 path: ${{ steps.pnpm_store.outputs.verified }}
112 key: pnpm-verified-v1-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}
113
114 - 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.1.0
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.1.0
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 != ''
152 shell: bash
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