From 9f4e4b38b62ee9ca00316603448ff7b24ae1d5da Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Sat, 15 Jun 2024 22:07:35 -0700
Subject: [PATCH] Echo a progress counter for each purge chunk

---
 .gitlab-ci.yml            | 4 +---
 purge-cache.gitlab-ci.yml | 4 ++++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d8527f4..1aaa27f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -103,11 +103,9 @@ create-purge-list:
     - sort -u -o purge-list.txt purge-list.txt
     # Duplicate each line, adding a trailing slash to the duplicates
     - sed -i 'p;s|$|/|' purge-list.txt
-    - cat purge-list.txt
-    - mv purge-list.txt purge.txt
   artifacts:
     paths:
-      - purge.txt
+      - purge-list.txt
 
 trigger-cache-purge:
   stage: .post
diff --git a/purge-cache.gitlab-ci.yml b/purge-cache.gitlab-ci.yml
index 54620ab..17287bd 100644
--- a/purge-cache.gitlab-ci.yml
+++ b/purge-cache.gitlab-ci.yml
@@ -22,10 +22,14 @@ purge-cache:
     - echo "Chunk size of ${CF_PURGE_CACHE_CHUNK_SIZE:=30}"
   script:
     # Split the purge list into chunks named 'purge-chunk-[aaa,aab,...]'
+    - rm purge-chunk-*
     - split -l $CF_PURGE_CACHE_CHUNK_SIZE -a 3 purge-list.txt purge-chunk-
+    - chunks=$(find . -type f -name 'purge-chunk-*' | wc -l)
     # Loop over the chunks, creating a purge request for each
     - |-
+      counter=0
       for chunk in purge-chunk-* ; do
+        echo -e "\nChunk $((++counter))/$chunks"
         # Create the purge request body
         echo -en "{\n  \"files\": [" > purge.json
         unset comma # This needs to be unset for the first line in each chunk
-- 
GitLab