From da18c85e192ea070cfd0da760596cf72300fc57e Mon Sep 17 00:00:00 2001 From: Jonathan Cubides Date: Thu, 23 Mar 2023 12:10:38 +0100 Subject: [PATCH 1/2] Create clean-up-cache.yaml --- .github/workflows/clean-up-cache.yaml | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/clean-up-cache.yaml diff --git a/.github/workflows/clean-up-cache.yaml b/.github/workflows/clean-up-cache.yaml new file mode 100644 index 0000000000..a6208495a7 --- /dev/null +++ b/.github/workflows/clean-up-cache.yaml @@ -0,0 +1,34 @@ +name: cleanup caches by a branch +on: + pull_request: + types: + - closed + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Cleanup + run: | + gh extension install actions/gh-actions-cache + + REPO=${{ github.repository }} + BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge" + + echo "Fetching list of cache key" + cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | 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 }} From 0d7a21fd622bf698d25df591235f93eb4bf4d9fd Mon Sep 17 00:00:00 2001 From: Jonathan Cubides Date: Thu, 23 Mar 2023 12:15:14 +0100 Subject: [PATCH 2/2] Make pre-commit happy --- .github/workflows/clean-up-cache.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/clean-up-cache.yaml b/.github/workflows/clean-up-cache.yaml index a6208495a7..df66592e51 100644 --- a/.github/workflows/clean-up-cache.yaml +++ b/.github/workflows/clean-up-cache.yaml @@ -10,19 +10,19 @@ jobs: steps: - name: Check out code uses: actions/checkout@v3 - + - name: Cleanup run: | gh extension install actions/gh-actions-cache - + REPO=${{ github.repository }} BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge" echo "Fetching list of cache key" cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 ) - ## Setting this to not fail the workflow while deleting cache keys. - + ## Setting this to not fail the workflow while deleting cache keys. + set +e echo "Deleting caches..." for cacheKey in $cacheKeysForPR