Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(ci): restore node tool cache in pnpm-install (#77740)

Raúl Negrón-Oterob902d73d2038
diff --git a/.depot/actions/pnpm-install/action.yml b/.depot/actions/pnpm-install/action.yml
index 13bd3da720d9..7f8d69cc3648 100644
--- a/.depot/actions/pnpm-install/action.yml
+++ b/.depot/actions/pnpm-install/action.yml
@@ -1,6 +1,8 @@
# Depot mirror of .github/actions/pnpm-install (same pattern as .depot/actions/setup-sqlx-cli).
-# Kept byte-for-byte equivalent to canonical except the node-gyp chmod below, which is hardened
-# for Depot Cache restores. actions/cache routes to Depot Cache, so the shared key does not collide.
+# Kept byte-for-byte equivalent to canonical except: the node-gyp chmod below (hardened for
+# Depot Cache restores) and no `token` input (org secrets are unavailable on Depot, so
+# setup-node stays on github.token). actions/cache routes to Depot Cache, so shared keys do
+# not collide.
name: Install pnpm dependencies
description: |
Sets up pnpm + Node, restores the shared pnpm store cache, installs, and
@@ -10,6 +12,9 @@ description: |
one namespace (`pnpm-<os>-<lockfile-hash>`), so the store is cached once
instead of fragmenting across runner-arch casings or per-workflow keys.
+ Also pre-seeds the Node tool cache (`node-toolcache-<os>-<arch>-<version>`,
+ master-gated save) so setup-node makes no GitHub API calls on a hit.
+
Deliberately does NOT use setup-node's `cache: pnpm`: that auto-saves on
every run (PRs included, and the post-save can't be gated) and keys on
`os.arch()` (lowercase `x64`), which never matches a hand-written
@@ -41,12 +46,47 @@ runs:
# Locate it across pnpm/action-setup layouts and never fail if it is absent.
run: find ~/setup-pnpm -name gyp_main.py -path '*/node-gyp/*' -exec chmod +x {} + 2>/dev/null || true
+ - name: Resolve Node version
+ id: node-version
+ shell: bash
+ # An empty version (missing file or non-exact pin) skips the tool cache
+ # steps, so setup-node falls back to resolving the version itself. Only
+ # exact x.y.z pins are cacheable: the tool-cache directory is named after
+ # the resolved version, so a range spec would never match it.
+ env:
+ NODE_VERSION_FILE: ${{ inputs.node-version-file }}
+ run: |
+ version=""
+ [[ -f "$NODE_VERSION_FILE" ]] && version=$(tr -d 'v[:space:]' < "$NODE_VERSION_FILE")
+ [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || version=""
+ echo "version=$version" >> "$GITHUB_OUTPUT"
+
+ # A tool-cache hit turns setup-node into a filesystem lookup. On a miss it
+ # fetches the version manifest from api.github.com (two rate-limited API
+ # calls per job) and downloads the tarball, on every Node job, because
+ # runner images don't ship the .nvmrc version.
+ - name: Restore Node tool cache
+ id: node-toolcache
+ if: steps.node-version.outputs.version != ''
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/node/${{ steps.node-version.outputs.version }}
+ key: node-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ steps.node-version.outputs.version }}
+
- name: Set up Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: ${{ inputs.node-version-file }}
token: ${{ github.token }}
+ # Save only on the default branch, for the same reasons as the pnpm store save below.
+ - name: Save Node tool cache
+ if: github.ref == 'refs/heads/master' && steps.node-version.outputs.version != '' && steps.node-toolcache.outputs.cache-hit != 'true'
+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/node/${{ steps.node-version.outputs.version }}
+ key: node-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ steps.node-version.outputs.version }}
+
- name: Get pnpm store path
id: pnpm-store
shell: bash
diff --git a/.github/actions/pnpm-install/action.yml b/.github/actions/pnpm-install/action.yml
index 0f2e2090384b..f0542459e96c 100644
--- a/.github/actions/pnpm-install/action.yml
+++ b/.github/actions/pnpm-install/action.yml
@@ -7,6 +7,9 @@ description: |
one namespace (`pnpm-<os>-<lockfile-hash>`), so the store is cached once
instead of fragmenting across runner-arch casings or per-workflow keys.
+ Also pre-seeds the Node tool cache (`node-toolcache-<os>-<arch>-<version>`,
+ master-gated save) so setup-node makes no GitHub API calls on a hit.
+
Deliberately does NOT use setup-node's `cache: pnpm`: that auto-saves on
every run (PRs included, and the post-save can't be gated) and keys on
`os.arch()` (lowercase `x64`), which never matches a hand-written
@@ -43,12 +46,47 @@ runs:
shell: bash
run: find ~/setup-pnpm -name gyp_main.py -exec chmod +x {} +
+ - name: Resolve Node version
+ id: node-version
+ shell: bash
+ # An empty version (missing file or non-exact pin) skips the tool cache
+ # steps, so setup-node falls back to resolving the version itself. Only
+ # exact x.y.z pins are cacheable: the tool-cache directory is named after
+ # the resolved version, so a range spec would never match it.
+ env:
+ NODE_VERSION_FILE: ${{ inputs.node-version-file }}
+ run: |
+ version=""
+ [[ -f "$NODE_VERSION_FILE" ]] && version=$(tr -d 'v[:space:]' < "$NODE_VERSION_FILE")
+ [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || version=""
+ echo "version=$version" >> "$GITHUB_OUTPUT"
+
+ # A tool-cache hit turns setup-node into a filesystem lookup. On a miss it
+ # fetches the version manifest from api.github.com (two rate-limited API
+ # calls per job) and downloads the tarball, on every Node job, because
+ # runner images don't ship the .nvmrc version.
+ - name: Restore Node tool cache
+ id: node-toolcache
+ if: steps.node-version.outputs.version != ''
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/node/${{ steps.node-version.outputs.version }}
+ key: node-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ steps.node-version.outputs.version }}
+
- name: Set up Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: ${{ inputs.node-version-file }}
token: ${{ inputs.token }}
+ # Save only on the default branch, for the same reasons as the pnpm store save below.
+ - name: Save Node tool cache
+ if: github.ref == 'refs/heads/master' && steps.node-version.outputs.version != '' && steps.node-toolcache.outputs.cache-hit != 'true'
+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ runner.tool_cache }}/node/${{ steps.node-version.outputs.version }}
+ key: node-toolcache-${{ runner.os }}-${{ runner.arch }}-${{ steps.node-version.outputs.version }}
+
- name: Get pnpm store path
id: pnpm-store
shell: bash