Skip to content

Commit 7b02626

Browse files
committed
Update clean up script
1 parent f2d6c86 commit 7b02626

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

.github/workflows/cleanup-script.sh

+47-19
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,57 @@ delete_old_tags() {
3030
# Function to start garbage collection
3131
start_garbage_collection() {
3232
echo "Starting garbage collection..."
33-
doctl registry garbage-collection start --include-untagged-manifests --force
33+
if doctl registry garbage-collection start --include-untagged-manifests --force; then
34+
echo "Garbage collection started successfully."
35+
return 0
36+
else
37+
echo "Failed to start garbage collection."
38+
return 1
39+
fi
3440
}
3541

3642
# Function to check garbage collection status
3743
check_garbage_collection_status() {
3844
local status
39-
status=$(doctl registry garbage-collection get-active --format Status --no-header)
40-
echo "$status"
45+
status=$(doctl registry garbage-collection get-active --format Status --no-header 2>/dev/null) || true
46+
if [ -z "$status" ]; then
47+
echo "no_active_gc"
48+
else
49+
echo "$status"
50+
fi
4151
}
4252

4353
# Function to wait for garbage collection to complete
4454
wait_for_garbage_collection() {
45-
echo "Waiting for garbage collection to complete..."
46-
while true; do
55+
echo "Checking garbage collection status..."
56+
local max_attempts=30
57+
local attempt=1
58+
while [ $attempt -le $max_attempts ]; do
4759
local status
4860
status=$(check_garbage_collection_status)
49-
if [ "$status" = "succeeded" ]; then
50-
echo "Garbage collection completed successfully."
51-
break
52-
elif [ "$status" = "failed" ]; then
53-
echo "Garbage collection failed."
54-
exit 1
55-
fi
56-
echo "Garbage collection is still in progress. Waiting..."
57-
sleep 60 # Wait for 60 seconds before checking again
61+
case "$status" in
62+
"succeeded")
63+
echo "Garbage collection completed successfully."
64+
return 0
65+
;;
66+
"failed")
67+
echo "Garbage collection failed."
68+
return 1
69+
;;
70+
"no_active_gc")
71+
echo "No active garbage collection found. It may have completed quickly."
72+
return 0
73+
;;
74+
*)
75+
if [ $attempt -eq $max_attempts ]; then
76+
echo "Garbage collection is still in progress after maximum attempts. Please check manually."
77+
return 1
78+
fi
79+
echo "Garbage collection is still in progress. Waiting... (Attempt $attempt/$max_attempts)"
80+
sleep 30 # Wait for 30 seconds before checking again
81+
;;
82+
esac
83+
attempt=$((attempt + 1))
5884
done
5985
}
6086

@@ -73,9 +99,11 @@ while IFS= read -r repo; do
7399
done <<< "$REPOS"
74100

75101
# Start garbage collection
76-
start_garbage_collection
77-
78-
# Wait for garbage collection to complete
79-
wait_for_garbage_collection
102+
if start_garbage_collection; then
103+
# Wait for garbage collection to complete
104+
wait_for_garbage_collection
105+
else
106+
echo "Skipping garbage collection wait due to start failure."
107+
fi
80108

81-
echo "Cleanup and garbage collection completed."
109+
echo "Cleanup process completed."

0 commit comments

Comments
 (0)