Skip to content

Commit

Permalink
ci: Add cache cleanup workflow (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
bodgit authored Dec 10, 2023
1 parent 11825a1 commit f654743
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Clean up per-branch caches

on:
pull_request:
types:
- closed
workflow_dispatch:

permissions:
contents: read

jobs:
cleanup:
runs-on: ubuntu-latest

permissions:
actions: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
BRANCH=refs/pull/${{ github.event.pull_request.number }}/merge
echo "Fetching list of cache keys"
keys=$(gh actions-cache list -R $GITHUB_REPOSITORY -B $BRANCH -L 100 | cut -f 1)
set +e
echo "Deleting caches..."
for key in $keys ; do
gh actions-cache delete $key -R $GITHUB_REPOSITORY -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit f654743

Please sign in to comment.