cleanup-cache.yml 892 B

123456789101112131415161718192021222324252627282930313233
  1. name: Cleanup caches by a branch
  2. on:
  3. pull_request:
  4. types:
  5. - closed
  6. jobs:
  7. cleanup:
  8. runs-on: ubuntu-latest
  9. steps:
  10. - name: Checkout
  11. uses: actions/checkout@v4
  12. - name: Cleanup
  13. run: |
  14. gh extension install actions/gh-actions-cache
  15. REPO=${{ github.repository }}
  16. BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
  17. echo "Fetching list of cache key"
  18. cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
  19. ## Setting this to not fail the workflow while deleting cache keys.
  20. set +e
  21. echo "Deleting caches..."
  22. for cacheKey in $cacheKeysForPR
  23. do
  24. gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
  25. done
  26. echo "Done"
  27. env:
  28. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}