mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 14:28:42 +00:00
Run cache-cleanup at 3am & 4:30am AEST instead of after every PR (#944)
since cache-cleanup will issue a lot of gh api requests, running the workflow right after the PRs would cause the GH API to rate limit all workflows (including our CI for testing and release) that they can no longer upload artifacts and `cargo-binstall` would have to fallback to sending GET requests instead of using GH API, which makes it a lot slower and more likely to fail. This PR changes it to be run at 3am and 4:30am AEST which nobody would submit any PR at that time and then remove all caches of the top 20 closed prs. The workflow can also now be triggered manually. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
2ebc39478c
commit
47d4aeaa96
2 changed files with 37 additions and 22 deletions
34
.github/workflows/cache-cleanup.yml
vendored
34
.github/workflows/cache-cleanup.yml
vendored
|
@ -1,8 +1,12 @@
|
|||
name: Cleanup caches for closed PRs
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- closed
|
||||
# Run twice every day to remove the cache so that the caches from the closed prs
|
||||
# are removed.
|
||||
schedule:
|
||||
- cron: "0 17 * * *"
|
||||
- cron: "30 18 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
cleanup:
|
||||
|
@ -13,26 +17,12 @@ jobs:
|
|||
run: |
|
||||
gh extension install actions/gh-actions-cache
|
||||
|
||||
REPO="${{ github.repository }}"
|
||||
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
|
||||
export REPO="${{ github.repository }}"
|
||||
|
||||
while true; do
|
||||
echo "Fetching list of cache key"
|
||||
cacheKeysForPR="$(gh actions-cache list -R "$REPO" -B "$BRANCH" -L 100 | cut -f 1 )"
|
||||
|
||||
if [ -z "$cacheKeysForPR" ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
## Setting this to not fail the workflow while deleting cache keys.
|
||||
set +e
|
||||
echo "Deleting caches..."
|
||||
for cacheKey in $cacheKeysForPR
|
||||
do
|
||||
echo Removing "$cacheKey"
|
||||
gh actions-cache delete "$cacheKey" -R "$REPO" -B "$BRANCH" --confirm
|
||||
gh pr list --state closed -L 20 --json number --jq '.[]|.number' | (
|
||||
while IFS='$\n' read -r closed_pr; do
|
||||
BRANCH="refs/pull/${closed_pr}/merge" ./cleanup-cache.sh
|
||||
done
|
||||
done
|
||||
echo "Done"
|
||||
)
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue