Skip to content

Commit 7769f2f

Browse files
B4nanclaude
andcommitted
fix(pnpm-install): pin lock-hash to a step output so cache-save survives teardown
`actions/cache@v4` re-evaluates `key:` in its post-step (cache-save) at job teardown. On some self-hosted / k8s runners the workspace is wiped before the post-step runs, so `hashFiles('**/pnpm-lock.yaml')` returns no files and fails the entire job — even when every real step has already passed. Capture the hash once in a regular `run:` step (where `hashFiles` is evaluated against the live workspace) and feed the resulting value into the cache `key:` via `steps.pnpm-lock-hash.outputs.HASH`. Step outputs are stored in the runner's `_temp/` state and survive workspace teardown, so the post-step evaluation of `key:` no longer touches the filesystem. Functionally equivalent on healthy runners — same hash, same cache key. Observed in the wild against `apify-core`: cypress shard 6 of run https://github.com/apify/apify-core/actions/runs/25511344092, where all 41 specs passed but the job was failed by `Post Install dependencies` with `hashFiles('**/pnpm-lock.yaml') failed. Fail to hash files under directory '/home/runner/_work/apify-core/apify-core'`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 46dde02 commit 7769f2f

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

pnpm-install/action.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,23 @@ runs:
6767
run: |
6868
echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
6969
70+
# Pre-compute the lockfile hash and store it as a step output. `actions/cache@v4`
71+
# re-evaluates `key:` in its post-step (cache-save) at job teardown, and on some
72+
# self-hosted/k8s runners the workspace is wiped before that runs — calling
73+
# `hashFiles('**/pnpm-lock.yaml')` from the post-step then fails the job after
74+
# all real steps have already passed. Capturing the hash once here pins the
75+
# value to a step output, which survives teardown.
76+
- name: Compute pnpm-lock.yaml hash
77+
id: pnpm-lock-hash
78+
shell: bash
79+
run: |
80+
echo "HASH=${{ hashFiles('**/pnpm-lock.yaml') }}" >> $GITHUB_OUTPUT
81+
7082
- uses: actions/cache@v4
7183
name: Setup pnpm cache
7284
with:
7385
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
74-
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
86+
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ steps.pnpm-lock-hash.outputs.HASH }}
7587
restore-keys: |
7688
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
7789

0 commit comments

Comments
 (0)