github.com/crowdsecurity/crowdsec@v1.6.1/.github/workflows/cache-cleanup.yaml (about) 1 # https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#managing-caches 2 3 name: cleanup caches by a branch 4 on: 5 pull_request: 6 types: 7 - closed 8 9 jobs: 10 cleanup: 11 runs-on: ubuntu-latest 12 steps: 13 - name: Check out code 14 uses: actions/checkout@v4 15 16 - name: Cleanup 17 run: | 18 gh extension install actions/gh-actions-cache 19 20 REPO=${{ github.repository }} 21 BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge" 22 23 echo "Fetching list of cache key" 24 cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 ) 25 26 ## Setting this to not fail the workflow while deleting cache keys. 27 set +e 28 echo "Deleting caches..." 29 for cacheKey in $cacheKeysForPR 30 do 31 gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm 32 done 33 echo "Done" 34 env: 35 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}