Skip to content

Create script to clear older caches#18751

Merged
seanbudd merged 5 commits intomasterfrom
clearCaches
Aug 19, 2025
Merged

Create script to clear older caches#18751
seanbudd merged 5 commits intomasterfrom
clearCaches

Conversation

@seanbudd
Copy link
Copy Markdown
Member

@seanbudd seanbudd commented Aug 19, 2025

Link to issue number:

Part of #17878

Summary of the issue:

PRs have been failing recently as we are well over our cache limit.
GitHub actions doesn't allow us to easily delete the caches of PR builds from within PRs, due to it being a cache poisoning risk.
Instead, we should clear caches manually on a regular basis.

Description of user facing changes:

None

Description of developer facing changes:

PRs more reliable

Description of development approach:

  • Use gh cli to fetch cache items
  • filter with jq for cache items last accessed older than 6 hours ago
  • delete filtered cache items

Testing strategy:

Tested locally from CLI

Known issues with pull request:

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@coderabbitai summary

@seanbudd seanbudd marked this pull request as ready for review August 19, 2025 03:08
Copilot AI review requested due to automatic review settings August 19, 2025 03:08
@seanbudd seanbudd requested a review from a team as a code owner August 19, 2025 03:08
@seanbudd seanbudd requested a review from SaschaCowley August 19, 2025 03:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces an automated cache cleanup workflow to address GitHub Actions cache limit issues that have been causing PR failures. The workflow runs every 3 hours to delete caches older than 6 hours (configurable).

  • Adds a scheduled GitHub Actions workflow for automatic cache cleanup
  • Implements configurable cache expiration time with a 6-hour default
  • Uses GitHub CLI and jq to filter and delete old cache entries

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
# Filter for caches last accessed older than the expiration time
jqStr: 'map(select((.lastAccessedAt | sub("\\.\\d+Z$"; "Z") | fromdateiso8601) < (now - ${{ env.CACHE_EXPIRATION_HOUR }} * 3600))) | .[].key'
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

[nitpick] The jq filter expression is complex and hard to read when embedded in the environment variable. Consider moving the jq expression inline or breaking it into multiple steps for better readability and maintainability.

Suggested change
jqStr: 'map(select((.lastAccessedAt | sub("\\.\\d+Z$"; "Z") | fromdateiso8601) < (now - ${{ env.CACHE_EXPIRATION_HOUR }} * 3600))) | .[].key'
# Filter for caches last accessed older than the expiration time
EXPIRATION_SEC=$(( ${{ env.CACHE_EXPIRATION_HOUR }} * 3600 ))
gh cache list --json key,lastAccessedAt \
| jq -r 'map(select((.lastAccessedAt | sub("\\.\\d+Z$"; "Z") | fromdateiso8601) < (now - '"$EXPIRATION_SEC"'))) | .[].key' \
| while read -r cache; do
gh cache delete "$cache"
done
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}

Copilot uses AI. Check for mistakes.
seanbudd and others added 2 commits August 19, 2025 13:13
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@seanbudd
Copy link
Copy Markdown
Member Author

Force merging this for now to fix builds, will action review comments post-merge

@seanbudd seanbudd changed the base branch from master to beta August 19, 2025 04:27
@seanbudd seanbudd changed the base branch from beta to master August 19, 2025 04:27
@seanbudd seanbudd merged commit 4a2e1a0 into master Aug 19, 2025
21 of 22 checks passed
@seanbudd seanbudd deleted the clearCaches branch August 19, 2025 04:27
@github-actions github-actions bot added this to the 2026.1 milestone Aug 19, 2025
@seanbudd seanbudd mentioned this pull request Aug 19, 2025
seanbudd added a commit that referenced this pull request Aug 19, 2025
Fixup of #18751

Uses IDs rather than keys to more consistently delete caches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants