Skip to content

Commit

Permalink
attempt to clear cache #4
Browse files Browse the repository at this point in the history
  • Loading branch information
bahill committed Nov 14, 2024
1 parent d68cdd3 commit 0c181f8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/clean_cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: cleanup caches by a branch
on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
# `actions:write` permission is required to delete caches
# See also: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-a-github-actions-cache-for-a-repository-using-a-cache-id
actions: write
contents: read
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH=refs/pull/${{ github.event.pull_request.number }}/merge
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | 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.BH_GH_TOKEN_TO_CLEAN_CACHE }}
2 changes: 0 additions & 2 deletions .github/workflows/validate_pull_request_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ jobs:
uses: snok/install-poetry@v1
with:
version: 1.1.9
- name: Clear Poetry Cache
run: rm -rf ~/.cache/pypoetry/*
- name: Restore cache dependencies
uses: actions/cache@v2
env:
Expand Down

0 comments on commit 0c181f8

Please sign in to comment.