From fd96ba48c6195462b5b2de80304025c79b61e6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 13 Mar 2025 16:54:07 +0100 Subject: [PATCH] CI: Add workflow to cleanup PR caches when closed This is pretty much copied from the GitHub Actions documentation: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries --- .github/workflows/cache_cleanup.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/cache_cleanup.yml diff --git a/.github/workflows/cache_cleanup.yml b/.github/workflows/cache_cleanup.yml new file mode 100644 index 00000000000..94188b379cc --- /dev/null +++ b/.github/workflows/cache_cleanup.yml @@ -0,0 +1,28 @@ +# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries +name: 🧹 Cache Cleanup +on: + pull_request: + types: + - closed + +jobs: + cleanup: + name: Cleanup PR caches + runs-on: ubuntu-latest + steps: + - name: Cleanup + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge + run: | + echo "Fetching list of cache key" + cache_keys_for_pr=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id') + # Setting this to not fail the workflow while deleting cache keys. + set +e + echo "Deleting caches..." + for cache_key in $cache_keys_for_pr; do + gh cache delete $cache_key + echo "Deleted: $cache_key" + done + echo "Done"