Skip to content

Commit 2089052

Browse files
authored
[ci] Add cache cleanup workflow (facebook#32675)
> Caches have branch scope restriction in place. This means that if caches for a specific branch are using a lot of storage quota, it may result into more frequently used caches from default branch getting thrashed. For example, if there are many pull requests happening on a repo and are creating caches, these cannot be used in default branch scope but will still occupy a lot of space till they get cleaned up by eviction policy. But sometime we want to clean them up on a faster cadence so as to ensure default branch is not thrashing. https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32675). * __->__ facebook#32675 * facebook#32674
1 parent 891a633 commit 2089052

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 Branch Caches
4+
on:
5+
pull_request:
6+
types:
7+
- closed
8+
workflow_dispatch:
9+
10+
jobs:
11+
cleanup:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
# `actions:write` permission is required to delete caches
15+
# 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
16+
actions: write
17+
contents: read
18+
steps:
19+
- name: Cleanup
20+
run: |
21+
echo "Fetching list of cache key"
22+
cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
23+
24+
## Setting this to not fail the workflow while deleting cache keys.
25+
set +e
26+
echo "Deleting caches..."
27+
for cacheKey in $cacheKeysForPR
28+
do
29+
gh cache delete $cacheKey
30+
done
31+
echo "Done"
32+
env:
33+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
GH_REPO: ${{ github.repository }}
35+
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge

0 commit comments

Comments
 (0)