|
1 | 1 | name: Setup CI dependencies |
2 | 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: "" |
3 | 16 | runs: |
4 | 17 | using: composite |
5 | 18 | steps: |
6 | | - # setup-vp reuses an installed exact version, so restoring its home skips the |
7 | | - # installer download on every job. |
| 19 | + # ~/.vite-plus holds vp, the Node.js runtime, and pnpm. A cache entry never |
| 20 | + # updates, so the key names all three versions; otherwise a pnpm or Node.js |
| 21 | + # bump makes every job download them from npm again. |
8 | 22 | - name: Resolve Vite+ version |
9 | 23 | id: vp |
10 | 24 | shell: bash |
11 | 25 | run: | |
12 | 26 | echo "version=$(sed -nE 's/^ vite-plus: ([0-9][^ ]*)$/\1/p' pnpm-workspace.yaml)" >> "$GITHUB_OUTPUT" |
| 27 | + echo "node=$(jq -r '.engines.node' package.json)" >> "$GITHUB_OUTPUT" |
| 28 | + echo "pnpm=$(jq -r '.packageManager' package.json)" >> "$GITHUB_OUTPUT" |
13 | 29 |
|
| 30 | + # Pinned because release-desktop.yml signs builds with this action in the job. |
14 | 31 | - name: Cache Vite+ |
| 32 | + id: vp_cache |
15 | 33 | if: steps.vp.outputs.version != '' |
16 | | - uses: actions/cache@v6 |
| 34 | + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 |
17 | 35 | with: |
18 | 36 | path: ~/.vite-plus |
19 | | - key: vite-plus-home-v1-${{ runner.os }}-${{ runner.arch }}-${{ steps.vp.outputs.version }} |
| 37 | + key: vite-plus-home-v2-${{ runner.os }}-${{ runner.arch }}-${{ steps.vp.outputs.version }}-node${{ steps.vp.outputs.node }}-${{ steps.vp.outputs.pnpm }} |
20 | 38 |
|
| 39 | + # setup-vp always runs the installer, which fetches vp from npm even when |
| 40 | + # this exact version is installed. A cache hit already has everything, so |
| 41 | + # skip setup-vp and do its remaining work here. This keeps npm outages from |
| 42 | + # failing jobs. |
| 43 | + - name: Use cached Vite+ |
| 44 | + if: steps.vp_cache.outputs.cache-hit == 'true' |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + echo "$HOME/.vite-plus/bin" >> "$GITHUB_PATH" |
| 48 | + "$HOME/.vite-plus/bin/vp" env use "${{ steps.vp.outputs.node }}" |
| 49 | +
|
| 50 | + # vp gives each Node.js download attempt 10 minutes by default, so one |
| 51 | + # stalled stream holds the job that long. It retries 3 times and resumes |
| 52 | + # partial bytes, so a shorter limit costs a slow download only a retry. |
21 | 53 | - name: Setup Vite+ |
22 | | - uses: voidzero-dev/setup-vp@v1 |
| 54 | + if: steps.vp_cache.outputs.cache-hit != 'true' |
| 55 | + uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb # v1 |
| 56 | + env: |
| 57 | + VP_DOWNLOAD_TIMEOUT: "120" |
23 | 58 | with: |
24 | 59 | node-version-file: package.json |
25 | 60 | cache: false |
26 | 61 | run-install: false |
27 | 62 |
|
28 | | - - name: Resolve pnpm store path |
| 63 | + # A shared key lets whichever install saves first, often a small filtered |
| 64 | + # one, become every job's store. Each set of install args gets its own. |
| 65 | + - name: Resolve pnpm store |
29 | 66 | id: pnpm_store |
| 67 | + if: inputs.install == 'true' |
30 | 68 | shell: bash |
| 69 | + env: |
| 70 | + INSTALL_ARGS: ${{ inputs.install-args }} |
31 | 71 | run: | |
32 | | - store_path="$(vp pm cache dir)" |
33 | | - echo "path=$store_path" >> "$GITHUB_OUTPUT" |
| 72 | + echo "path=$(vp pm cache dir)" >> "$GITHUB_OUTPUT" |
| 73 | + metadata_dir="${pnpm_config_cache_dir:-$RUNNER_TEMP/pnpm-metadata}" |
| 74 | + echo "pnpm_config_cache_dir=$metadata_dir" >> "$GITHUB_ENV" |
| 75 | + echo "verified=$metadata_dir/lockfile-verified.jsonl" >> "$GITHUB_OUTPUT" |
| 76 | + if [[ -z "$INSTALL_ARGS" ]]; then |
| 77 | + echo "namespace=full" >> "$GITHUB_OUTPUT" |
| 78 | + else |
| 79 | + echo "namespace=filtered-$(printf '%s' "$INSTALL_ARGS" | cksum | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" |
| 80 | + fi |
34 | 81 |
|
35 | | - # setup-vp's shared cache key ignores install filters. Keep full installs in a |
36 | | - # separate namespace, including fallback restores. |
| 82 | + # Filtered installs prefer the current full store, which holds every package, |
| 83 | + # over an older store of their own. |
37 | 84 | # The pnpm store stays a cache tarball on the runner's own disk. A store on a |
38 | 85 | # Blacksmith sticky disk mounts in under a second, but pnpm then copies every |
39 | 86 | # package across filesystems instead of hard-linking it: install took 28-49s |
40 | 87 | # against 9s plus an 11s restore. |
41 | | - - name: Cache full pnpm store |
42 | | - uses: actions/cache@v6 |
| 88 | + - name: Restore pnpm store |
| 89 | + id: pnpm_cache |
| 90 | + if: inputs.install == 'true' |
| 91 | + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 |
43 | 92 | with: |
44 | 93 | path: ${{ steps.pnpm_store.outputs.path }} |
45 | | - key: pnpm-full-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }} |
| 94 | + key: pnpm-${{ steps.pnpm_store.outputs.namespace }}-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }} |
46 | 95 | restore-keys: | |
| 96 | + pnpm-full-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }} |
| 97 | + pnpm-${{ steps.pnpm_store.outputs.namespace }}-v1-${{ runner.os }}-${{ runner.arch }}- |
47 | 98 | pnpm-full-v1-${{ runner.os }}-${{ runner.arch }}- |
48 | 99 |
|
| 100 | + # pnpm accepts an earlier pass for the same lockfile and policy at any age, so |
| 101 | + # a cached record skips fetching registry metadata for every package. |
| 102 | + - name: Restore lockfile verification |
| 103 | + id: pnpm_verified |
| 104 | + if: inputs.install == 'true' |
| 105 | + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 |
| 106 | + with: |
| 107 | + path: ${{ steps.pnpm_store.outputs.verified }} |
| 108 | + key: pnpm-verified-v1-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }} |
| 109 | + |
49 | 110 | - name: Install dependencies |
| 111 | + if: inputs.install == 'true' |
50 | 112 | shell: bash |
51 | | - run: vp install |
| 113 | + env: |
| 114 | + INSTALL_ARGS: ${{ inputs.install-args }} |
| 115 | + # Unquoted so each filter is its own argument. |
| 116 | + run: vp install $INSTALL_ARGS |
| 117 | + |
| 118 | + - name: Save lockfile verification |
| 119 | + if: inputs.install == 'true' && steps.pnpm_verified.outputs.cache-hit != 'true' |
| 120 | + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 |
| 121 | + with: |
| 122 | + path: ${{ steps.pnpm_store.outputs.verified }} |
| 123 | + key: ${{ steps.pnpm_verified.outputs.cache-primary-key }} |
| 124 | + |
| 125 | + # A filtered install that started from the current full store adds nothing |
| 126 | + # worth a second copy of it. |
| 127 | + - name: Save pnpm store |
| 128 | + if: >- |
| 129 | + inputs.install == 'true' && |
| 130 | + steps.pnpm_cache.outputs.cache-hit != 'true' && |
| 131 | + (steps.pnpm_store.outputs.namespace == 'full' || |
| 132 | + 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'))) |
| 133 | + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 |
| 134 | + with: |
| 135 | + path: ${{ steps.pnpm_store.outputs.path }} |
| 136 | + key: ${{ steps.pnpm_cache.outputs.cache-primary-key }} |
| 137 | + |
| 138 | + - name: Enable shared task cache |
| 139 | + if: >- |
| 140 | + github.repository == 'pingdotgg/t3code' && |
| 141 | + (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && |
| 142 | + hashFiles('.task-cache.json') != '' && |
| 143 | + inputs.task-cache-read-token != '' |
| 144 | + shell: bash |
| 145 | + env: |
| 146 | + T3_TASK_CACHE_READ_TOKEN: ${{ inputs.task-cache-read-token }} |
| 147 | + run: | |
| 148 | + node infra/task-cache/scripts/install-ci.ts |
| 149 | + if [[ ( "$GITHUB_EVENT_NAME" == pull_request && "$GITHUB_BASE_REF" == main ) || ( "$GITHUB_EVENT_NAME" == push && "$GITHUB_REF" == refs/heads/main ) ]]; then |
| 150 | + echo 'VP_REMOTE_CACHE=read-write' >> "$GITHUB_ENV" |
| 151 | + else |
| 152 | + echo 'VP_REMOTE_CACHE=read' >> "$GITHUB_ENV" |
| 153 | + fi |
0 commit comments