From cc87fe062da81e7f1b8f905ef5a6adbc7a8b1587 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Mon, 5 Jun 2023 22:54:01 +1000 Subject: [PATCH] ci: Rm merge queue cache in `cache-cleanup.yml` (#1129) since they cannot be reused Signed-off-by: Jiahao XU --- .github/workflows/cache-cleanup.yml | 12 ++++++++++++ cleanup-cache.sh | 4 +--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cache-cleanup.yml b/.github/workflows/cache-cleanup.yml index 1e8da6ba..2a9ad231 100644 --- a/.github/workflows/cache-cleanup.yml +++ b/.github/workflows/cache-cleanup.yml @@ -15,14 +15,26 @@ jobs: - uses: actions/checkout@v3 - name: Cleanup run: | + set -euxo pipefail + gh extension install actions/gh-actions-cache export REPO="${{ github.repository }}" + # Setting this to not fail the workflow while deleting cache keys. + set +e + + # Remove pull requests cache, since they cannot be reused 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 ) + # Remove merge queue cache, since they cannot be reused + gh actions-cache list -L 100 | cut -f 3 | grep 'gh-readonly-queue' | sort -u | ( + while IFS='$\n' read -r branch; do + BRANCH="$branch" ./cleanup-cache.sh + done + ) env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/cleanup-cache.sh b/cleanup-cache.sh index 5c38d86a..4fcbf6d3 100755 --- a/cleanup-cache.sh +++ b/cleanup-cache.sh @@ -7,14 +7,12 @@ 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 )" + 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