boa icon indicating copy to clipboard operation
boa copied to clipboard

CI: add workflow to cleanup PR caches on close

Open RishavTiwari25 opened this issue 8 months ago • 5 comments

I think we should improve the way we manage our GitHub Actions cache limits by adding an automated workflow that deletes runner caches scoped to a pull request when it is closed or merged.

Currently, our CI uses GitHub Actions caching extensively (saving cargo registries, index, and build artifacts) to speed up our tests. However, we do not have an automated way to clean up orphaned caches once a PR is closed or merged. Without cleanup, these orphaned caches can accumulate and quickly consume the repository's 10 GB cache storage limit, causing cache eviction churn and slowing down active PRs.

We could implement this by adding a small .github/workflows/cleanup-caches.yml workflow that triggers on pull_request: [closed] and uses the gh actions-cache delete CLI extension or a community action to clear up space when it's no longer needed.

RishavTiwari25 avatar Mar 17 '26 20:03 RishavTiwari25

We do not clean up caches because all PRs share the same cache, right? Then cleaning up every cache from PRs will evict everything that also matches main, making builds slower overall

jedel1043 avatar Mar 18 '26 00:03 jedel1043

Good question! We actually don't have to worry about evicting main's caches making builds slower.

According to GitHub Actions' scoping design, a PR can restore a cache from main, but any new/updated caches generated during the PR run are strictly scoped and saved only to that specific PR's branch.

Because our workflow explicitly passes the -B (branch) flag to the CLI (-B "refs/pull/${{ github.event.pull_request.number }}/merge"), it exclusively deletes the isolated duplicate caches generated for that individual PR. It leaves main completely untouched, ensuring active PRs stay perfectly fast while freeing up chunks of our 10 GB repository limit.

RishavTiwari25 avatar Mar 18 '26 22:03 RishavTiwari25

That doesn't make sense though... If the PRs use a cache that is only scoped to that specific PR, then the only caches that are saved are from the runs in main, right? Thus, we don't have anything to delete since everything's deleted when the branch from the PR gets deleted

jedel1043 avatar Mar 18 '26 22:03 jedel1043

By the same token, the only space consumed by caching is from the fork where the PR comes from, so any space used by caches from PRs won't count for the space used by this repository's cache from runs in main.

jedel1043 avatar Mar 18 '26 22:03 jedel1043

Closing this since it's not clear if the changes really improve cache disk usage

jedel1043 avatar Mar 19 '26 14:03 jedel1043