-
Notifications
You must be signed in to change notification settings - Fork 366
[CI] Add smarter cache cleanup with size-based filtering #8580
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
Conversation
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'm good with trying this out.
A possibly simpler alternative would be to gate the cleanup on if: failure()
and then delete exactly the cache that was created for this build. This requires passing information between jobs which may be tricky.
.github/workflows/cleanupCache.yml
Outdated
|
||
# Calculate the size threshold as 1/2 of the maximum cache size | ||
MAX_SIZE=$(echo "$MATCHING_CACHES" | jq 'map(.sizeInBytes) | max // 0') | ||
SIZE_THRESHOLD=$((MAX_SIZE / 2)) |
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'm surprised this just works? I thought you would need to use dc
or bc
to do math in a shell script?
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 think posix shell supports (( )) for calculating single arithmetic expression( 2.6.4 https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html)
utils/delete-cache.sh
Outdated
else | ||
echo "Failed to delete cache ID: $id" >&2 | ||
fi | ||
sleep 2 |
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.
What's the sleep for?
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.
There is rate limit for github API so just making sure it doesn't call overwhelming number of API calls. Though it wouldn't be a problem practically.
Implement automated cache cleanup system that removes small caches (likely from failed builds) and maintains only the most recent successful builds. This implementation uses a dynamic size threshold of 1/2 of maximum cache size as the cleanup threshold. It employs regex pattern matching to find caches with `.*PATTERN.*` for flexible matching. The system keeps the top 1 cache to preserve the most recent successful build and is safe by default with dry-run mode enabled to prevent accidental deletions. The changes add a reusable cleanup workflow at .github/workflows/cleanupCache.yml and integrate cache cleanup into unified build workflows. Cache cleanup has been added to short integration tests with cache key pattern generation and reuse implemented. The cache cleanup logic calculates the threshold as 50% of largest cache size, then deletes all caches smaller than the threshold (failed builds) and deletes caches beyond top 1 that exceed the threshold (old builds). It uses regex matching for flexible cache key patterns. The workflows updated include unifiedBuildTestAndInstall.yml, unifiedBuildTestAndInstallStatic.yml, and shortIntegrationTests.yml.
Don't delete cache in main
cf5ed69
to
5cfdbb9
Compare
8f81584
to
0d9aa45
Compare
ab9ff3d
to
6866aa0
Compare
Drop nightly integration test change because docker image doesn't have jq
Updated cache cleanup system so that we can remove small caches (likely from failed builds) and maintain only the most recent successful builds. Previously cache is saved even when the step fails so cache hit rate dramatically decreases after the compilation failure in the early stage (via trivial error or manual cancelation). This commit adds new cleanupCache step (renamed from garbageCollection step since I thought cleanup is better name). This implementation uses a dynamic size threshold of 1/2 of maximum cache size as the cleanup threshold. It employs regex pattern matching to find caches with `.*PATTERN.*` for flexible matching. The system keeps the top 1 cache to preserve the most recent successful build and is safe by default with dry-run mode enabled to prevent accidental deletions. The changes add a reusable cleanup workflow at .github/workflows/cleanupCache.yml and integrate cache cleanup into unified build workflows. Cache cleanup has been added to short integration tests with cache key pattern generation and reuse implemented. The cache cleanup logic calculates the threshold as 50% of largest cache size, then deletes all caches smaller than the threshold (failed builds) and deletes caches beyond top 1 that exceed the threshold (old builds). It uses regex matching for flexible cache key patterns. The workflows updated include unifiedBuildTestAndInstall.yml, unifiedBuildTestAndInstallStatic.yml, and shortIntegrationTests.yml and windowsCI.
Updated cache cleanup system so that we can remove small caches (likely from failed builds) and maintain only the most recent successful builds. Previously cache is saved even when the step failed (hendrikmuhs/ccache-action#149) so cache hit rate dramatically decreases after the compilation failure in the early stage (via trivial error or manual cancelation).
This commit adds new cleanupCache step (renamed from garbageCollection step since I thought cleanup is better name).
This implementation uses a dynamic size threshold of 1/2 of maximum cache size as the cleanup threshold. It employs regex pattern matching to find caches with
.*PATTERN.*
for flexible matching. The system keeps the top 1 cache to preserve the most recent successful build and is safe by default with dry-run mode enabled to prevent accidental deletions.The changes add a reusable cleanup workflow at .github/workflows/cleanupCache.yml and integrate cache cleanup into unified build workflows. Cache cleanup has been added to short integration tests with cache key pattern generation and reuse implemented.
The cache cleanup logic calculates the threshold as 50% of largest cache size, then deletes all caches smaller than the threshold (failed builds) and deletes caches beyond top 1 that exceed the threshold (old builds). It uses regex matching for flexible cache key patterns.
The workflows updated include unifiedBuildTestAndInstall.yml, unifiedBuildTestAndInstallStatic.yml, and shortIntegrationTests.yml and windowsCI.