|
| 1 | +# Copyright(C) 2025-2026 Advanced Micro Devices, Inc. All rights reserved. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +# Cross-compile matrix + static-binary packaging for the native (C++) Agent Hub |
| 5 | +# agents in cpp/. Each matrix leg builds the C++ example agents with static |
| 6 | +# linking (BUILD_SHARED_LIBS=OFF + vcpkg *-static triplet + static MSVC runtime) |
| 7 | +# so the artifacts have no runtime DLL/.so dependency, then packages each agent |
| 8 | +# into dist/<id>/ (binary + gaia-agent.yaml + checksums.sha256) and uploads it. |
| 9 | +# |
| 10 | +# On a version tag (v*), a release job consolidates every platform's artifacts |
| 11 | +# into a single bundle for downstream publishing (R2 / PyPI are handled by other |
| 12 | +# Agent Hub issues — this workflow only produces and uploads the artifacts). |
| 13 | +# |
| 14 | +# Static triplets: Windows uses the built-in x64-windows-static; Linux/macOS use |
| 15 | +# the overlay triplets in cpp/triplets/ (no built-in *-static there). |
| 16 | +# Manifests + the packaging script: cpp/agents/, cpp/packaging/package_agents.py |
| 17 | +# Issue: https://github.com/amd/gaia/issues/1094 |
| 18 | + |
| 19 | +name: Agent Binaries (C++) |
| 20 | + |
| 21 | +on: |
| 22 | + push: |
| 23 | + branches: [ main ] |
| 24 | + tags: [ 'v*' ] |
| 25 | + paths: |
| 26 | + - 'cpp/**' |
| 27 | + - '.github/workflows/build_agents.yml' |
| 28 | + pull_request: |
| 29 | + branches: [ main ] |
| 30 | + types: [opened, synchronize, reopened, ready_for_review] |
| 31 | + paths: |
| 32 | + - 'cpp/**' |
| 33 | + - '.github/workflows/build_agents.yml' |
| 34 | + merge_group: |
| 35 | + workflow_dispatch: |
| 36 | + |
| 37 | +concurrency: |
| 38 | + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} |
| 39 | + cancel-in-progress: true |
| 40 | + |
| 41 | +permissions: |
| 42 | + contents: read |
| 43 | + |
| 44 | +jobs: |
| 45 | + build: |
| 46 | + name: Package (${{ matrix.platform }}) |
| 47 | + runs-on: ${{ matrix.os }} |
| 48 | + if: github.event_name != 'pull_request' || github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'ready_for_ci') |
| 49 | + |
| 50 | + strategy: |
| 51 | + fail-fast: false |
| 52 | + matrix: |
| 53 | + include: |
| 54 | + - os: windows-latest |
| 55 | + platform: win-x64 |
| 56 | + triplet: x64-windows-static |
| 57 | + - os: ubuntu-latest |
| 58 | + platform: linux-x64 |
| 59 | + triplet: x64-linux-static |
| 60 | + - os: macos-latest |
| 61 | + platform: darwin-arm64 |
| 62 | + triplet: arm64-osx-static |
| 63 | + |
| 64 | + env: |
| 65 | + # vcpkg binary cache so static OpenSSL is built once and reused across runs. |
| 66 | + VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/.vcpkg-cache |
| 67 | + |
| 68 | + steps: |
| 69 | + - uses: actions/checkout@v6 |
| 70 | + |
| 71 | + - name: Set up Python |
| 72 | + uses: actions/setup-python@v6 |
| 73 | + with: |
| 74 | + python-version: '3.12' |
| 75 | + |
| 76 | + - name: Install packaging deps |
| 77 | + run: python -m pip install --upgrade pyyaml |
| 78 | + |
| 79 | + - name: Prepare vcpkg binary cache dir |
| 80 | + shell: bash |
| 81 | + run: mkdir -p "${VCPKG_DEFAULT_BINARY_CACHE}" |
| 82 | + |
| 83 | + - name: Restore vcpkg binary cache |
| 84 | + uses: actions/cache@v5 |
| 85 | + with: |
| 86 | + path: ${{ github.workspace }}/.vcpkg-cache |
| 87 | + key: vcpkg-${{ matrix.triplet }}-${{ hashFiles('cpp/vcpkg.json') }} |
| 88 | + restore-keys: | |
| 89 | + vcpkg-${{ matrix.triplet }}- |
| 90 | +
|
| 91 | + - name: Restore FetchContent cache |
| 92 | + uses: actions/cache@v5 |
| 93 | + with: |
| 94 | + path: cpp/build/_deps |
| 95 | + key: fetchcontent-agents-${{ matrix.platform }}-${{ hashFiles('cpp/CMakeLists.txt') }} |
| 96 | + |
| 97 | + - name: Install static OpenSSL via vcpkg (${{ matrix.triplet }}) |
| 98 | + shell: bash |
| 99 | + run: | |
| 100 | + set -euo pipefail |
| 101 | + if [ -z "${VCPKG_INSTALLATION_ROOT:-}" ]; then |
| 102 | + echo "::error::VCPKG_INSTALLATION_ROOT is not set on this runner" |
| 103 | + exit 1 |
| 104 | + fi |
| 105 | + # Linux/macOS have no built-in *-static triplet; cpp/triplets supplies |
| 106 | + # them as overlays (Windows still uses its built-in x64-windows-static). |
| 107 | + "${VCPKG_INSTALLATION_ROOT}/vcpkg" install "openssl:${{ matrix.triplet }}" \ |
| 108 | + --overlay-triplets="${GITHUB_WORKSPACE}/cpp/triplets" |
| 109 | +
|
| 110 | + - name: Configure CMake (static) |
| 111 | + shell: bash |
| 112 | + run: | |
| 113 | + set -euo pipefail |
| 114 | + cmake -B cpp/build -S cpp \ |
| 115 | + -DCMAKE_BUILD_TYPE=Release \ |
| 116 | + -DBUILD_SHARED_LIBS=OFF \ |
| 117 | + -DGAIA_BUILD_TESTS=OFF \ |
| 118 | + -DGAIA_BUILD_EXAMPLES=ON \ |
| 119 | + -DGAIA_BUILD_INTEGRATION_TESTS=OFF \ |
| 120 | + -DGAIA_BUILD_BENCHMARKS=OFF \ |
| 121 | + -DVCPKG_MANIFEST_MODE=OFF \ |
| 122 | + -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} \ |
| 123 | + -DVCPKG_OVERLAY_TRIPLETS="${GITHUB_WORKSPACE}/cpp/triplets" \ |
| 124 | + -DCMAKE_TOOLCHAIN_FILE="${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake" |
| 125 | +
|
| 126 | + - name: Build (Release) |
| 127 | + run: cmake --build cpp/build --config Release --parallel |
| 128 | + |
| 129 | + - name: Package agents for ${{ matrix.platform }} |
| 130 | + run: >- |
| 131 | + python cpp/packaging/package_agents.py |
| 132 | + --platform ${{ matrix.platform }} |
| 133 | + --build-dir cpp/build |
| 134 | + --agents-dir cpp/agents |
| 135 | + --out dist |
| 136 | +
|
| 137 | + - name: Show packaged artifacts |
| 138 | + shell: bash |
| 139 | + run: | |
| 140 | + echo "=== dist/ (${{ matrix.platform }}) ===" |
| 141 | + find dist -type f | sort |
| 142 | + echo |
| 143 | + echo "=== checksums ===" |
| 144 | + find dist -name checksums.sha256 -exec cat {} + |
| 145 | +
|
| 146 | + - name: Upload artifacts |
| 147 | + uses: actions/upload-artifact@v7 |
| 148 | + with: |
| 149 | + name: cpp-agents-${{ matrix.platform }} |
| 150 | + path: dist/ |
| 151 | + if-no-files-found: error |
| 152 | + |
| 153 | + # On a version tag, consolidate every platform's dist/ into one bundle so a |
| 154 | + # downstream job (R2 / PyPI — other issues) has a single artifact to publish. |
| 155 | + release-bundle: |
| 156 | + name: Consolidate release bundle |
| 157 | + runs-on: ubuntu-latest |
| 158 | + needs: [build] |
| 159 | + if: startsWith(github.ref, 'refs/tags/v') |
| 160 | + permissions: |
| 161 | + contents: read |
| 162 | + steps: |
| 163 | + - name: Download all platform artifacts |
| 164 | + uses: actions/download-artifact@v8 |
| 165 | + with: |
| 166 | + pattern: cpp-agents-* |
| 167 | + path: artifacts |
| 168 | + |
| 169 | + - name: Merge into release bundle |
| 170 | + shell: bash |
| 171 | + run: | |
| 172 | + set -euo pipefail |
| 173 | + mkdir -p bundle |
| 174 | + # Each artifact is artifacts/cpp-agents-<platform>/<id>/...; merge by id |
| 175 | + # so a single bundle/<id>/ holds every platform's binary + the manifest. |
| 176 | + # The per-leg checksums.sha256 files collide (same path per id), so drop |
| 177 | + # them here and regenerate complete per-agent + aggregate checksums from |
| 178 | + # the merged binaries below. |
| 179 | + for leg in artifacts/cpp-agents-*; do |
| 180 | + [ -d "$leg" ] || continue |
| 181 | + cp -r "$leg"/* bundle/ |
| 182 | + done |
| 183 | + find bundle -name checksums.sha256 -delete |
| 184 | +
|
| 185 | + : > bundle/CHECKSUMS.sha256 |
| 186 | + for agent_dir in bundle/*/; do |
| 187 | + [ -d "$agent_dir" ] || continue |
| 188 | + ( cd "$agent_dir" |
| 189 | + # Hash every shipped binary (everything except yaml/checksum files). |
| 190 | + : > checksums.sha256 |
| 191 | + for f in *; do |
| 192 | + case "$f" in |
| 193 | + *.yaml|*.sha256) continue ;; |
| 194 | + esac |
| 195 | + [ -f "$f" ] || continue |
| 196 | + sha256sum "$f" >> checksums.sha256 |
| 197 | + done |
| 198 | + ) |
| 199 | + agent_id="$(basename "$agent_dir")" |
| 200 | + sed "s|\$| (${agent_id})|" "${agent_dir}checksums.sha256" >> bundle/CHECKSUMS.sha256 |
| 201 | + done |
| 202 | +
|
| 203 | + echo "=== release bundle ===" |
| 204 | + find bundle -type f | sort |
| 205 | + echo "=== aggregated checksums ===" |
| 206 | + cat bundle/CHECKSUMS.sha256 |
| 207 | +
|
| 208 | + - name: Upload release bundle |
| 209 | + uses: actions/upload-artifact@v7 |
| 210 | + with: |
| 211 | + name: gaia-cpp-agents-${{ github.ref_name }} |
| 212 | + path: bundle/ |
| 213 | + if-no-files-found: error |
| 214 | + |
| 215 | + agents-build-summary: |
| 216 | + name: Agent Binaries Summary |
| 217 | + runs-on: ubuntu-latest |
| 218 | + needs: [build] |
| 219 | + if: always() && !cancelled() |
| 220 | + steps: |
| 221 | + - name: Check results |
| 222 | + run: | |
| 223 | + echo "=== Agent Binaries (C++) Summary ===" |
| 224 | + echo "Build/package matrix: ${{ needs.build.result }}" |
| 225 | + if [[ "${{ needs.build.result }}" == "skipped" ]]; then |
| 226 | + echo "Matrix skipped (draft PR — add 'ready_for_ci' label to run)" |
| 227 | + exit 0 |
| 228 | + fi |
| 229 | + if [[ "${{ needs.build.result }}" != "success" ]]; then |
| 230 | + echo "One or more matrix legs failed" |
| 231 | + exit 1 |
| 232 | + fi |
| 233 | + echo "All platform legs packaged successfully" |
0 commit comments