diff --git a/.github/actions/setup-gradle/action.yml b/.github/actions/setup-gradle/action.yml index 1c8b2e5f3f7..6027c0ab9c5 100644 --- a/.github/actions/setup-gradle/action.yml +++ b/.github/actions/setup-gradle/action.yml @@ -7,3 +7,7 @@ runs: uses: gradle/actions/setup-gradle@v3 with: gradle-version: wrapper + # The gradle-home-v1 cache entry grows very, eventually failing the jobs + # when extracted. + gradle-home-cache-cleanup: true + diff --git a/.github/workflows/cleanup-pr-cache.yml b/.github/workflows/cleanup-pr-cache.yml new file mode 100644 index 00000000000..38d78749b32 --- /dev/null +++ b/.github/workflows/cleanup-pr-cache.yml @@ -0,0 +1,30 @@ +# From: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries +name: cleanup caches by a branch that was closed +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