From 9dfe000ac68c17b6159864200d549d8a2191bad8 Mon Sep 17 00:00:00 2001 From: Nick Fedor <71477161+nicholas-fedor@users.noreply.github.com> Date: Sat, 18 Jan 2025 00:44:12 -0700 Subject: [PATCH] Create clean-cache.yml --- .github/workflows/clean-cache.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/clean-cache.yml diff --git a/.github/workflows/clean-cache.yml b/.github/workflows/clean-cache.yml new file mode 100644 index 0000000..6cf8646 --- /dev/null +++ b/.github/workflows/clean-cache.yml @@ -0,0 +1,27 @@ +name: cleanup caches by a branch +on: + pull_request: + types: + - closed + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Cleanup + run: | + echo "Fetching list of cache key" + cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id') + + ## Setting this to not fail the workflow while deleting cache keys. + set +e + echo "Deleting caches..." + for cacheKey in $cacheKeysForPR + do + gh cache delete $cacheKey + done + echo "Done" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge