: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(devex): cache pnpm's lockfile verdict so installs skip registry calls (#124808)
Julian Bez72a87869128d
diff --git a/.depot/actions/pnpm-install/action.yml b/.depot/actions/pnpm-install/action.ymlindex 0876efa5bcaa..c2e92050eb81 100644--- a/.depot/actions/pnpm-install/action.yml+++ b/.depot/actions/pnpm-install/action.yml@@ -61,6 +61,25 @@ runs:key: pnpm-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}restore-keys: pnpm-${{ runner.os }}-+ # pnpm 11 checks the lockfile against the supply-chain policies in pnpm-workspace.yaml+ # on every install, and the check fetches registry metadata even when the store is warm.+ # pnpm records a passed check in lockfile-verified.jsonl, keyed by lockfile path, content+ # and policy, and skips the check when the record matches. No restore-keys: a record for+ # another lockfile cannot match.+ - name: Get pnpm cache path+ id: pnpm-cache+ if: inputs.install != 'false'+ shell: bash+ run: echo "path=$(pnpm cache path --silent)" >> "$GITHUB_OUTPUT"++ - name: Restore pnpm lockfile verdict+ id: restore-verdict+ if: inputs.install != 'false'+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: ${{ steps.pnpm-cache.outputs.path }}/lockfile-verified.jsonl+ key: pnpm-verdict-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}+- name: Install dependenciesif: inputs.install != 'false'shell: bash@@ -81,3 +100,11 @@ runs:with:path: ${{ steps.pnpm-store.outputs.path }}key: pnpm-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}++ # On a verdict miss the install above ran the check itself, so the record is pnpm's own.+ - name: Save pnpm lockfile verdict+ if: inputs.install != 'false' && github.ref == 'refs/heads/master' && steps.restore-verdict.outputs.cache-hit != 'true'+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: ${{ steps.pnpm-cache.outputs.path }}/lockfile-verified.jsonl+ key: pnpm-verdict-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}diff --git a/.github/actions/pnpm-install/action.yml b/.github/actions/pnpm-install/action.ymlindex e4d096d51fe1..2f6a954c4064 100644--- a/.github/actions/pnpm-install/action.yml+++ b/.github/actions/pnpm-install/action.yml@@ -56,6 +56,22 @@ runs:key: pnpm-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}restore-keys: pnpm-${{ runner.os }}-+ # pnpm 11 checks the lockfile against the supply-chain policies in pnpm-workspace.yaml+ # on every install, and the check fetches registry metadata even when the store is warm.+ # pnpm records a passed check in lockfile-verified.jsonl, keyed by lockfile path, content+ # and policy, and skips the check when the record matches. pnpm-store-cache.yml writes+ # this file on master. No restore-keys: a record for another lockfile cannot match.+ - name: Get pnpm cache path+ id: pnpm-cache+ shell: bash+ run: echo "path=$(pnpm cache path --silent)" >> "$GITHUB_OUTPUT"++ - name: Restore pnpm lockfile verdict+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: ${{ steps.pnpm-cache.outputs.path }}/lockfile-verified.jsonl+ key: pnpm-verdict-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}+- name: Install dependenciesshell: bashworking-directory: ${{ inputs.working-directory }}diff --git a/.github/workflows/pnpm-store-cache.yml b/.github/workflows/pnpm-store-cache.ymlindex 8ce5e89ff97d..0b7d4902dac3 100644--- a/.github/workflows/pnpm-store-cache.yml+++ b/.github/workflows/pnpm-store-cache.yml@@ -18,6 +18,9 @@ on:- masterpaths:- pnpm-lock.yaml+ # The lockfile verdict is keyed on these too: the policy and the pnpm version.+ - pnpm-workspace.yaml+ - package.json- .github/workflows/pnpm-store-cache.yml# A PR that edits this file runs the install as a dry run; the save stays master only.pull_request:@@ -70,11 +73,26 @@ jobs:key: pnpm-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}lookup-only: true+ - name: Get pnpm cache path+ id: pnpm-cache+ run: echo "path=$(pnpm cache path --silent)" >> "$GITHUB_OUTPUT"++ # pnpm writes lockfile-verified.jsonl when the install passes the supply-chain check,+ # and pnpm-install restores it so consumers skip the check's registry requests.+ - name: Check for an existing lockfile verdict+ id: verdict-lookup+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: ${{ steps.pnpm-cache.outputs.path }}/lockfile-verified.jsonl+ key: pnpm-verdict-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}+ lookup-only: true+# Build scripts run on purpose: pnpm keeps their output in the store, so# consumers get prebuilt native packages instead of compiling them per job.# A PR dry run always installs, so a broken writer fails here and not on master.+ # A verdict miss also installs, because a store hit alone runs no check to record.- name: Install into an empty store- if: steps.lookup.outputs.cache-hit != 'true' || github.event_name == 'pull_request'+ if: steps.lookup.outputs.cache-hit != 'true' || steps.verdict-lookup.outputs.cache-hit != 'true' || github.event_name == 'pull_request'run: pnpm install --frozen-lockfile# Master only: Depot Cache has no branch isolation, so a dispatch from a@@ -85,3 +103,12 @@ jobs:with:path: ${{ steps.pnpm-store.outputs.path }}key: pnpm-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}++ # Master only, for the same reason as the store. The runner starts with an empty+ # pnpm cache, so the record comes from the check the install above just ran.+ - name: Save lockfile verdict+ if: github.ref == 'refs/heads/master' && steps.verdict-lookup.outputs.cache-hit != 'true'+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: ${{ steps.pnpm-cache.outputs.path }}/lockfile-verified.jsonl+ key: pnpm-verdict-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json') }}