1
0
mirror of https://github.com/immich-app/immich.git synced 2024-11-24 08:52:28 +02:00

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
This commit is contained in:
bo0tzz 2023-01-18 15:28:28 +01:00 committed by GitHub
parent 3e4a14b299
commit 0c469cc712
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

33
.github/workflows/cache-cleanup.yml vendored Normal file
View File

@ -0,0 +1,33 @@
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 }}