-
-
Notifications
You must be signed in to change notification settings - Fork 23.7k
CI: Add workflow to cleanup PR caches when closed #104077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
akien-mga
merged 1 commit into
godotengine:master
from
akien-mga:ci-cache-cleanup-on-pr-close
Mar 13, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries | ||
| name: 🧹 Cache Cleanup | ||
| on: | ||
| pull_request: | ||
| types: | ||
| - closed | ||
|
|
||
| jobs: | ||
| cleanup: | ||
| name: Cleanup PR caches | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Cleanup | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GH_REPO: ${{ github.repository }} | ||
| BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge | ||
| run: | | ||
| echo "Fetching list of cache key" | ||
| cache_keys_for_pr=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id') | ||
| # Setting this to not fail the workflow while deleting cache keys. | ||
| set +e | ||
| echo "Deleting caches..." | ||
| for cache_key in $cache_keys_for_pr; do | ||
| gh cache delete $cache_key | ||
| echo "Deleted: $cache_key" | ||
| done | ||
| echo "Done" | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this deletes only up to 100 caches (that's what the docs example does).
After #104076 we should only have a single cache key pattern per PR, so maybe around 20 caches totally from all our jobs, so it should be fine.
Currently this might not even include all caches in a PR where e.g. a commit was amended 10 times, which would have around 200 unique caches. The rest would be culled after 7 days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So since #104076 isn't going to work, maybe we need to reconsider how many caches we want to query here, as we might have multiple hundreds in a lot of PRs.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100 caches would be a bit over 5 runs of a PR, that's not an unreasonable case, 200 would be pretty sufficient I'd say, that's 10 recent runs
Note also that a significant portion of PRs are merged when they have no caches around, or at most one set likely, the general retention for caches with the pressure we have is about a day, essentially always no older than two days (never seen a cache on the repo that old AFAIK)
So only cases where a PR is amended repeatedly shortly before (within 24 hours) being merged would we need to worry about that I'd say (I occasionally go through and check for old caches that are for merged PRs and there often aren't any/many)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked quickly some recent PRs that had multiple commits today and they all have only 19 caches. So it sounds like previous caches already get dropped somehow, maybe because we're already at such a saturated level that they quickly get garbage collected.
We can reassess after we've reduced our cache congestion further to see if it needs to be increased.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRs that were merged recently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No some that are still open and had multiple commits today, e.g. the Traits PR.