6262 total_runs=0
6363 while true; do
6464 echo "📄 Fetching page ${page}..."
65- response=$(gh api "repos/${{ github.repository }}/actions/runs?per_page=100&page=${page}" --jq '.workflow_runs[] | "\(.id)~ \(.created_at)~ \(.name // "Unknown")~ \(.workflow_id)"')
65+ response=$(gh api "repos/${{ github.repository }}/actions/runs?per_page=100&page=${page}" --jq '.workflow_runs[] | "\(.id)| \(.created_at)| \(.name // "Unknown" | @base64)| \(.workflow_id)"')
6666
6767 if [[ -z "$response" ]]; then
6868 echo "📄 No more runs found on page ${page}"
@@ -80,20 +80,23 @@ runs:
8080 echo "📊 Total workflow runs found: ${total_runs}"
8181
8282 # Sort runs by date (newest first) and process them
83- sort -t'~ ' -k2 -r "$ALL_RUNS" > "${ALL_RUNS}.sorted"
83+ sort -t'| ' -k2 -r "$ALL_RUNS" > "${ALL_RUNS}.sorted"
8484
8585 # Group runs by workflow_id and keep the specified number of latest runs
8686 declare -A workflow_keep_count
8787 runs_to_delete=0
8888 runs_to_keep=0
8989
90- while IFS='~ ' read -r run_id created_at workflow_name workflow_id; do
90+ while IFS='| ' read -r run_id created_at workflow_name_b64 workflow_id; do
9191 # Skip empty lines and validate essential fields
9292 if [[ -z "$run_id" || -z "$created_at" ]]; then
9393 echo "⚠️ Skipping invalid entry: run_id='$run_id', created_at='$created_at'"
9494 continue
9595 fi
9696
97+ # Decode the workflow name from base64
98+ workflow_name=$(echo "$workflow_name_b64" | base64 -d 2>/dev/null || echo "Unknown")
99+
97100 # Skip if workflow_id is empty or invalid
98101 if [[ -z "$workflow_id" ]]; then
99102 workflow_id="unknown"
@@ -121,7 +124,7 @@ runs:
121124 fi
122125
123126 if [[ "$should_delete" == "true" ]]; then
124- echo "${run_id}~ ${created_at}~${workflow_name}~ ${workflow_id}" >> "$RUNS_TO_DELETE"
127+ echo "${run_id}| ${created_at}|${workflow_name_b64}| ${workflow_id}" >> "$RUNS_TO_DELETE"
125128 runs_to_delete=$((runs_to_delete + 1))
126129 else
127130 runs_to_keep=$((runs_to_keep + 1))
@@ -145,13 +148,16 @@ runs:
145148 deleted_count=0
146149 failed_count=0
147150
148- while IFS='~ ' read -r run_id created_at workflow_name workflow_id; do
151+ while IFS='| ' read -r run_id created_at workflow_name_b64 workflow_id; do
149152 # Skip empty lines and validate run_id
150153 if [[ -z "$run_id" ]]; then
151154 echo "⚠️ Skipping deletion: empty run_id"
152155 continue
153156 fi
154157
158+ # Decode the workflow name from base64
159+ workflow_name=$(echo "$workflow_name_b64" | base64 -d 2>/dev/null || echo "Unknown")
160+
155161 if [[ "$DRY_RUN" == "true" ]]; then
156162 echo "🔍 [DRY RUN] Would delete: Run ${run_id} (${workflow_name}) created ${created_at}"
157163 else
0 commit comments