Skip to content

Commit 95af7fc

Browse files
authored
ci: prune pnpm store before caching and purge PR caches on close (#5340)
The pnpm store cache saved by actions/setup-node's cache: 'pnpm' only ever grows: cache keys are immutable, so every lockfile change saves a brand-new store on top of the previous one and pnpm never drops old package versions from it on its own. Two fixes: - node-setup: run `pnpm store prune` after install, so each saved cache entry only contains what the current lockfile references instead of every version ever fetched. - cleanup-caches.yml: delete a PR's caches when it closes/merges, following GitHub's documented pattern (docs.github.com/actions/.../caching-dependencies-to-speed-up-workflows). PR-branch caches are scoped to a ref that stops being used once the PR is gone, but GitHub never deletes them automatically, so they sit consuming the repo's 10GB quota until LRU eviction forces them out - which stalls the *next* cache save while eviction runs. One-time cleanup: manually purged all 73 existing cache entries (10.72GB, already over quota) via `gh cache delete` so both fixes start from a clean slate.
1 parent 02d88e6 commit 95af7fc

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

.github/actions/node-setup/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ runs:
2121
- name: Install dependencies
2222
shell: bash
2323
run: pnpm install --frozen-lockfile
24+
25+
# Cache keys are immutable, so every lockfile change saves a brand-new
26+
# store on top of the previous one and old package versions never get
27+
# dropped. Pruning here keeps the saved cache scoped to what this
28+
# lockfile actually needs instead of growing unbounded.
29+
- name: Prune pnpm store
30+
shell: bash
31+
run: pnpm store prune
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Cleanup PR caches
2+
3+
# Actions cache entries are scoped to the ref that created them and are never
4+
# deleted automatically when a PR branch goes away, so they keep consuming
5+
# the repo's 10GB quota until GitHub's LRU eviction forces it out - which
6+
# stalls the *next* cache save while eviction runs. Purge a PR's caches as
7+
# soon as it closes so the quota reflects only active branches.
8+
on:
9+
pull_request:
10+
types:
11+
- closed
12+
13+
permissions:
14+
actions: write
15+
contents: read
16+
17+
jobs:
18+
cleanup:
19+
name: Delete caches for closed PR
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Delete caches
23+
env:
24+
GH_TOKEN: ${{ github.token }}
25+
REPO: ${{ github.repository }}
26+
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
27+
run: |
28+
echo "Fetching caches for $BRANCH"
29+
cacheKeys=$(gh cache list --repo "$REPO" --ref "$BRANCH" --limit 100 --json id --jq '.[].id')
30+
31+
if [ -z "$cacheKeys" ]; then
32+
echo "No caches found for $BRANCH"
33+
exit 0
34+
fi
35+
36+
for id in $cacheKeys; do
37+
echo "Deleting cache $id"
38+
gh cache delete "$id" --repo "$REPO" || true
39+
done

0 commit comments

Comments
 (0)