Skip to content

[CI] Delete the Actions caches of closed pull requests - #406

Merged
Ewerton Scaboro da Silva (ewertons) merged 2 commits into
mainfrom
chore/cleanup-pr-caches
Oct 10, 2026
Merged

Ewerton Scaboro da Silva (ewertons) merged 2 commits into
mainfrom
chore/cleanup-pr-caches

Conversation

@ewertons

Copy link
Copy Markdown
Contributor

A closed pull request's caches (refs/pull/<n>/merge) serve nothing but count against the 10 GB cache quota until unused for 7 days. ci-c-yocto saves ~450 MB of sstate per run that built something, so they can evict main's entry, which every pull request restores.

New workflow cleanup-pr-caches:

  • On close (pull_request: closed): deletes that pull request's caches. Same-repository pull requests only; a fork's token is read-only.
  • Nightly and manual sweep: deletes the caches of every closed pull request. Covers forks, entries saved by a run still going at close, and older pull requests. Manual runs have a dry-run input.

pull_request_target is not used: zizmor rates it high (dangerous-triggers), and the sweep covers forks.

Verified locally

  • actionlint 1.7.12 and zizmor 1.30.1, as in lint-workflows: no findings.
  • Sweep script against this repository, dry-run: no pull request caches exist today, nothing listed.
  • Sweep script with a stubbed cache list (one merged, one open pull request): deletes only the merged one; dry-run deletes nothing.
  • gh cache delete --all --ref <ref> --succeed-on-no-caches on a ref without caches exits 0.

Not verified: a real deletion. The on-close job first runs when this pull request closes.

A closed pull request's caches serve nothing but count against the
10 GB quota until unused for 7 days. ci-c-yocto saves ~450 MB of sstate
per run that built something, so they could evict main's entry.

- On close: delete that pull request's caches (same-repository only;
  a fork's token is read-only).
- Nightly and manual sweep: delete the caches of every closed pull
  request. Covers forks, entries saved after close, and older pull
  requests. Manual runs can dry-run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The on-close job fails whenever the pull request has no caches.

1 open finding
What changed in this PR

Adds automated cleanup of GitHub Actions caches belonging to closed pull requests.

Changes:

  • Deletes same-repository PR caches upon closure.
  • Adds nightly/manual sweeps with dry-run support.
File Description
.github/​workflows/​cleanup-pr-caches.yml Defines cache cleanup triggers and jobs.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/workflows/cleanup-pr-caches.yml Outdated
gh cache list --json returns an empty array with exit status 0 when a
ref has no caches, whatever the gh version.
Copilot AI balanced review requested due to automatic review settings October 10, 2026 07:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The workflow safely scopes permissions, handles fork limitations, and supports no-op and dry-run cases.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed/Approved

@ewertons
Ewerton Scaboro da Silva (ewertons) merged commit 4ed012c into main Oct 10, 2026
34 checks passed
@ewertons
Ewerton Scaboro da Silva (ewertons) deleted the chore/cleanup-pr-caches branch October 10, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants