-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 changed file
with
13 additions
and
13 deletions.
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 |
---|---|---|
@@ -1,27 +1,27 @@ | ||
# Mostly for DeterminateSystems/magic-nix-cache-action | ||
name: 👋 caches in a branch | ||
name: 👋 caches in merged PRs | ||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
schedule: | ||
# Every 12:42 JST | ||
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule | ||
- cron: '42 3 * * *' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
cleanup: | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
# Intentionally cover all merged PRs to keep simple logics. See https://github.com/kachick/times_kachick/issues/311 | ||
- name: Cleanup | ||
run: | | ||
echo "Fetching list of cache key" | ||
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" | ||
gh pr list --state merged --json number --jq '.[].number' --limit 2000 | \ | ||
xargs --no-run-if-empty -I '{}' gh cache list --sort size_in_bytes --order desc --json id --jq '.[].id' --limit 100 --ref 'refs/pull/{}/merge' | \ | ||
xargs --no-run-if-empty --max-lines=1 gh cache delete | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge |