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(devex): cache the VR CLI install and give it a real budget (#94980)

Julian Bez83201a925704
diff --git a/.github/workflows/ci-e2e-playwright.yml b/.github/workflows/ci-e2e-playwright.yml
index eef50bdce732..19b41a384a92 100644
--- a/.github/workflows/ci-e2e-playwright.yml
+++ b/.github/workflows/ci-e2e-playwright.yml
@@ -966,6 +966,16 @@ jobs:
# Visual Review: create run + upload snapshots directly from the test job.
# Completion happens in handle-screenshots so the baseline lands in the same commit as PNGs.
+ # Shares the entry ci-storybook.yml writes, keyed on the same lockfile. A miss
+ # only means the install downloads the tree, which is what it does today.
+ - name: Restore VR CLI npm cache
+ if: always() && (github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push')
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ~/.npm
+ key: npm-vr-cli-${{ runner.os }}-${{ hashFiles('**/products/visual_review/cli/package-lock.json') }}
+ restore-keys: npm-vr-cli-${{ runner.os }}-
+
- name: Install VR CLI
if: always() && (github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push')
run: cd products/visual_review/cli && npm ci && npm run build && npm link
@@ -1255,6 +1265,14 @@ jobs:
node-version-file: .nvmrc
token: ${{ steps.setup-gh-token.outputs.token || github.token }}
+ # Shares the entry ci-storybook.yml writes, keyed on the same lockfile.
+ - name: Restore VR CLI npm cache
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ~/.npm
+ key: npm-vr-cli-${{ runner.os }}-${{ hashFiles('**/products/visual_review/cli/package-lock.json') }}
+ restore-keys: npm-vr-cli-${{ runner.os }}-
+
- name: Install VR CLI
run: cd products/visual_review/cli && npm ci && npm run build && npm link
diff --git a/.github/workflows/ci-storybook.yml b/.github/workflows/ci-storybook.yml
index adcd731f81cf..bc4d6cd13511 100644
--- a/.github/workflows/ci-storybook.yml
+++ b/.github/workflows/ci-storybook.yml
@@ -308,7 +308,10 @@ jobs:
vr-setup:
name: Create Visual Review run
runs-on: ubuntu-latest
- timeout-minutes: 5
+ # The VR CLI install dominates this job, and it runs against a cold npm cache
+ # whenever the restore misses. vr-complete allows the same budget for the same
+ # install.
+ timeout-minutes: 15
needs: [changes, build-storybook, select-stories]
# A status function is required because select-stories is skipped on forced-full
# PRs and master pushes, and GitHub would otherwise cascade that skip to this job.
@@ -365,9 +368,31 @@ jobs:
node-version-file: .nvmrc
token: ${{ steps.setup-gh-token.outputs.token || github.token }}
+ # The CLI is a standalone npm package outside the pnpm workspace, so no other
+ # job warms its tarballs. Without this cache, every run downloads the whole
+ # dependency tree, which includes the sharp binaries and the test toolchain
+ # that the build never uses.
+ - name: Restore VR CLI npm cache
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ~/.npm
+ key: npm-vr-cli-${{ runner.os }}-${{ hashFiles('**/products/visual_review/cli/package-lock.json') }}
+ restore-keys: npm-vr-cli-${{ runner.os }}-
+
- name: Install VR CLI
run: cd vr-cli/products/visual_review/cli && npm ci && npm run build
+ - name: Save VR CLI npm cache
+ # The only writer for every VR CLI install, here and in
+ # ci-e2e-playwright.yml. They key on the same lockfile, so one entry serves
+ # them all and no two jobs save the same content at once. A job that finds
+ # no entry downloads the dependency tree instead.
+ if: github.ref == 'refs/heads/master'
+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ~/.npm
+ key: npm-vr-cli-${{ runner.os }}-${{ hashFiles('**/products/visual_review/cli/package-lock.json') }}
+
- name: Create VR run
id: create
env:
@@ -577,6 +602,18 @@ jobs:
products/visual_review/frontend/generated/api.schemas.ts
sparse-checkout-cone-mode: false
+ # Every shard installs the CLI, so this is the highest-volume reader of the
+ # entry vr-setup writes. Restore only: a save here would race the other
+ # shards for one key. npm stores its cache by content, so the entry moves
+ # between the runner home and the container home without a rewrite.
+ - name: Restore VR CLI npm cache
+ if: always() && needs.vr-setup.outputs.run_id != ''
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ~/.npm
+ key: npm-vr-cli-${{ runner.os }}-${{ hashFiles('**/products/visual_review/cli/package-lock.json') }}
+ restore-keys: npm-vr-cli-${{ runner.os }}-
+
- name: Install VR CLI
if: always() && needs.vr-setup.outputs.run_id != ''
run: cd vr-cli/products/visual_review/cli && npm ci && npm run build
@@ -828,6 +865,14 @@ jobs:
node-version-file: .nvmrc
token: ${{ steps.setup-gh-token.outputs.token || github.token }}
+ # Reads the cache that vr-setup writes. This job never saves it.
+ - name: Restore VR CLI npm cache
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ~/.npm
+ key: npm-vr-cli-${{ runner.os }}-${{ hashFiles('**/products/visual_review/cli/package-lock.json') }}
+ restore-keys: npm-vr-cli-${{ runner.os }}-
+
- name: Install VR CLI
run: cd vr-cli/products/visual_review/cli && npm ci && npm run build