From 499ba8ad2aae2286087c4f45dff18973b1d8c384 Mon Sep 17 00:00:00 2001 From: Ytallo Layon Date: Sat, 15 Aug 2026 06:48:00 -0300 Subject: [PATCH] chore(ci): fix closed PR cache cleanup --- .../tests/test_cache_cleanup_workflow.py | 21 +++++++++++++++++++ .github/workflows/cache-cleanup.yml | 12 ++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .github/scripts/tests/test_cache_cleanup_workflow.py diff --git a/.github/scripts/tests/test_cache_cleanup_workflow.py b/.github/scripts/tests/test_cache_cleanup_workflow.py new file mode 100644 index 000000000..7fb55da2b --- /dev/null +++ b/.github/scripts/tests/test_cache_cleanup_workflow.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from pathlib import Path + +import yaml + + +WORKFLOWS = Path(__file__).parents[2] / "workflows" + + +def test_cache_cleanup_uses_get_and_propagates_list_failures() -> None: + workflow = yaml.load( + (WORKFLOWS / "cache-cleanup.yml").read_text(), + Loader=yaml.BaseLoader, + ) + run = workflow["jobs"]["cleanup"]["steps"][0]["run"] + + assert 'gh api --method GET "repos/$REPOSITORY/actions/caches"' in run + assert 'cache_ids="$(' in run + assert 'mapfile -t ids <<<"$cache_ids"' in run + assert '< <(gh api' not in run diff --git a/.github/workflows/cache-cleanup.yml b/.github/workflows/cache-cleanup.yml index d06208b9d..06c5b87cd 100644 --- a/.github/workflows/cache-cleanup.yml +++ b/.github/workflows/cache-cleanup.yml @@ -24,7 +24,17 @@ jobs: run: | set -euo pipefail ref="refs/pull/$PR_NUMBER/merge" - mapfile -t ids < <(gh api "repos/$REPOSITORY/actions/caches" -f ref="$ref" -F per_page=100 --paginate --jq '.actions_caches[].id') + cache_ids="$( + gh api --method GET "repos/$REPOSITORY/actions/caches" \ + -f ref="$ref" \ + -F per_page=100 \ + --paginate \ + --jq '.actions_caches[].id' + )" + ids=() + if [[ -n "$cache_ids" ]]; then + mapfile -t ids <<<"$cache_ids" + fi for id in "${ids[@]}"; do gh api --method DELETE "repos/$REPOSITORY/actions/caches/$id" done