Add weekly GitHub Actions cache cleanup - #325
Conversation
|
@coderabbitai autofix |
|
Claude finished @ANcpLua's task in 1m 24s —— View job Review — Add weekly GitHub Actions cache cleanup
Overall this is a clean, well-scoped workflow — minimized permissions (
1. Filter is broader than the PR description claims —
|
There was a problem hiding this comment.
Pull request overview
Risk: Medium — scheduled workflow with actions: write can delete more caches than intended if the ref filter is too broad.
This PR adds a scheduled + manually-triggerable GitHub Actions workflow to prune stale Actions caches associated with pull request refs, aiming to keep cache storage usage under control without affecting main caches.
Changes:
- Add a weekly scheduled workflow plus
workflow_dispatchinputs for retention window (minimum_age_days) anddry_run. - Implement an embedded Python script that enumerates Actions caches via the GitHub API, filters by ref + last-accessed time, and optionally deletes them.
Blockers
- The current ref filter matches all
refs/pull/*caches, but the PR description/header comment state it should delete onlyrefs/pull/*/mergecaches. This can lead to unintended deletions.
Important issues
- The script can crash if
last_accessed_atis missing/invalid becausedatetime.fromisoformat(...)will raise, aborting the whole cleanup run. - Workflow permissions include
contents: readeven though the job doesn’t read repository contents; tightening permissions would reduce blast radius.
Minor / optional
- None noted.
| ref = str(cache.get("ref", "")) | ||
| last_accessed = str(cache.get("last_accessed_at", "")) | ||
| if not ref.startswith("refs/pull/"): | ||
| continue |
| if not ref.startswith("refs/pull/"): | ||
| continue | ||
|
|
||
| accessed_at = datetime.fromisoformat(last_accessed.replace("Z", "+00:00")) |
|
|
||
| permissions: | ||
| actions: write | ||
| contents: read |
|
@coderabbitai autofix |
|
Claude finished @ANcpLua's task in 1m 42s —— View job Review — Add weekly GitHub Actions cache cleanup
I drafted the fix and tried to push it to this branch, but the remote rejected it: this GitHub App doesn't carry the The three findings the earlier reviewers raised (filter scope, 1. Filter doesn't match what the header comment + PR body promise —
|
The destructive tier runs on a runner without actions/checkout, so the
working dir has no .git. gh pr {review,merge,view} without --repo tries
to derive the repository from the local git context and dies with
"fatal: not a git repository". Add --repo "$GITHUB_REPOSITORY" to every
gh call in the workflow so they bind to the calling repository via env
instead of git-context detection.
Observed on the first destructive run against PR #325 — both attempts
failed at the admin-merge step with that exact error.
Three findings from the copilot-pull-request-reviewer pass on PR #325, all valid: 1. Filter mismatch (blocker, line 122): the previous predicate `ref.startswith("refs/pull/")` matched both refs/pull/<N>/head and refs/pull/<N>/merge, but the PR description and the workflow header comment say only the merge-test refs should be deleted. The head refs back the active build for the open PR's head SHA and are still useful while the PR is open. Tighten to require the `/merge` suffix; head caches are now preserved. 2. fromisoformat fragility (important, line 125): if last_accessed_at is missing/empty or malformed, datetime.fromisoformat raises and aborts the whole cleanup run. Skip those entries with a clear ::warning:: instead so one bad cache record cannot break the job. Also handle the empty-string case explicitly (str(None) -> "None" but cache.get(..., "") -> "" is the actual path). 3. Least-privilege permissions (important, line 30): the job only talks to the actions/caches API; it does not check out the repo or read repository contents. Drop `contents: read` so the workflow token grants only `actions: write`.
ghost
left a comment
There was a problem hiding this comment.
✅ Auto-approved by destructive auto-merge (admin tier)
|
@coderabbitai autofix |
|
Claude finished @ANcpLua's task in 52s —— View job Review — Add weekly GitHub Actions cache cleanup
All three substantive findings from the earlier review rounds (Copilot + my prior pass) already landed in commit
Nothing else worth flagging:
Why no commit on this branchPR is already merged, and this GitHub App can't write to |
ghost
left a comment
There was a problem hiding this comment.
✅ Auto-approved by destructive auto-merge (admin tier)
| minimum_age_days: | ||
| description: "Delete pull-ref caches last accessed at least this many days ago" | ||
| required: false | ||
| default: "3" |
| dry_run: | ||
| description: "Report matching caches without deleting them" | ||
| required: false | ||
| default: "false" | ||
| type: choice | ||
| options: | ||
| - "false" | ||
| - "true" |
| jobs: | ||
| cleanup: | ||
| name: Delete stale pull-request caches | ||
| runs-on: ubuntu-latest |
Summary
refs/pull/*/mergecache entriesrefs/heads/maincaches untouchedVerification
ruby -e 'require "yaml"; YAML.load_file(ARGV.fetch(0)); puts "yaml ok"' .github/workflows/actions-cache-cleanup.ymlDRY_RUN=trueactionlint .github/workflows/actions-cache-cleanup.ymlgit diff --checkNeed help on this PR? Tag
@codesmithwith what you need.