]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
[CI] Cleanup action caches.
authorMika T. Lindqvist <postmaster@raasu.org>
Tue, 12 May 2026 07:53:45 +0000 (10:53 +0300)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 14 May 2026 11:13:20 +0000 (13:13 +0200)
.github/workflows/cache.yml [new file with mode: 0644]

diff --git a/.github/workflows/cache.yml b/.github/workflows/cache.yml
new file mode 100644 (file)
index 0000000..07f843f
--- /dev/null
@@ -0,0 +1,35 @@
+# Cleanup caches by a branch, original version from actions/cache documentation
+name: Cache Cleanup
+on:
+  pull_request:
+    types:
+      - closed
+  workflow_dispatch:
+
+jobs:
+  cleanup:
+    name: Cache Cleanup
+    runs-on: ubuntu-latest
+    permissions:
+      # `actions:write` permission is required to delete caches
+      #   See also: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-a-github-actions-cache-for-a-repository-using-a-cache-id
+      actions: write
+      contents: read
+    steps:
+      - name: Cleanup
+        run: |
+          echo "Fetching list of cache keys"
+          cacheKeysForPR=$(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 cacheKey in $cacheKeysForPR
+          do
+              gh cache delete $cacheKey
+          done
+          echo "Done"
+        env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          GH_REPO: ${{ github.repository }}
+          BRANCH: ${{ github.event.ref || format('refs/pull/{0}/merge', github.event.pull_request.number) }}