1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-01 09:51:16 +02:00
immich/.github/workflows/cache-cleanup.yml
bo0tzz 0c469cc712
feat(ci): Clean up the actions cache on PR close (#1350)
* feat(ci): Clean up the actions cache on PR close

The cache entries that are generated on a workflow run for a PR cannot be used by any other contexts [1]. As such, they are useless and just wasting valuable cache space. This commit adds a workflow (copied from [2]) that deletes the cache entries when a PR is closed.

[1] https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache
[2] https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries

* feat(ci): List as many cache entries as possible
2023-01-18 08:28:28 -06:00

34 lines
893 B
YAML

name: Clean up actions cache on PR close
on:
pull_request:
types:
- closed
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH=${{ github.ref }}
echo "Fetching list of cache keys"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}