-
Notifications
You must be signed in to change notification settings - Fork 215
717 lines (614 loc) · 30.3 KB
/
server.yml
File metadata and controls
717 lines (614 loc) · 30.3 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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
---
name: Agent Server
on:
push:
branches: [main]
tags:
- '*' # Trigger on any tag (e.g., 1.0.0, 1.0.0a5, build-docker)
pull_request:
branches: [main]
workflow_dispatch:
inputs:
base_image:
description: Base runtime image
type: string
default: nikolaik/python-nodejs:python3.13-nodejs22-slim
image:
description: GHCR image name
type: string
default: ghcr.io/openhands/agent-server
platforms:
description: Target platforms
type: string
default: linux/amd64,linux/arm64
permissions:
contents: read
packages: write
jobs:
build-binary-and-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
version: latest
python-version: '3.13'
- name: Install dependencies
run: uv sync --dev
- name: Build binary
run: |
make build-server
# FIXME: windows-latest not working due to
# Run if [[ "windows-latest" == "windows-latest" ]]; then
# [PYI-2160:ERROR] Failed to load Python DLL 'C:\Users\RUNNER~1\AppData\Local\Temp\_MEI5602\python312.dll'.
# LoadLibrary: Invalid access to memory location.
# - name: Test binary (Windows)
# if: matrix.os == 'windows-latest'
# shell: pwsh
# run: |
# Get-ChildItem dist
# .\dist\openhands-agent-server.exe --help
- name: Test binary (Linux and macOS)
if: matrix.os != 'windows-latest'
shell: bash
run: |
# Test help command
./dist/openhands-agent-server --help
# Test server startup and template loading
echo "Testing server startup and template loading..."
./dist/openhands-agent-server --port 8002 > server_test.log 2>&1 &
SERVER_PID=$!
# Wait for server to start
sleep 5
# Check if server started successfully (no template errors)
if grep -q "system_prompt.j2.*not found" server_test.log; then
echo "ERROR: Template files not found in binary!"
cat server_test.log
kill $SERVER_PID 2>/dev/null || true
exit 1
fi
# Check if server is running
if ! kill -0 $SERVER_PID 2>/dev/null; then
echo "ERROR: Server failed to start!"
cat server_test.log
exit 1
fi
# Test basic API endpoint
if command -v curl >/dev/null 2>&1; then
echo "Testing basic API endpoint..."
if curl -f -s http://localhost:8002/health >/dev/null 2>&1; then
echo "✓ Health endpoint accessible"
else
echo "⚠ Health endpoint not accessible (may be expected)"
fi
fi
# Clean up
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
rm -f server_test.log
echo "✓ Binary test completed successfully"
- name: Upload binary artifact
uses: actions/upload-artifact@v5
with:
name: openhands-server-${{ matrix.os }}
path: |
dist/openhands-server*
retention-days: 7
check-openapi-schema:
name: Check OpenAPI Schema
runs-on: ubuntu-24.04
steps:
- name: Checkout PR branch
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
version: latest
python-version: '3.13'
- name: Install Node.js (for npx)
uses: actions/setup-node@v6
with:
node-version: 22
- name: Install dependencies
run: |
uv sync --frozen --dev
- name: Check OpenAPI JSON and build client
env:
PYTHONPATH: .
run: |
make test-server-schema
build-and-push-image:
name: Build & Push (${{ matrix.variant }}-${{ matrix.arch }})
# Run on push events, pull requests from the same repository (not forks), and manual workflow_dispatch
# Fork PRs cannot push to GHCR and would fail authentication
if: >
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' &&
!github.event.pull_request.head.repo.fork)
strategy:
fail-fast: false
matrix:
# Explicit matrix: 3 variants × 2 architectures = 6 jobs
# Each job specifies exactly what it builds and where it runs
include:
# Python variant
# NOTE: Using Python 3.12 due to PyInstaller+libtmux compatibility
# issue with Python 3.13. See issue #1886 for details.
- variant: python
arch: amd64
base_image: nikolaik/python-nodejs:python3.12-nodejs22
runner: ubuntu-24.04
platform: linux/amd64
- variant: python
arch: arm64
base_image: nikolaik/python-nodejs:python3.12-nodejs22
runner: ubuntu-24.04-arm
platform: linux/arm64
# Java variant
- variant: java
arch: amd64
base_image: eclipse-temurin:17-jdk
runner: ubuntu-24.04
platform: linux/amd64
- variant: java
arch: arm64
base_image: eclipse-temurin:17-jdk
runner: ubuntu-24.04-arm
platform: linux/arm64
# Golang variant
- variant: golang
arch: amd64
base_image: golang:1.21-bookworm
runner: ubuntu-24.04
platform: linux/amd64
- variant: golang
arch: arm64
base_image: golang:1.21-bookworm
runner: ubuntu-24.04-arm
platform: linux/arm64
runs-on: ${{ matrix.runner }}
env:
IMAGE: ${{ inputs.image != '' && inputs.image || 'ghcr.io/openhands/agent-server' }}
BASE_IMAGE: ${{ inputs.base_image != '' && inputs.base_image || matrix.base_image }}
CUSTOM_TAGS: ${{ matrix.variant }}
VARIANT: ${{ matrix.variant }}
ARCH: ${{ matrix.arch }}
TARGET: binary
PLATFORM: ${{ matrix.platform }}
# Use PR head SHA for pull requests to match the image tag expected by run-examples.yml
GITHUB_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
GITHUB_REF: ${{ github.ref }}
CI: 'true'
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
version: latest
python-version: '3.13'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare build context and metadata
id: prep
run: |
uv sync --frozen
# Generate build context and tags with arch suffix
# build.py now handles architecture tagging internally via --arch flag
# Add --versioned-tag when triggered by a git tag (e.g., v1.0.0)
BUILD_CMD="uv run ./openhands-agent-server/openhands/agent_server/docker/build.py --build-ctx-only --arch ${{ matrix.arch }}"
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
BUILD_CMD="$BUILD_CMD --versioned-tag"
fi
eval "$BUILD_CMD"
# Alias tags_csv output to tags for the build action
TAGS=$(grep '^tags_csv=' $GITHUB_OUTPUT | cut -d= -f2-)
echo "tags=$TAGS" >> $GITHUB_OUTPUT
# Extract short SHA for consolidation
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT
# Extract versioned tags CSV for consolidation
VERSIONED_TAGS_CSV=$(grep '^versioned_tags_csv=' $GITHUB_OUTPUT | cut -d= -f2- || echo "")
echo "versioned_tags_csv=$VERSIONED_TAGS_CSV" >> $GITHUB_OUTPUT
# Verify outputs
echo "=== Build outputs ==="
echo "Build context: $(grep '^build_context=' $GITHUB_OUTPUT | cut -d= -f2-)"
echo "Tags: $TAGS"
echo "Short SHA: $SHORT_SHA"
echo "Versioned tags: $VERSIONED_TAGS_CSV"
echo "===================="
- name: Build & Push (${{ matrix.variant }}-${{ matrix.arch }})
id: build
uses: docker/build-push-action@v6
with:
context: ${{ steps.prep.outputs.build_context }}
file: ${{ steps.prep.outputs.dockerfile }}
target: ${{ env.TARGET }}
platforms: ${{ env.PLATFORM }}
push: true
tags: ${{ steps.prep.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BASE_IMAGE=${{ env.BASE_IMAGE }}
- name: Cleanup build context
if: always()
run: |
if [ -n "${{ steps.prep.outputs.build_context }}" ] && [ -d "${{ steps.prep.outputs.build_context }}" ]; then
echo "Cleaning up build context: ${{ steps.prep.outputs.build_context }}"
rm -rf "${{ steps.prep.outputs.build_context }}"
fi
- name: Summary (${{ matrix.variant }}-${{ matrix.arch }}) - outputs
run: |
echo "Image: ${{ env.IMAGE }}"
echo "Variant: ${{ env.VARIANT }}"
echo "Architecture: ${{ env.ARCH }}"
echo "Platform: ${{ env.PLATFORM }}"
echo "Short SHA: ${{ steps.prep.outputs.short_sha }}"
echo "Tags: ${{ steps.prep.outputs.tags }}"
echo "Build digest: ${{ steps.build.outputs.digest }}"
- name: Save build info for consolidation
run: |
mkdir -p build-info
cat > "build-info/${{ matrix.variant }}-${{ matrix.arch }}.json" << EOF
{
"variant": "${{ matrix.variant }}",
"arch": "${{ matrix.arch }}",
"base_image": "${{ matrix.base_image }}",
"image": "${{ env.IMAGE }}",
"short_sha": "${{ steps.prep.outputs.short_sha }}",
"tags": "${{ steps.prep.outputs.tags }}",
"versioned_tags_csv": "${{ steps.prep.outputs.versioned_tags_csv }}",
"platform": "${{ env.PLATFORM }}"
}
EOF
- name: Upload build info artifact
uses: actions/upload-artifact@v5
with:
name: build-info-${{ matrix.variant }}-${{ matrix.arch }}
path: build-info/${{ matrix.variant }}-${{ matrix.arch }}.json
retention-days: 1
merge-manifests:
name: Merge Multi-Arch Manifests
needs: build-and-push-image
if: >
github.event_name == 'push' ||
(github.event_name == 'pull_request' &&
!github.event.pull_request.head.repo.fork)
runs-on: ubuntu-24.04
strategy:
matrix:
variant: [python, java, golang]
env:
IMAGE: ${{ inputs.image != '' && inputs.image || 'ghcr.io/openhands/agent-server' }}
steps:
- name: Download build info to extract SHORT_SHA
uses: actions/download-artifact@v6
with:
pattern: build-info-${{ matrix.variant }}-*
merge-multiple: true
path: build-info
- name: Extract SHORT_SHA from build info
id: get_sha
run: |
# Get SHORT_SHA from any build info artifact for this variant
SHORT_SHA=$(jq -r '.short_sha' build-info/${{ matrix.variant }}-amd64.json)
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT
echo "Using SHORT_SHA: $SHORT_SHA"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push multi-arch manifest for ${{ matrix.variant }}
id: create_manifest
run: |
SHORT_SHA=${{ steps.get_sha.outputs.short_sha }}
VARIANT=${{ matrix.variant }}
MANIFEST_TAG="${SHORT_SHA}-${VARIANT}"
# Create multi-arch manifest combining amd64 and arm64 using buildx imagetools
# This properly handles manifest lists from Docker builds
echo "Creating multi-arch manifest: ${IMAGE}:${MANIFEST_TAG}"
docker buildx imagetools create -t ${IMAGE}:${MANIFEST_TAG} \
${IMAGE}:${SHORT_SHA}-${VARIANT}-amd64 \
${IMAGE}:${SHORT_SHA}-${VARIANT}-arm64
# Verify the multi-arch manifest
echo "Inspecting multi-arch manifest:"
docker buildx imagetools inspect ${IMAGE}:${MANIFEST_TAG}
echo "✓ Multi-arch manifest created: ${IMAGE}:${MANIFEST_TAG}"
# Create latest manifest if on main branch
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
LATEST_TAG="latest-${VARIANT}"
echo "Creating latest multi-arch manifest: ${IMAGE}:${LATEST_TAG}"
docker buildx imagetools create -t ${IMAGE}:${LATEST_TAG} \
${IMAGE}:main-${VARIANT}-amd64 \
${IMAGE}:main-${VARIANT}-arm64
echo "Inspecting latest multi-arch manifest:"
docker buildx imagetools inspect ${IMAGE}:${LATEST_TAG}
echo "✓ Latest multi-arch manifest created: ${IMAGE}:${LATEST_TAG}"
MANIFEST_TAG="${MANIFEST_TAG},${LATEST_TAG}"
fi
# Create versioned manifests if triggered by a git tag
# Extract versioned tags from build info (format: "1.2.0-python,1.2.0-java")
VERSIONED_TAGS_CSV=$(jq -r '.versioned_tags_csv' build-info/${VARIANT}-amd64.json)
if [ -n "$VERSIONED_TAGS_CSV" ] && [ "$VERSIONED_TAGS_CSV" != "null" ] && [ "$VERSIONED_TAGS_CSV" != "" ]; then
echo "Found versioned tags: $VERSIONED_TAGS_CSV"
# Split CSV and create manifest for each versioned tag
IFS=',' read -ra VERSIONED_TAGS <<< "$VERSIONED_TAGS_CSV"
for VERSIONED_TAG in "${VERSIONED_TAGS[@]}"; do
if [ -n "$VERSIONED_TAG" ]; then
echo "Creating versioned multi-arch manifest: ${IMAGE}:${VERSIONED_TAG}"
docker buildx imagetools create -t ${IMAGE}:${VERSIONED_TAG} \
${IMAGE}:${VERSIONED_TAG}-amd64 \
${IMAGE}:${VERSIONED_TAG}-arm64
echo "Inspecting versioned multi-arch manifest:"
docker buildx imagetools inspect ${IMAGE}:${VERSIONED_TAG}
echo "✓ Versioned multi-arch manifest created: ${IMAGE}:${VERSIONED_TAG}"
MANIFEST_TAG="${MANIFEST_TAG},${VERSIONED_TAG}"
fi
done
fi
# Save manifest info for consolidation
mkdir -p manifest-info
cat > "manifest-info/${VARIANT}.json" << EOF
{
"variant": "${VARIANT}",
"image": "${IMAGE}",
"short_sha": "${SHORT_SHA}",
"manifest_tag": "${MANIFEST_TAG}"
}
EOF
- name: Upload manifest info artifact
uses: actions/upload-artifact@v5
with:
name: manifest-info-${{ matrix.variant }}
path: manifest-info/${{ matrix.variant }}.json
retention-days: 1
consolidate-build-info:
name: Consolidate Build Information
needs: [build-and-push-image, merge-manifests]
# Run if it's a PR and the matrix job completed (even if some variants failed)
if: github.event_name == 'pull_request' && always() && (needs.build-and-push-image.result == 'success' || needs.build-and-push-image.result ==
'failure')
runs-on: ubuntu-24.04
outputs:
build_summary: ${{ steps.consolidate.outputs.build_summary }}
steps:
- name: Download build info artifacts
uses: actions/download-artifact@v6
with:
pattern: build-info-*
merge-multiple: true
path: build-info
- name: Download manifest info artifacts
uses: actions/download-artifact@v6
with:
pattern: manifest-info-*
merge-multiple: true
path: manifest-info
- name: Consolidate build information from artifacts
id: consolidate
run: |
echo "Processing build info artifacts..."
ls -la build-info/
echo "Found $(ls build-info/*.json 2>/dev/null | wc -l) JSON files"
# Initialize variables
IMAGE=""
SHORT_SHA=""
ALL_TAGS=""
# Use associative arrays to track variants (bash 4+)
declare -A VARIANT_BASE_IMAGE
declare -A VARIANT_ARCHS
# Process each build info
for info_file in build-info/*.json; do
if [[ ! -f "$info_file" ]]; then
echo "Skipping $info_file - not a file"
continue
fi
echo "=== Processing $info_file ==="
cat "$info_file"
echo "=== End of $info_file ==="
# Extract information from JSON
VARIANT=$(jq -r '.variant' "$info_file")
ARCH=$(jq -r '.arch' "$info_file")
BASE_IMAGE=$(jq -r '.base_image' "$info_file")
VARIANT_IMAGE=$(jq -r '.image' "$info_file")
VARIANT_SHA=$(jq -r '.short_sha' "$info_file")
VARIANT_TAGS=$(jq -r '.tags' "$info_file")
# Set common values (same across all builds)
if [[ -z "$IMAGE" ]]; then
IMAGE="$VARIANT_IMAGE"
SHORT_SHA="$VARIANT_SHA"
fi
# Store variant information
VARIANT_BASE_IMAGE[$VARIANT]=$BASE_IMAGE
if [[ -z "${VARIANT_ARCHS[$VARIANT]}" ]]; then
VARIANT_ARCHS[$VARIANT]=$ARCH
else
VARIANT_ARCHS[$VARIANT]="${VARIANT_ARCHS[$VARIANT]}, $ARCH"
fi
# Collect tags (comma-separated to newline-separated)
if [[ -n "$VARIANT_TAGS" ]]; then
VARIANT_TAG_LIST=$(echo "$VARIANT_TAGS" | tr ',' '\n')
if [[ -n "$ALL_TAGS" ]]; then
ALL_TAGS="${ALL_TAGS}"$'\n'"${VARIANT_TAG_LIST}"
else
ALL_TAGS="$VARIANT_TAG_LIST"
fi
fi
done
# Build variants JSON array from collected data
VARIANTS_JSON="[]"
for VARIANT in "${!VARIANT_BASE_IMAGE[@]}"; do
BASE_IMG="${VARIANT_BASE_IMAGE[$VARIANT]}"
ARCHS="${VARIANT_ARCHS[$VARIANT]}"
VARIANTS_JSON=$(echo "$VARIANTS_JSON" | jq \
--arg variant "$VARIANT" \
--arg base_image "$BASE_IMG" \
--arg archs "$ARCHS" \
'. += [{custom_tags: $variant, base_image: $base_image, architectures: $archs}]')
echo "Added variant $VARIANT ($ARCHS), current variants JSON:"
echo "$VARIANTS_JSON" | jq .
done
# Process manifest info artifacts
echo "Processing manifest info artifacts..."
if [[ -d "manifest-info" ]]; then
ls -la manifest-info/
MANIFEST_TAGS=""
for manifest_file in manifest-info/*.json; do
if [[ -f "$manifest_file" ]]; then
echo "=== Processing $manifest_file ==="
cat "$manifest_file"
MANIFEST_TAG_CSV=$(jq -r '.manifest_tag' "$manifest_file")
# Convert comma-separated tags to newline-separated
MANIFEST_TAG_LIST=$(echo "$MANIFEST_TAG_CSV" | tr ',' '\n' | sed "s|^|${IMAGE}:|")
if [[ -n "$MANIFEST_TAGS" ]]; then
MANIFEST_TAGS="${MANIFEST_TAGS}"$'\n'"${MANIFEST_TAG_LIST}"
else
MANIFEST_TAGS="$MANIFEST_TAG_LIST"
fi
fi
done
# Add manifest tags to ALL_TAGS
if [[ -n "$MANIFEST_TAGS" ]]; then
echo "Adding manifest tags to output"
if [[ -n "$ALL_TAGS" ]]; then
ALL_TAGS="${ALL_TAGS}"$'\n'"${MANIFEST_TAGS}"
else
ALL_TAGS="$MANIFEST_TAGS"
fi
fi
else
echo "No manifest-info directory found (merge-manifests may not have run)"
fi
# Create consolidated build summary
BUILD_SUMMARY=$(jq -n \
--arg image "$IMAGE" \
--arg short_sha "$SHORT_SHA" \
--arg ghcr_url "https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server" \
--arg all_tags "$ALL_TAGS" \
--argjson variants "$VARIANTS_JSON" \
'{
image: $image,
short_sha: $short_sha,
ghcr_package_url: $ghcr_url,
all_tags: $all_tags,
variants: $variants
}')
echo "Consolidated build summary:"
echo "$BUILD_SUMMARY" | jq .
echo "DEBUG: Final variants count: $(echo "$VARIANTS_JSON" | jq 'length')"
echo "DEBUG: Final variants: $(echo "$VARIANTS_JSON" | jq -c '.')"
# Set output
{
echo 'build_summary<<EOF'
echo "$BUILD_SUMMARY"
echo 'EOF'
} >> $GITHUB_OUTPUT
update-pr-description:
name: Update PR description with agent server image
needs: consolidate-build-info
# Only on PRs, and only if the consolidation succeeded
if: github.event_name == 'pull_request' && needs.consolidate-build-info.result == 'success'
runs-on: ubuntu-24.04
permissions:
contents: read
pull-requests: write
steps:
- name: Generate PR description from build summary
id: generate_description
run: |
echo "Event: ${{ github.event_name }}"
echo "PR number: ${{ github.event.number }}"
echo "Run attempt: ${{ github.run_attempt }}"
# Parse the build summary JSON
BUILD_SUMMARY='${{ needs.consolidate-build-info.outputs.build_summary }}'
echo "Build summary received:"
echo "$BUILD_SUMMARY" | jq .
# Extract basic information
IMAGE=$(echo "$BUILD_SUMMARY" | jq -r '.image')
SHORT_SHA=$(echo "$BUILD_SUMMARY" | jq -r '.short_sha')
GHCR_URL=$(echo "$BUILD_SUMMARY" | jq -r '.ghcr_package_url')
ALL_TAGS=$(echo "$BUILD_SUMMARY" | jq -r '.all_tags')
# Build the variants table dynamically
VARIANTS_TABLE=""
# Process each build
VARIANTS=$(echo "$BUILD_SUMMARY" | jq -r '.variants[] | @base64')
echo "DEBUG: Found builds (base64 encoded):"
echo "$VARIANTS"
echo "DEBUG: Number of builds: $(echo "$VARIANTS" | wc -l)"
for variant_data in $VARIANTS; do
# Decode base64 and extract build info
VARIANT_JSON=$(echo "$variant_data" | base64 --decode)
echo "DEBUG: Processing build JSON: $VARIANT_JSON"
CUSTOM_TAGS=$(echo "$VARIANT_JSON" | jq -r '.custom_tags')
BASE_IMAGE=$(echo "$VARIANT_JSON" | jq -r '.base_image')
ARCHS=$(echo "$VARIANT_JSON" | jq -r '.architectures // "amd64, arm64"')
echo "DEBUG: Adding variant $CUSTOM_TAGS with base image $BASE_IMAGE (archs: $ARCHS)"
# Add to variants table with architecture info
VARIANTS_TABLE="${VARIANTS_TABLE}| ${CUSTOM_TAGS} | ${ARCHS} | \`${BASE_IMAGE}\` | [Link](https://hub.docker.com/_/${BASE_IMAGE}) |"$'\n'
done
echo "DEBUG: Final variants table:"
echo "$VARIANTS_TABLE"
# Create the complete PR description with the requested format
PR_CONTENT=$(cat << EOF
<!-- AGENT_SERVER_IMAGES_START -->
---
**Agent Server images for this PR**
• **GHCR package:** ${GHCR_URL}
**Variants & Base Images**
| Variant | Architectures | Base Image | Docs / Tags |
|---|---|---|---|
${VARIANTS_TABLE}
**Pull (multi-arch manifest)**
\`\`\`bash
# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ${IMAGE}:${SHORT_SHA}-python
\`\`\`
**Run**
\`\`\`bash
docker run -it --rm \\
-p 8000:8000 \\
--name agent-server-${SHORT_SHA}-python \\
${IMAGE}:${SHORT_SHA}-python
\`\`\`
**All tags pushed for this build**
\`\`\`
${ALL_TAGS}
\`\`\`
**About Multi-Architecture Support**
- Each variant tag (e.g., \`${SHORT_SHA}-python\`) is a **multi-arch manifest** supporting both **amd64** and **arm64**
- Docker automatically pulls the correct architecture for your platform
- Individual architecture tags (e.g., \`${SHORT_SHA}-python-amd64\`) are also available if needed
<!-- AGENT_SERVER_IMAGES_END -->
EOF
)
# Set output for the next step
{
echo 'pr_content<<EOF'
echo "$PR_CONTENT"
echo 'EOF'
} >> $GITHUB_OUTPUT
- name: Update PR description with docker image details
uses: nefrob/pr-description@v1.2.0
with:
content: ${{ steps.generate_description.outputs.pr_content }}
regex: <!-- AGENT_SERVER_IMAGES_START -->.*?<!-- AGENT_SERVER_IMAGES_END -->
regexFlags: s
token: ${{ secrets.GITHUB_TOKEN }}