@@ -83,14 +83,38 @@ jobs:
83
83
if : runner.os != 'Windows'
84
84
shell : bash
85
85
run : |
86
- # Get the build cache size (in MB) using docker system df
87
- cache_size=$(docker system df -v | grep "Build Cache" | awk '{print $3}' | sed 's/GB//' | sed 's/MB//' | awk '{printf "%.0f\n", $1 * (index($0, "GB") > 0 ? 1024 : 1)}')
88
- # Check if the cache size exceeds 50GB (51200MB)
89
- if [ "$cache_size" -gt 51200 ]; then
90
- echo "Cache is over 50GB, pruning..."
91
- docker builder prune --all --force
86
+ # First check if build cache exists
87
+ if docker system df -v | grep -q "Build Cache"; then
88
+ # Get the build cache size and convert to MB
89
+ cache_info=$(docker system df -v | grep "Build Cache")
90
+ if echo "$cache_info" | grep -q "GB"; then
91
+ # Extract value and convert GB to MB
92
+ cache_size=$(echo "$cache_info" | awk '{print $3}' | sed 's/GB//' | awk '{printf "%.0f", $1 * 1024}')
93
+ elif echo "$cache_info" | grep -q "MB"; then
94
+ # Extract MB value directly
95
+ cache_size=$(echo "$cache_info" | awk '{print $3}' | sed 's/MB//' | awk '{printf "%.0f", $1}')
96
+ else
97
+ # Handle KB or smaller (treat as 0 MB)
98
+ cache_size=0
99
+ fi
100
+
101
+ # Ensure cache_size is a number
102
+ if [[ "$cache_size" =~ ^[0-9]+$ ]]; then
103
+ # Check if the cache size exceeds 50GB (51200MB)
104
+ if [ "$cache_size" -gt 51200 ]; then
105
+ echo "Cache is over 50GB (${cache_size}MB), pruning..."
106
+ docker builder prune --all --force
107
+ else
108
+ echo "Cache size is ${cache_size}MB, under 50GB, no action taken."
109
+ fi
110
+ else
111
+ echo "Could not determine cache size, output was: $cache_info"
112
+ # Show example output to debug
113
+ echo "Full docker system df -v output:"
114
+ docker system df -v
115
+ fi
92
116
else
93
- echo "Cache size is ${cache_size}MB, under 50GB, no action taken ."
117
+ echo "No build cache found ."
94
118
fi
95
119
96
120
0 commit comments