Skip to content

Commit addce2f

Browse files
authored
[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
1 parent 74bcf3d commit addce2f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 }}

0 commit comments

Comments
 (0)