-
Notifications
You must be signed in to change notification settings - Fork 51
423 lines (375 loc) · 15.8 KB
/
ci-a2a-sub-agent.yml
File metadata and controls
423 lines (375 loc) · 15.8 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
name: "[CI][A2A] Sub-Agents A2A Docker Build and Push"
description: "Build and push A2A Docker images for sub-agents"
on:
# Trigger on push to main to detect changes and build/retag images
push:
branches:
- main
paths:
- 'ai_platform_engineering/**'
- 'build/**'
- 'pyproject.toml'
- 'uv.lock'
# Build on all manual new tags as well
tags:
- '**'
pull_request:
branches:
- main
paths:
- 'ai_platform_engineering/utils/**'
- 'ai_platform_engineering/agents/**'
- 'build/agents/Dockerfile.a2a'
workflow_dispatch:
inputs:
build_all:
description: 'Build all containers (skip change detection)'
required: false
default: false
type: boolean
tag_version:
description: 'Version tag to apply (e.g., 0.2.8-rc.1). If provided, unchanged agents will be retagged from previous version.'
required: false
type: string
jobs:
load-config:
runs-on: ubuntu-latest
if: always()
outputs:
all_agents: ${{ steps.read-config.outputs.all_agents }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
sparse-checkout: .github/agents.json
sparse-checkout-cone-mode: false
- name: Read agents config
id: read-config
run: |
ALL_AGENTS=$(jq -c '.a2a_agents' .github/agents.json)
echo "all_agents=$ALL_AGENTS" >> $GITHUB_OUTPUT
determine-agents:
runs-on: ubuntu-latest
needs: load-config
if: |
((github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))) ||
(github.event_name == 'pull_request' && !startsWith(github.head_ref, 'prebuild/')) ||
(github.event_name == 'workflow_dispatch')
outputs:
agents_to_build: ${{ steps.set-matrix.outputs.agents_to_build }}
agents_to_retag: ${{ steps.set-matrix.outputs.agents_to_retag }}
should_build: ${{ steps.set-matrix.outputs.should_build }}
should_retag: ${{ steps.set-matrix.outputs.should_retag }}
tag_version: ${{ steps.version.outputs.tag_version }}
env:
ALL_AGENTS: ${{ needs.load-config.outputs.all_agents }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Determine Tag
id: version
uses: ./.github/actions/determine-release-tag
with:
manual_tag: ${{ inputs.tag_version }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate path filters
id: generate-filters
uses: actions/github-script@v8
with:
script: |
const agents = JSON.parse(process.env.ALL_AGENTS);
let filters = 'shared_utils:\n';
filters += ' - \'ai_platform_engineering/utils/**\'\n';
filters += 'shared_config:\n';
filters += ' - \'pyproject.toml\'\n';
filters += ' - \'uv.lock\'\n';
filters += 'shared_dockerfile:\n';
filters += ' - \'build/agents/Dockerfile.a2a\'\n';
agents.forEach(agent => {
filters += `${agent}:\n`;
filters += ` - 'ai_platform_engineering/agents/${agent}/**'\n`;
filters += ` - '!ai_platform_engineering/agents/${agent}/mcp/**'\n`;
filters += ` - '!ai_platform_engineering/agents/${agent}/build/Dockerfile.mcp'\n`;
});
core.setOutput('filters', filters);
- name: Detect changed paths
id: filter
uses: dorny/paths-filter@v4
with:
predicate-quantifier: 'every'
filters: ${{ steps.generate-filters.outputs.filters }}
- name: Set matrix based on changes
id: set-matrix
uses: actions/github-script@v8
env:
FILTER_OUTPUTS: ${{ toJson(steps.filter.outputs) }}
TAG_VERSION: ${{ steps.version.outputs.tag_version }}
MANUAL_BUILD_ALL: ${{ inputs.build_all || 'false' }}
with:
script: |
const allAgents = JSON.parse(process.env.ALL_AGENTS);
const filterOutputs = JSON.parse(process.env.FILTER_OUTPUTS);
const tagVersion = process.env.TAG_VERSION;
const manualBuildAll = process.env.MANUAL_BUILD_ALL === 'true';
const isRc = /-rc\.\d+$/.test(tagVersion);
const isSharedChanged = filterOutputs.shared_utils === 'true' ||
filterOutputs.shared_config === 'true' ||
filterOutputs.shared_dockerfile === 'true';
// "Truly Build All" if:
// 1. Manual build_all input is true
// 2. Shared files (utils, config, dockerfile) changed
// 3. We have a tag, but it's NOT an RC tag (e.g. final release)
const shouldForceBuildAll = manualBuildAll || isSharedChanged || (tagVersion && !isRc);
let agentsToBuild;
let agentsToRetag = [];
if (shouldForceBuildAll) {
console.log("🚀 Forced 'Build All' mode activated");
agentsToBuild = allAgents;
agentsToRetag = [];
} else if (isRc) {
console.log(`🏷️ RC Tag detected (${tagVersion}): Using Build vs. Retag optimization`);
agentsToBuild = allAgents.filter(a => filterOutputs[a] === 'true');
agentsToRetag = allAgents.filter(a => filterOutputs[a] !== 'true');
} else {
console.log("🔍 Standard PR/Push: Building only changed agents");
agentsToBuild = allAgents.filter(a => filterOutputs[a] === 'true');
agentsToRetag = [];
}
core.setOutput('agents_to_build', JSON.stringify(agentsToBuild));
core.setOutput('agents_to_retag', JSON.stringify(agentsToRetag));
core.setOutput('should_build', String(agentsToBuild.length > 0));
core.setOutput('should_retag', String(agentsToRetag.length > 0 && !!tagVersion));
console.log(`Agents to build: ${agentsToBuild.join(', ') || 'none'}`);
console.log(`Agents to retag: ${agentsToRetag.join(', ') || 'none'}`);
build-and-push:
runs-on: ubuntu-latest
needs: [determine-agents, load-config]
if: (needs.determine-agents.outputs.should_build == 'true' && (github.event_name != 'pull_request' || !startsWith(github.head_ref, 'prebuild/')))
permissions:
contents: read
packages: write
strategy:
matrix:
agent: ${{ fromJson(needs.determine-agents.outputs.agents_to_build) }}
fail-fast: false
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/agent-${{ matrix.agent }}
AGENT_DIR: ai_platform_engineering/agents/${{ matrix.agent }}
steps:
- name: 🔒 harden runner
uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
with:
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main' }}
type=raw,value=${{ needs.determine-agents.outputs.tag_version }},enable=${{ needs.determine-agents.outputs.tag_version != '' }}
type=ref,event=branch,prefix=
type=ref,event=tag,prefix=
type=sha,format=short,prefix=
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Determine Dockerfile path
id: dockerfile
run: |
if [ -f "${{ env.AGENT_DIR }}/build/Dockerfile.a2a" ]; then
echo "path=${{ env.AGENT_DIR }}/build/Dockerfile.a2a" >> $GITHUB_OUTPUT
else
echo "path=build/agents/Dockerfile.a2a" >> $GITHUB_OUTPUT
fi
- name: Determine Agent Package Name
id: agent_package
run: |
# Special case: template agent uses agent_petstore package
if [ "${{ matrix.agent }}" == "template" ]; then
echo "name=petstore" >> $GITHUB_OUTPUT
else
echo "name=${{ matrix.agent }}" >> $GITHUB_OUTPUT
fi
- name: Build and Push A2A Docker image
uses: docker/build-push-action@v7
with:
context: .
file: ${{ steps.dockerfile.outputs.path }}
push: ${{ github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
AGENT_NAME=${{ matrix.agent }}
AGENT_PACKAGE=${{ steps.agent_package.outputs.name }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
# Retag unchanged agents from previous version when tag_version is provided
# If source image doesn't exist (still building), falls back to full build
retag-unchanged:
runs-on: ubuntu-latest
needs: determine-agents
if: needs.determine-agents.outputs.should_retag == 'true'
permissions:
contents: read
packages: write
strategy:
matrix:
agent: ${{ fromJson(needs.determine-agents.outputs.agents_to_retag) }}
fail-fast: false
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/agent-${{ matrix.agent }}
AGENT_DIR: ai_platform_engineering/agents/${{ matrix.agent }}
steps:
- name: 🔒 Harden runner
uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
with:
egress-policy: audit
- name: 📦 Install crane
run: |
VERSION="v0.20.2"
curl -sL "https://github.com/google/go-containerregistry/releases/download/${VERSION}/go-containerregistry_Linux_x86_64.tar.gz" | tar xz crane
sudo mv crane /usr/local/bin/
- name: 🔐 Log in to registry
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "$GH_TOKEN" | crane auth login ghcr.io -u ${{ github.actor }} --password-stdin
- name: 🔍 Check source image and retag or build
id: retag-or-build
env:
TAG_VERSION: ${{ needs.determine-agents.outputs.tag_version }}
run: |
FULL_IMAGE="${REGISTRY}/${IMAGE_NAME}"
echo "🏷️ Processing agent-${{ matrix.agent }}..."
# Determine source tag (previous version)
if [[ "$TAG_VERSION" =~ ^(.+)-rc\.([0-9]+)$ ]]; then
BASE_VERSION="${BASH_REMATCH[1]}"
RC_NUM="${BASH_REMATCH[2]}"
if [[ "$RC_NUM" -gt 1 ]]; then
PREV_RC=$((RC_NUM - 1))
SOURCE_TAG="${BASE_VERSION}-rc.${PREV_RC}"
else
SOURCE_TAG="${BASE_VERSION}"
fi
else
SOURCE_TAG="latest"
fi
echo " Source: ${SOURCE_TAG}"
echo " Target: ${TAG_VERSION}"
# Check if source image exists
if crane manifest "${FULL_IMAGE}:${SOURCE_TAG}" >/dev/null 2>&1; then
echo " ✅ Source image exists, retagging..."
if crane tag "${FULL_IMAGE}:${SOURCE_TAG}" "${TAG_VERSION}"; then
echo " ✅ Successfully retagged from ${SOURCE_TAG}"
echo "needs_build=false" >> $GITHUB_OUTPUT
else
echo " ⚠️ Retag failed unexpectedly, will build instead"
echo "needs_build=true" >> $GITHUB_OUTPUT
fi
else
echo " ⚠️ Source image ${SOURCE_TAG} not found (may still be building)"
echo " 📦 Will build fresh instead of using stale fallback"
echo "needs_build=true" >> $GITHUB_OUTPUT
fi
# Fallback build if retag not possible
- name: Checkout repository
if: steps.retag-or-build.outputs.needs_build == 'true'
uses: actions/checkout@v6
- name: Set up Docker Buildx
if: steps.retag-or-build.outputs.needs_build == 'true'
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
if: steps.retag-or-build.outputs.needs_build == 'true'
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
if: steps.retag-or-build.outputs.needs_build == 'true'
uses: docker/setup-qemu-action@v4
- name: Determine Dockerfile path
if: steps.retag-or-build.outputs.needs_build == 'true'
id: dockerfile
run: |
if [ -f "${{ env.AGENT_DIR }}/build/Dockerfile.a2a" ]; then
echo "path=${{ env.AGENT_DIR }}/build/Dockerfile.a2a" >> $GITHUB_OUTPUT
else
echo "path=build/agents/Dockerfile.a2a" >> $GITHUB_OUTPUT
fi
- name: Determine Agent Package Name
if: steps.retag-or-build.outputs.needs_build == 'true'
id: agent_package
run: |
if [ "${{ matrix.agent }}" == "template" ]; then
echo "name=petstore" >> $GITHUB_OUTPUT
else
echo "name=${{ matrix.agent }}" >> $GITHUB_OUTPUT
fi
- name: 🔨 Build and Push (fallback)
if: steps.retag-or-build.outputs.needs_build == 'true'
uses: docker/build-push-action@v7
with:
context: .
file: ${{ steps.dockerfile.outputs.path }}
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.determine-agents.outputs.tag_version }}
build-args: |
AGENT_NAME=${{ matrix.agent }}
AGENT_PACKAGE=${{ steps.agent_package.outputs.name }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
# Notify release-finalize workflow when this CI completes (for final release builds only)
notify-release:
runs-on: ubuntu-latest
needs: [determine-agents, build-and-push, retag-unchanged]
# Only notify for final releases (non-RC tags) - RC builds don't need release finalization
if: |
always() &&
needs.determine-agents.outputs.tag_version != '' &&
!contains(needs.determine-agents.outputs.tag_version, '-rc.')
steps:
- name: 🔔 Notify release finalize
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_VERSION: ${{ needs.determine-agents.outputs.tag_version }}
run: |
# Determine overall conclusion
BUILD_RESULT="${{ needs.build-and-push.result }}"
RETAG_RESULT="${{ needs.retag-unchanged.result }}"
# Consider skipped as success (job conditions not met)
if [[ "$BUILD_RESULT" == "skipped" ]]; then BUILD_RESULT="success"; fi
if [[ "$RETAG_RESULT" == "skipped" ]]; then RETAG_RESULT="success"; fi
if [[ "$BUILD_RESULT" == "success" && "$RETAG_RESULT" == "success" ]]; then
CONCLUSION="success"
else
CONCLUSION="failure"
fi
echo "🔔 Notifying release-finalize: tag=$TAG_VERSION, conclusion=$CONCLUSION"
gh api /repos/${{ github.repository }}/dispatches --input - <<EOF
{
"event_type": "ci-completed",
"client_payload": {
"tag": "$TAG_VERSION",
"workflow": "${{ github.workflow }}",
"conclusion": "$CONCLUSION"
}
}
EOF