Skip to content

Commit 0dc32a8

Browse files
Update lite-test-ubuntu-headless.yml
1 parent 0ad687b commit 0dc32a8

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

.github/workflows/lite-test-ubuntu-headless.yml

+31-7
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,38 @@ jobs:
8383
if: runner.os != 'Windows'
8484
shell: bash
8585
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
92116
else
93-
echo "Cache size is ${cache_size}MB, under 50GB, no action taken."
117+
echo "No build cache found."
94118
fi
95119
96120

0 commit comments

Comments
 (0)