From 0c85b9915f92eca4fde00b0db423eafe4da9b905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sun, 19 May 2024 21:28:08 +0200 Subject: [PATCH] ci/cleanup_caches: group by cache prefixes too I've simplified this too much during refactoring, forgot about this. We need to preserve the latest cache with each prefix. Fixes: c6b950ae1e722dbe8c2414017a3c521f8c5730e9 --- .github/workflows/cleanup_caches.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 }}