Skip to content

Commit

Permalink
Close #563: Clear caches for branches of merged PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbenito committed Jan 15, 2025
1 parent bf380bd commit d1b60a1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/cleanup-caches.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Delete caches for a PR after merging
on:
pull_request:
types:
- closed

jobs:
cleanup:
runs-on: ubuntu-22.04
steps:
- name: Cleanup
run: |
echo "Fetching list of cache keys for PR..."
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: refs/pull/${{ github.event.pull_request.number }}/merge

0 comments on commit d1b60a1

Please sign in to comment.