1414 - name : Cleanup old caches
1515 shell : bash
1616 run : |
17+ # Enable debug mode and error handling
18+ set -x
19+
20+ # Test GitHub CLI authentication
21+ echo "🔑 Testing GitHub CLI authentication..."
22+ gh auth status || {
23+ echo "❌ GitHub CLI authentication failed"
24+ exit 1
25+ }
26+
1727 # Define services array
1828 services=("server" "stage-transcriptions" "session-transcriptions" "clips" "reel-creator")
1929
2232 echo "🔍 Scanning buildx cache for service: $service"
2333
2434 # Get all cache keys for this specific service's buildx cache
35+ echo "📋 Fetching cache list..."
2536 cacheKeys=$(gh cache list --limit 100 --json key,createdAt \
2637 --jq '.[] | select(.key | contains("Linux-buildx-'$service'")) | [.key, .createdAt] | @tsv' \
27- | sort -k2,2r)
38+ | sort -k2,2r) || {
39+ echo "❌ Failed to fetch cache list for $service"
40+ return 1
41+ }
42+
43+ if [ -z "$cacheKeys" ]; then
44+ echo "ℹ️ No caches found for service: $service"
45+ return 0
46+ }
2847
2948 # Keep count of caches for this service
3049 count=0
3453 # Keep only the most recent cache for each service
3554 if [ "$count" -gt 1 ]; then
3655 echo "🗑️ Deleting old cache for $service: $key"
37- gh cache delete "$key"
56+ gh cache delete "$key" || echo "⚠️ Failed to delete cache: $key"
3857 else
3958 echo "💾 Keeping most recent cache for $service: $key"
4059 fi
4463
4564 # Clean up buildx caches for each service
4665 echo "🚀 Starting cache cleanup process..."
66+ failed_services=()
4767 for service in "${services[@]}"; do
48- cleanup_buildx_cache "$service"
68+ if ! cleanup_buildx_cache "$service"; then
69+ failed_services+=("$service")
70+ fi
4971 done
5072
5173 # Clean up other types of caches (playwright, yarn)
@@ -56,15 +78,23 @@ jobs:
5678
5779 cacheKeys=$(gh cache list --limit 100 --json key,createdAt \
5880 --jq '.[] | select(.key | contains("'$pattern'")) | [.key, .createdAt] | @tsv' \
59- | sort -k2,2r)
81+ | sort -k2,2r) || {
82+ echo "❌ Failed to fetch cache list for $pattern"
83+ return 1
84+ }
85+
86+ if [ -z "$cacheKeys" ]; then
87+ echo "ℹ️ No caches found for pattern: $pattern"
88+ return 0
89+ }
6090
6191 count=0
6292 while IFS=$'\t' read -r key date; do
6393 ((count++))
6494
6595 if [ "$count" -gt "$keep" ]; then
6696 echo "🗑️ Deleting old cache: $key"
67- gh cache delete "$key"
97+ gh cache delete "$key" || echo "⚠️ Failed to delete cache: $key"
6898 else
6999 echo "💾 Keeping recent cache: $key"
70100 fi
@@ -73,9 +103,24 @@ jobs:
73103 }
74104
75105 # Clean up other cache types
76- cleanup_other_caches "playwright" 2
77- cleanup_other_caches "yarn" 2
78- echo "🎉 Cache cleanup completed successfully!"
106+ failed_patterns=()
107+ for pattern in "playwright" "yarn"; do
108+ if ! cleanup_other_caches "$pattern" 2; then
109+ failed_patterns+=("$pattern")
110+ fi
111+ done
112+
113+ # Report results
114+ echo "📊 Cleanup Summary:"
115+ if [ ${#failed_services[@]} -eq 0 ] && [ ${#failed_patterns[@]} -eq 0 ]; then
116+ echo "🎉 Cache cleanup completed successfully!"
117+ exit 0
118+ else
119+ echo "⚠️ Cache cleanup completed with some issues:"
120+ [ ${#failed_services[@]} -gt 0 ] && echo "❌ Failed services: ${failed_services[*]}"
121+ [ ${#failed_patterns[@]} -gt 0 ] && echo "❌ Failed patterns: ${failed_patterns[*]}"
122+ exit 1
123+ fi
79124 env :
80125 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
81126 GH_REPO : ${{ github.repository }}
0 commit comments