Skip to content

Commit

Permalink
Merge pull request #7 from byawitz/feature/clear_cache
Browse files Browse the repository at this point in the history
[⚡️] - Adding clean cache action
  • Loading branch information
byawitz authored Mar 17, 2024
2 parents 34298f8 + d1e46da commit 21bdfdb
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/clear-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Clear Cache

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="refs/pull/${{ github.event.pull_request.number }}/merge"
while true
do
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
if [ -z "$cacheKeysForPR" ]
then
break
fi
## Setting this to not fail the workflow while deleting cache keys.
set +e
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 21bdfdb

Please sign in to comment.