From: Mika T. Lindqvist Date: Tue, 12 May 2026 07:53:45 +0000 (+0300) Subject: [CI] Cleanup action caches. X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=2ddd64c3264f07972d98ccf96748977a5004d68d;p=thirdparty%2Fzlib-ng.git [CI] Cleanup action caches. --- diff --git a/.github/workflows/cache.yml b/.github/workflows/cache.yml new file mode 100644 index 000000000..07f843f2a --- /dev/null +++ b/.github/workflows/cache.yml @@ -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) }}