From ef53cb38e3528b55e97a2f3104e62073556a3efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renato=20Foot=20Guimar=C3=A3es=20Costallat?= Date: Wed, 1 Nov 2023 11:21:16 -0300 Subject: [PATCH] ci/cl: clear GitHub actions cache on PR closure (#1751) Clean GHA cache related to the PR being closed. --- .github/workflows/clean-cache.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/clean-cache.yaml diff --git a/.github/workflows/clean-cache.yaml b/.github/workflows/clean-cache.yaml new file mode 100644 index 00000000000..ed298937a51 --- /dev/null +++ b/.github/workflows/clean-cache.yaml @@ -0,0 +1,30 @@ +--- +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