Why do we need this improvement?
GitHub Actions caches accumulate per branch and per pull request. On every PR run, caches are written scoped to refs/pull/<n>/merge (via setup-node caches in the centrally managed workflows, and any additional test/build caches). When a PR is merged or closed, those caches are not removed automatically — they keep counting against the repository's 10 GB cache quota until GitHub's 7-day LRU eviction kicks in.
Under the quota, the LRU policy can evict live caches for master and for currently open PRs before it reaches the stale per-PR entries. The result is unnecessary cache misses on the branches that matter most, which increases CI time for everyone.
How will this change help?
A small maintenance workflow triggered on pull_request (type: closed) would list the caches scoped to the closing PR's ref and delete them via the GitHub REST API. Net effect:
- Cache quota freed sooner → fewer cold builds on
master and on open PRs.
- No behavioral change to existing CI jobs — the new workflow runs only after a PR has closed.
- No changes to any existing workflow file, so no conflict with the
# This action is centrally managed in https://github.com/asyncapi/.github/ header carried by every current workflow in this repo.
Screenshots
No response
How could it be implemented/designed?
Add a new file .github/workflows/cleanup-pr-caches.yml:
name: Cleanup caches for closed PRs
on:
pull_request:
types: [closed]
permissions:
actions: write
contents: read
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const ref = `refs/pull/${context.payload.pull_request.number}/merge`;
const { data } = await github.rest.actions.getActionsCacheList({
owner: context.repo.owner,
repo: context.repo.repo,
ref,
});
for (const cache of data.actions_caches) {
await github.rest.actions.deleteActionsCacheById({
owner: context.repo.owner,
repo: context.repo.repo,
cache_id: cache.id,
});
}
Notes:
- New file, so it is not in scope of the central
asyncapi/.github sync that overwrites existing workflows here.
- Scoped permissions (
actions: write, contents: read) — no write access to repo contents.
- If the org prefers pinning actions to immutable SHAs,
actions/github-script@v7 can be pinned accordingly.
🚧 Breaking changes
No
👀 Have you checked for similar open issues?
🏢 Have you read the Contributing Guidelines?
Are you willing to work on this issue?
Yes I am willing to submit a PR!
Why do we need this improvement?
GitHub Actions caches accumulate per branch and per pull request. On every PR run, caches are written scoped to
refs/pull/<n>/merge(viasetup-nodecaches in the centrally managed workflows, and any additional test/build caches). When a PR is merged or closed, those caches are not removed automatically — they keep counting against the repository's 10 GB cache quota until GitHub's 7-day LRU eviction kicks in.Under the quota, the LRU policy can evict live caches for
masterand for currently open PRs before it reaches the stale per-PR entries. The result is unnecessary cache misses on the branches that matter most, which increases CI time for everyone.How will this change help?
A small maintenance workflow triggered on
pull_request(type:closed) would list the caches scoped to the closing PR's ref and delete them via the GitHub REST API. Net effect:masterand on open PRs.# This action is centrally managed in https://github.com/asyncapi/.github/header carried by every current workflow in this repo.Screenshots
No response
How could it be implemented/designed?
Add a new file
.github/workflows/cleanup-pr-caches.yml:Notes:
asyncapi/.githubsync that overwrites existing workflows here.actions: write,contents: read) — no write access to repo contents.actions/github-script@v7can be pinned accordingly.🚧 Breaking changes
No
👀 Have you checked for similar open issues?
🏢 Have you read the Contributing Guidelines?
Are you willing to work on this issue?
Yes I am willing to submit a PR!