@@ -3,61 +3,112 @@ name: Build and Push Tutorial Agent
33on :
44 workflow_dispatch :
55 inputs :
6- agent_path :
7- description : " Path to the agent directory (e.g., examples/tutorials/10_agentic/00_base/000_hello_acp)"
8- required : true
9- type : string
10- version_tag :
11- description : " Version tag for the agent build (e.g., v1.0.0, latest)"
12- required : true
13- type : string
14- default : " latest"
15-
16- workflow_call :
17- inputs :
18- agent_path :
19- description : " Path to the agent directory"
20- required : true
21- type : string
22- version_tag :
23- description : " Version tag for the agent build"
24- required : true
25- type : string
26- default : " latest"
6+ rebuild_all :
7+ description : " Rebuild all agents regardless of changes"
8+ required : false
9+ type : boolean
10+ default : false
11+
12+ pull_request :
13+ paths :
14+ - " examples/tutorials/**"
15+
16+ push :
17+ branches :
18+ - main
19+ paths :
20+ - " examples/tutorials/**"
2721
2822permissions :
2923 contents : read
3024 packages : write
3125
3226jobs :
33- build-and-push-agent :
34- timeout-minutes : 10
35- name : Build Tutorial Agent
27+ find-agents :
3628 runs-on : ubuntu-latest
37-
29+ outputs :
30+ agents : ${{ steps.get-agents.outputs.agents }}
31+ has_agents : ${{ steps.get-agents.outputs.has_agents }}
3832 steps :
3933 - name : Checkout repository
4034 uses : actions/checkout@v4
35+ with :
36+ fetch-depth : 0 # Fetch full history for git diff
4137
42- - name : Validate agent path exists
38+ - name : Find tutorial agents to build
39+ id : get-agents
4340 run : |
44- if [ ! -d "${{ inputs.agent_path }}" ]; then
45- echo "❌ Error: Agent path '${{ inputs.agent_path }}' does not exist"
46- exit 1
41+ # Find all tutorial directories with manifest.yaml
42+ all_agents=$(find examples/tutorials -name "manifest.yaml" -exec dirname {} \; | sort)
43+ agents_to_build=()
44+
45+ if [ "${{ inputs.rebuild_all }}" = "true" ]; then
46+ echo "Rebuild all agents requested"
47+ echo "DEBUG: All agents found: $all_agents"
48+ agents_to_build=($(echo "$all_agents"))
49+ echo "DEBUG: Agents to build array has ${#agents_to_build[@]} items"
50+
51+ echo "### 🔄 Rebuilding All Tutorial Agents" >> $GITHUB_STEP_SUMMARY
52+ else
53+ # Determine the base branch for comparison
54+ if [ "${{ github.event_name }}" = "pull_request" ]; then
55+ BASE_BRANCH="origin/${{ github.base_ref }}"
56+ echo "Comparing against PR base branch: $BASE_BRANCH"
57+ else
58+ BASE_BRANCH="HEAD~1"
59+ echo "Comparing against previous commit: $BASE_BRANCH"
60+ fi
61+
62+ # Check each agent directory for changes
63+ for agent_dir in $all_agents; do
64+ echo "Checking $agent_dir for changes..."
65+
66+ # Check if any files in this agent directory have changed
67+ if git diff --name-only $BASE_BRANCH HEAD | grep -q "^$agent_dir/"; then
68+ echo " ✅ Changes detected in $agent_dir"
69+ agents_to_build+=("$agent_dir")
70+ else
71+ echo " ⏭️ No changes in $agent_dir"
72+ fi
73+ done
74+
75+ echo "### 🔄 Changed Tutorial Agents" >> $GITHUB_STEP_SUMMARY
4776 fi
48- echo "✅ Agent path verified: ${{ inputs.agent_path }}"
4977
50- - name : Validate manifest.yaml exists
51- run : |
52- if [ ! -f "${{ inputs.agent_path }}/manifest.yaml" ]; then
53- echo "❌ Error: manifest.yaml not found in '${{ inputs.agent_path }}'"
54- exit 1
78+ # Convert array to JSON format and output summary
79+ if [ ${#agents_to_build[@]} -eq 0 ]; then
80+ echo "No agents to build"
81+ echo "agents=[]" >> $GITHUB_OUTPUT
82+ echo "has_agents=false" >> $GITHUB_OUTPUT
83+ else
84+ echo "Agents to build: ${#agents_to_build[@]}"
85+ printf -v agents_json '%s\n' "${agents_to_build[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))'
86+ echo "agents=$agents_json" >> $GITHUB_OUTPUT
87+ echo "has_agents=true" >> $GITHUB_OUTPUT
88+
89+ echo "DEBUG: Generated JSON: $agents_json"
90+
91+ echo "" >> $GITHUB_STEP_SUMMARY
92+ for agent in "${agents_to_build[@]}"; do
93+ echo "- \`$agent\`" >> $GITHUB_STEP_SUMMARY
94+ done
95+ echo "" >> $GITHUB_STEP_SUMMARY
5596 fi
56- echo "✅ manifest.yaml found"
57- echo "### Validation Summary" >> $GITHUB_STEP_SUMMARY
58- echo "- **Agent Path**: ${{ inputs.agent_path }}" >> $GITHUB_STEP_SUMMARY
59- echo "- **Version Tag**: ${{ inputs.version_tag }}" >> $GITHUB_STEP_SUMMARY
60- echo "- **Status**: ✅ Validation passed" >> $GITHUB_STEP_SUMMARY
97+
98+ build-agents :
99+ needs : find-agents
100+ if : ${{ needs.find-agents.outputs.has_agents == 'true' }}
101+ runs-on : ubuntu-latest
102+ timeout-minutes : 15
103+ strategy :
104+ matrix :
105+ agent_path : ${{ fromJson(needs.find-agents.outputs.agents) }}
106+ fail-fast : false
107+ name : build-${{ matrix.agent_path }}
108+
109+ steps :
110+ - name : Checkout repository
111+ uses : actions/checkout@v4
61112
62113 - name : Set up Docker Buildx
63114 uses : docker/setup-buildx-action@v3
@@ -80,35 +131,46 @@ jobs:
80131 id : image-name
81132 run : |
82133 # Remove examples/tutorials/ prefix and replace / with -
83- AGENT_NAME=$(echo "${{ inputs .agent_path }}" | sed 's|^examples/tutorials/||' | sed 's|/|-|g')
134+ AGENT_NAME=$(echo "${{ matrix .agent_path }}" | sed 's|^examples/tutorials/||' | sed 's|/|-|g')
84135 echo "AGENT_NAME=$AGENT_NAME" >> $GITHUB_ENV
85136 echo "agent_name=$AGENT_NAME" >> $GITHUB_OUTPUT
86137 echo "Agent name set to $AGENT_NAME"
87138
88139 - name : Login to GitHub Container Registry
140+ # Only login if we're going to push (main branch or rebuild_all)
141+ if : ${{ github.event_name == 'push' || inputs.rebuild_all }}
89142 uses : docker/login-action@v3
90143 with :
91144 registry : ghcr.io
92145 username : ${{ github.actor }}
93146 password : ${{ secrets.GITHUB_TOKEN }}
94147
95- - name : Build and Push Agent Image
148+ - name : Build and Conditionally Push Agent Image
96149 env :
97150 REGISTRY : ghcr.io
98151 run : |
99152 AGENT_NAME="${{ steps.image-name.outputs.agent_name }}"
100- VERSION_TAG="${{ inputs.version_tag }}"
101153 REPOSITORY_NAME="${{ github.repository }}/tutorial-agents/${AGENT_NAME}"
102- FULL_IMAGE="${REGISTRY}/${REPOSITORY_NAME}:${VERSION_TAG}"
103-
104- agentex agents build \
105- --manifest "${{ inputs.agent_path }}/manifest.yaml" \
106- --registry "${REGISTRY}" \
107- --tag "${VERSION_TAG}" \
108- --platforms "linux/amd64" \
109- --repository-name "${REPOSITORY_NAME}" \
110- --push
111-
112- echo "Successfully built and pushed: ${FULL_IMAGE}"
113- echo "### Build Complete" >> $GITHUB_STEP_SUMMARY
114- echo "- **Image**: \`${FULL_IMAGE}\`" >> $GITHUB_STEP_SUMMARY
154+
155+ # Determine if we should push based on event type
156+ if [ "${{ github.event_name }}" = "push" ] || [ "${{ inputs.rebuild_all }}" = "true" ]; then
157+ SHOULD_PUSH=true
158+ VERSION_TAG="latest"
159+ echo "🚀 Building and pushing agent: ${{ matrix.agent_path }}"
160+ else
161+ SHOULD_PUSH=false
162+ VERSION_TAG="pr-${{ github.event.number }}"
163+ echo "🔍 Validating build for agent: ${{ matrix.agent_path }}"
164+ fi
165+
166+ # Build command - add --push only if we should push
167+ BUILD_ARGS="--manifest ${{ matrix.agent_path }}/manifest.yaml --registry ${REGISTRY} --tag ${VERSION_TAG} --platforms linux/amd64 --repository-name ${REPOSITORY_NAME}"
168+
169+ if [ "$SHOULD_PUSH" = "true" ]; then
170+ agentex agents build $BUILD_ARGS --push
171+ echo "✅ Successfully built and pushed: ${REGISTRY}/${REPOSITORY_NAME}:${VERSION_TAG}"
172+ else
173+ agentex agents build $BUILD_ARGS
174+ echo "✅ Build validation successful for: ${{ matrix.agent_path }}"
175+ fi
176+
0 commit comments