77 - cron : 0 6 * * *
88
99env :
10- CACHE_THRESHOLD : 6442450944 # 6GB in bytes
10+ CACHE_THRESHOLD_GB : 25.5
1111
1212jobs :
1313 keep-build-cache-small :
@@ -16,31 +16,50 @@ jobs:
1616 - name : Install dependencies
1717 run : |
1818 sudo apt-get update
19- sudo apt-get install -y skopeo jq
19+ sudo apt-get install -y skopeo jq bc
2020
2121 - name : Login to GitHub Container Registry
2222 uses : docker/login-action@v3
2323 with :
2424 registry : ghcr.io
2525 username : ${{ github.repository_owner }}
26- password : ${{ github.token }}
26+ password : ${{ secrets.GITHUB_TOKEN }}
2727
2828 - name : Calculate cache size
2929 id : calc_size
3030 run : |
31- # Inspect the image and sum the sizes from all manifests
32- SIZE=$(skopeo inspect --raw docker://ghcr.io/autowarefoundation/autoware-buildcache:amd64-main | jq '[.manifests[].size] | add')
33- echo "Cache size: $SIZE bytes"
34- # Set outputs so they can be used in later steps
35- echo "::set-output name=size::$SIZE"
36-
37- #
38- # - name: Remove image if cache size exceeds threshold
39- # if: ${{ steps.calc_size.outputs.size && (steps.calc_size.outputs.size > env.CACHE_THRESHOLD) }}
40- # run: |
41- # echo "Cache size exceeds threshold. Removing image..."
42- # skopeo delete docker://ghcr.io/autowarefoundation/autoware-buildcache:amd64-main
43- #
44- # - name: Confirm cache size within threshold
45- # if: ${{ steps.calc_size.outputs.size && (steps.calc_size.outputs.size <= env.CACHE_THRESHOLD) }}
46- # run: echo "Cache size is within threshold. No action needed."
31+ echo "🔍 Inspecting build cache size..."
32+ SIZE_BYTES=$(skopeo inspect --raw docker://ghcr.io/autowarefoundation/autoware-buildcache:amd64-main | jq '[.manifests[].size] | add')
33+ SIZE_GB=$(echo "scale=2; $SIZE_BYTES / (1024 * 1024 * 1024)" | bc)
34+ echo "Cache size: ${SIZE_GB} GB"
35+ echo "size_gb=${SIZE_GB}" >> "$GITHUB_ENV"
36+ echo "size_gb=${SIZE_GB}" >> "$GITHUB_OUTPUT"
37+
38+ - name : Compare cache size with threshold
39+ id : check_threshold
40+ run : |
41+ echo "📊 Checking cache size against threshold..."
42+ THRESHOLD_GB=${{ env.CACHE_THRESHOLD_GB }}
43+ CACHE_SIZE_GB=${{ env.size_gb }}
44+
45+ if (( $(echo "$CACHE_SIZE_GB > $THRESHOLD_GB" | bc -l) )); then
46+ echo "❌ Cache size exceeds threshold. Action needed."
47+ echo "status=exceeded" >> "$GITHUB_ENV"
48+ echo "status=exceeded" >> "$GITHUB_OUTPUT"
49+ else
50+ echo "✅ Cache size is within threshold. No action needed."
51+ echo "status=ok" >> "$GITHUB_ENV"
52+ echo "status=ok" >> "$GITHUB_OUTPUT"
53+ fi
54+
55+ - name : Generate workflow summary
56+ run : |
57+ echo "# 📦 Build Cache Size Check" >> $GITHUB_STEP_SUMMARY
58+ echo "- **Cache Size**: ${{ env.size_gb }} GB" >> $GITHUB_STEP_SUMMARY
59+ echo "- **Threshold**: ${{ env.CACHE_THRESHOLD_GB }} GB" >> $GITHUB_STEP_SUMMARY
60+
61+ if [[ "${{ env.status }}" == "exceeded" ]]; then
62+ echo "❌ **Cache size exceeds threshold. Consider cleaning up!**" >> $GITHUB_STEP_SUMMARY
63+ else
64+ echo "✅ **Cache size is within acceptable limits.**" >> $GITHUB_STEP_SUMMARY
65+ fi
0 commit comments