Skip to content

Purge a pull request's Actions caches when it closes #649

Description

@ChrisonSimtian

Problem

Actions caches created for a pull request are never deleted when that pull request closes. They stay until GitHub evicts them after 7 days of no access. On 2026-08-19 this organisation held 5.95 GB of caches, and 4.3 GB of that was unused caches belonging to pull requests that were already merged or closed. Each repository on the Free plan gets 10 GB of cache. Filling it wastes the allowance and produces billing alert emails.

Outcome

When a pull request closes, the caches that belong only to that pull request are deleted automatically. No manual cleanup is needed.

Acceptance criteria

  • A workflow runs on pull_request with types: [closed].
  • It deletes every cache whose ref is refs/pull/<number>/merge for the pull request that just closed.
  • It uses the built-in GITHUB_TOKEN with permissions: actions: write, not a personal access token.
  • The run succeeds when the pull request has no caches.
  • Caches on branch refs such as refs/heads/main and refs/heads/release/* are not touched.

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    CDContinuous delivery: release, publish and deployment-target concerns.enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions