-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: cleanup caches | ||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
workflow_dispatch: # Adding manual trigger option | ||
|
||
jobs: | ||
cleanup: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Cleanup all caches | ||
run: | | ||
if [ "${{ github.event_name }}" == "pull_request" ]; then | ||
# For pull request events, clean specific PR branch caches | ||
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge" | ||
echo "Cleaning caches for PR branch: $BRANCH" | ||
cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id') | ||
else | ||
# For manual dispatch, clean all caches | ||
echo "Cleaning all repository caches" | ||
cacheKeysForPR=$(gh cache list --limit 100 --json id --jq '.[].id') | ||
fi | ||
## 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 --confirm | ||
done | ||
echo "Done" | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GH_REPO: ${{ github.repository }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters