diff --git a/.github/workflows/cleanup_caches.yml b/.github/workflows/cleanup_caches.yml index fdc692682e..3cde65ca1d 100644 --- a/.github/workflows/cleanup_caches.yml +++ b/.github/workflows/cleanup_caches.yml @@ -18,16 +18,19 @@ jobs: group_by(.ref) | map({ ref: .[0].ref, - caches: map(.key) + caches: map({ + key: .key, + prefix: (.key | capture("^(?[\\w_-]+-)\\d+$").prefix) + }) | group_by(.prefix) | map({keys: map(.key)}) }) | .[] ' | while read -r group; do pr=$(echo "$group" | jq -r '.ref | capture("refs/pull/(?[0-9]+)/merge").num') if [[ -n "$pr" ]] && [ "$(gh pr view -R ${{ github.repository }} $pr --json state --jq '.state')" != "OPEN" ]; then - keys=$(echo "$group" | jq -c '.caches') + keys=$(echo "$group" | jq -c '.caches | map(.keys) | .[]') else - keys=$(echo "$group" | jq -c '.caches[1:]') + keys=$(echo "$group" | jq -c '.caches | map(.keys[1:]) | .[]') fi for key in $(echo "$keys" | jq -r '.[]'); do gh cache delete "$key" -R ${{ github.repository }}