From 237341203b866f9619561091ee72543312315028 Mon Sep 17 00:00:00 2001 From: Taylor Jones Date: Wed, 1 Nov 2023 08:18:55 -0500 Subject: [PATCH] ci(cache): cleanup caches after PRs merge (#15078) * ci(cache): turn off caching in the merge queue * ci(cache): cleanup caches after PRs merge --- .github/workflows/cleanup-caches.yml | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/cleanup-caches.yml diff --git a/.github/workflows/cleanup-caches.yml b/.github/workflows/cleanup-caches.yml new file mode 100644 index 000000000000..f447af3c850e --- /dev/null +++ b/.github/workflows/cleanup-caches.yml @@ -0,0 +1,30 @@ +# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries +name: Cleanup caches by a branch +on: + pull_request: + types: + - closed + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Cleanup + run: | + gh extension install actions/gh-actions-cache + + echo "Fetching list of cache key" + cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 ) + + ## Setting this to not fail the workflow while deleting cache keys. + set +e + echo "Deleting caches..." + for cacheKey in $cacheKeysForPR + do + gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm + done + echo "Done" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge