Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/scripts/tests/test_cache_cleanup_workflow.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion .github/workflows/cache-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading