cache_cleanup.yml 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. # https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy
  2. name: 🧹 Cache Cleanup
  3. on:
  4. pull_request:
  5. types:
  6. - closed
  7. jobs:
  8. cleanup:
  9. name: Cleanup PR caches
  10. runs-on: ubuntu-latest
  11. permissions:
  12. # `actions:write` permission is required to delete caches
  13. actions: write
  14. contents: read
  15. steps:
  16. - name: Cleanup
  17. env:
  18. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  19. GH_REPO: ${{ github.repository }}
  20. BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
  21. run: |
  22. echo "Fetching list of cache key"
  23. cache_keys_for_pr=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
  24. # Setting this to not fail the workflow while deleting cache keys.
  25. set +e
  26. echo "Deleting caches..."
  27. for cache_key in $cache_keys_for_pr; do
  28. gh cache delete $cache_key
  29. echo "Deleted: $cache_key"
  30. done
  31. echo "Done"