[ci] Add daily stale branch cache cleanup (#32691)
Cleans up stale non-main caches daily --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32691). * #32692 * __->__ #32691
lauren committed
Mar 20, 2025 at 17:17 UTC
addce2f9f222befc6151251a247247a8463052fa
1 file changed
+33
.github/workflows/shared_cleanup_stale_branch_caches.yml
new
+33
@@ -0,0 +1,33 @@
1
+# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy
2
+
3
+name: (Shared) Cleanup Stale Branch Caches
4
+on:
5
+ schedule:
6
+ - cron: 0 0 * * *
7
+ workflow_dispatch:
8
+
9
+jobs:
10
+ cleanup:
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ # `actions:write` permission is required to delete caches
14
+ # See also: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-a-github-actions-cache-for-a-repository-using-a-cache-id
15
+ actions: write
16
+ contents: read
17
+ steps:
18
+ - name: Cleanup
19
+ run: |
20
+ echo "Fetching list of cache keys"
21
+ cacheKeysForPR=$(gh cache list --limit 100 --json id,ref --jq '.[] | select(.ref != "refs/heads/main") | .id')
22
+
23
+ ## Setting this to not fail the workflow while deleting cache keys.
24
+ set +e
25
+ for cacheKey in $cacheKeysForPR
26
+ do
27
+ gh cache delete $cacheKey
28
+ echo "Deleting $cacheKey"
29
+ done
30
+ echo "Done"
31
+ env:
32
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33
+ GH_REPO: ${{ github.repository }}