cargo-binstall/cleanup-cache.sh
Jiahao XU 47d4aeaa96
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>
2023-03-23 18:10:30 +11:00

25 lines
599 B
Bash
Executable file

#!/bin/bash
set -uxo pipefail
REPO="${REPO?}"
BRANCH="${BRANCH?}"
while true; do
echo "Fetching list of cache key for $BRANCH"
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
done
done
echo "Done cleaning up $BRANCH"