ci(keep-build-cache-small): create new workflow #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: keep-build-cache-small | |
| on: | |
| pull_request: | |
| workflow_call: | |
| schedule: | |
| - cron: 0 6 * * * | |
| env: | |
| CACHE_THRESHOLD_GB: 25.5 | |
| jobs: | |
| keep-build-cache-small: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y skopeo jq bc | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Calculate cache size | |
| id: calc_size | |
| run: | | |
| echo "🔍 Inspecting build cache size..." | |
| SIZE_BYTES=$(skopeo inspect --raw docker://ghcr.io/autowarefoundation/autoware-buildcache:amd64-main | jq '[.manifests[].size] | add') | |
| SIZE_GB=$(echo "scale=2; $SIZE_BYTES / (1024 * 1024 * 1024)" | bc) | |
| echo "Cache size: ${SIZE_GB} GB" | |
| echo "size_gb=${SIZE_GB}" >> "$GITHUB_ENV" | |
| echo "size_gb=${SIZE_GB}" >> "$GITHUB_OUTPUT" | |
| - name: Compare cache size with threshold | |
| id: check_threshold | |
| run: | | |
| echo "📊 Checking cache size against threshold..." | |
| THRESHOLD_GB=${{ env.CACHE_THRESHOLD_GB }} | |
| CACHE_SIZE_GB=${{ env.size_gb }} | |
| if (( $(echo "$CACHE_SIZE_GB > $THRESHOLD_GB" | bc -l) )); then | |
| echo "❌ Cache size exceeds threshold. Action needed." | |
| echo "status=exceeded" >> "$GITHUB_ENV" | |
| echo "status=exceeded" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "✅ Cache size is within threshold. No action needed." | |
| echo "status=ok" >> "$GITHUB_ENV" | |
| echo "status=ok" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Generate workflow summary | |
| run: | | |
| echo "# 📦 Build Cache Size Check" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Cache Size**: ${{ env.size_gb }} GB" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Threshold**: ${{ env.CACHE_THRESHOLD_GB }} GB" >> $GITHUB_STEP_SUMMARY | |
| if [[ "${{ env.status }}" == "exceeded" ]]; then | |
| echo "❌ **Cache size exceeds threshold. Consider cleaning up!**" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "✅ **Cache size is within acceptable limits.**" >> $GITHUB_STEP_SUMMARY | |
| fi |