From 58a9a9a2206a6001a44277433b961a62ed57f36a Mon Sep 17 00:00:00 2001 From: Ivar Nilsen Date: Wed, 27 Nov 2024 13:12:52 +0100 Subject: [PATCH] chore: delete branch caches after merge --- .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 00000000000..0072fe28b65 --- /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.FREMTIND_BOT_ACCESS_TOKEN }} + GH_REPO: ${{ github.repository }} + BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge