Add workflow to clean up PR branch caches on close#169
Open
Conversation
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add workflow to clean up unnecessary caches after merge
Add workflow to clean up PR branch caches on close
Mar 16, 2026
There was a problem hiding this comment.
Pull request overview
Adds a GitHub Actions workflow to remove GitHub Actions caches associated with a PR’s merge ref when the PR is closed, preventing accumulation of stale PR-scoped caches in the repository.
Changes:
- Introduces a new
pull_request: closedworkflow to list and delete caches underrefs/pull/<number>/merge. - Installs the
actions/gh-actions-cacheGH CLI extension at runtime and iterates cache keys for deletion. - Applies repository-scoped permissions intended to allow cache deletion (
actions: write).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.github/workflows/cleanup-caches.yml
Outdated
Comment on lines
+10
to
+18
| contents: read | ||
|
|
||
| jobs: | ||
| cleanup: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check out code | ||
| uses: actions/checkout@v6 | ||
|
|
Comment on lines
+26
to
+33
| cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1) | ||
| ## Setting this to not fail the workflow while deleting cache keys. | ||
| set +e | ||
| echo "Deleting caches..." | ||
| for cacheKey in $cacheKeysForPR | ||
| do | ||
| gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm | ||
| done |
Member
|
@copilot address any applicable unresolved pr comments. |
…anup workflow Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
Author
Addressed both unresolved comments in f5054a2:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
.github/workflows/cleanup-caches.ymlworkflow that deletes PR-specific caches when a pull request is closedactions/checkoutstep (script only callsgh actions-cache, no workspace needed)contents: readpermission (no longer needed without checkout)set +escope to only the delete loop — restored withset -eafterwards so errors outside the loop are still surfaced✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.