-
Notifications
You must be signed in to change notification settings - Fork 3.6k
152 lines (134 loc) · 6.43 KB
/
keep-build-cache-small.yaml
File metadata and controls
152 lines (134 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: keep-build-cache-small
on:
workflow_dispatch:
schedule:
- cron: 0 6 * * *
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
jobs:
keep-build-cache-small:
runs-on: ubuntu-latest
strategy:
matrix:
include:
# ci-base
- { image_tag: ci-base-humble-amd64-main, cache_threshold_gb: 7.0 }
- { image_tag: ci-base-humble-arm64-main, cache_threshold_gb: 9.0 }
- { image_tag: ci-base-jazzy-amd64-main, cache_threshold_gb: 7.0 }
- { image_tag: ci-base-jazzy-arm64-main, cache_threshold_gb: 9.0 }
# ci-core
- { image_tag: ci-core-humble-amd64-main, cache_threshold_gb: 7.0 }
- { image_tag: ci-core-humble-arm64-main, cache_threshold_gb: 9.0 }
- { image_tag: ci-core-jazzy-amd64-main, cache_threshold_gb: 7.0 }
- { image_tag: ci-core-jazzy-arm64-main, cache_threshold_gb: 9.0 }
# ci-base-cuda
- { image_tag: ci-base-cuda-humble-amd64-main, cache_threshold_gb: 9.0 }
- { image_tag: ci-base-cuda-humble-arm64-main, cache_threshold_gb: 11.0 }
- { image_tag: ci-base-cuda-jazzy-amd64-main, cache_threshold_gb: 9.0 }
- { image_tag: ci-base-cuda-jazzy-arm64-main, cache_threshold_gb: 11.0 }
# ci-universe
- { image_tag: ci-universe-humble-amd64-main, cache_threshold_gb: 7.0 }
- { image_tag: ci-universe-humble-arm64-main, cache_threshold_gb: 9.0 }
- { image_tag: ci-universe-jazzy-amd64-main, cache_threshold_gb: 7.0 }
- { image_tag: ci-universe-jazzy-arm64-main, cache_threshold_gb: 9.0 }
# ci-universe-cuda
- { image_tag: ci-universe-cuda-humble-amd64-main, cache_threshold_gb: 9.0 }
- { image_tag: ci-universe-cuda-humble-arm64-main, cache_threshold_gb: 11.0 }
- { image_tag: ci-universe-cuda-jazzy-amd64-main, cache_threshold_gb: 9.0 }
- { image_tag: ci-universe-cuda-jazzy-arm64-main, cache_threshold_gb: 11.0 }
env:
IMAGE_NAME: autoware-buildcache
steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y skopeo jq bc
- name: Set up environment variables
run: |
echo "CACHE_THRESHOLD_GB=${{ matrix.cache_threshold_gb }}" >> "$GITHUB_ENV"
echo "IMAGE_TAG=${{ matrix.image_tag }}" >> "$GITHUB_ENV"
echo "BUILD_CACHE_IMAGE=ghcr.io/autowarefoundation/${{ env.IMAGE_NAME }}:${{ matrix.image_tag }}" >> "$GITHUB_ENV"
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Check if build cache image exists
id: check_image
run: |
echo "🔍 Checking if build cache image exists..."
if skopeo inspect --raw docker://${{ env.BUILD_CACHE_IMAGE }} > /dev/null 2>&1; then
echo "✅ Build cache image found. Proceeding..."
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "⚠️ Build cache image does not exist. Skipping remaining steps."
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Calculate cache size
id: calc_size
if: steps.check_image.outputs.exists == 'true'
run: |
echo "🔍 Inspecting build cache size for image: ${{ env.BUILD_CACHE_IMAGE }}..."
SIZE_BYTES=$(skopeo inspect --raw docker://${{ env.BUILD_CACHE_IMAGE }} | jq '.layers | map(.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_OUTPUT"
- name: Compare cache size with threshold
id: check_threshold
if: steps.check_image.outputs.exists == 'true'
run: |
echo "📊 Checking cache size against threshold..."
THRESHOLD_GB=${{ env.CACHE_THRESHOLD_GB }}
CACHE_SIZE_GB=${{ steps.calc_size.outputs.size_gb }}
if (( $(echo "$CACHE_SIZE_GB > $THRESHOLD_GB" | bc -l) )); then
echo "❌ Cache size exceeds threshold. Action needed."
echo "status=exceeded" >> "$GITHUB_OUTPUT"
else
echo "✅ Cache size is within threshold. No action needed."
echo "status=ok" >> "$GITHUB_OUTPUT"
fi
- name: Delete build cache if exceeded
uses: bots-house/ghcr-delete-image-action@v1.1.0
if: steps.check_threshold.outputs.status == 'exceeded'
with:
name: ${{ env.IMAGE_NAME }}
tag: ${{ matrix.image_tag }}
owner: ${{ github.repository_owner }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Verify cache deletion
if: steps.check_threshold.outputs.status == 'exceeded'
id: verify_deletion
run: |
echo "🔍 Verifying if build cache image has been deleted..."
if skopeo inspect --raw docker://${{ env.BUILD_CACHE_IMAGE }} > /dev/null 2>&1; then
echo "❌ Build cache image still exists!"
echo "status=failed" >> "$GITHUB_OUTPUT"
exit 1
else
echo "✅ Build cache image successfully deleted."
echo "status=success" >> "$GITHUB_OUTPUT"
fi
- name: Generate workflow summary
if: always()
run: |
SUMMARY="# 📦 Build Cache Size Check\n"
SUMMARY+="- **Image**: \`${{ env.BUILD_CACHE_IMAGE }}\`\n"
if [[ "${{ steps.check_image.outputs.exists }}" == "false" ]]; then
SUMMARY+="⚠️ **Build cache image does not exist. Skipping checks.**\n"
else
SUMMARY+="- **Cache Size**: ${{ steps.calc_size.outputs.size_gb }} GB\n"
SUMMARY+="- **Threshold**: ${{ env.CACHE_THRESHOLD_GB }} GB\n"
if [[ "${{ steps.check_threshold.outputs.status }}" == "exceeded" ]]; then
if [[ "${{ steps.verify_deletion.outputs.status }}" != "success" ]]; then
SUMMARY+="❌ **Cache size exceeded, but deletion failed!**\n"
else
SUMMARY+="🗑️✅ **Cache size exceeded. Image deleted successfully!**\n"
fi
else
SUMMARY+="👌✅ **Cache size is within acceptable limits.**\n"
fi
fi
echo -e "$SUMMARY"
echo -e "$SUMMARY" >> $GITHUB_STEP_SUMMARY