@@ -3,61 +3,124 @@ 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
40+ env :
41+ REBUILD_ALL : ${{ inputs.rebuild_all }}
4342 run : |
44- if [ ! -d "${{ inputs.agent_path }}" ]; then
45- echo "❌ Error: Agent path '${{ inputs.agent_path }}' does not exist"
46- exit 1
43+ # Find all tutorial directories with manifest.yaml
44+ all_agents=$(find examples/tutorials -name "manifest.yaml" -exec dirname {} \; | sort)
45+ agents_to_build=()
46+
47+ echo "DEBUG: REBUILD_ALL environment variable: '$REBUILD_ALL'"
48+
49+ if [ " ${{ inputs.rebuild_all }}" = "true" ]; then
50+ echo "Rebuild all agents requested"
51+ echo "DEBUG: All agents found: $all_agents"
52+ agents_to_build=($(echo "$all_agents"))
53+ echo "DEBUG: Agents to build array has ${#agents_to_build[@]} items"
54+
55+ echo "### 🔄 Rebuilding All Tutorial Agents" >> $GITHUB_STEP_SUMMARY
56+ else
57+ # Determine the base branch for comparison
58+ if [ "${{ github.event_name }}" = "pull_request" ]; then
59+ BASE_BRANCH="origin/${{ github.base_ref }}"
60+ echo "Comparing against PR base branch: $BASE_BRANCH"
61+ else
62+ BASE_BRANCH="HEAD~1"
63+ echo "Comparing against previous commit: $BASE_BRANCH"
64+ fi
65+
66+ # Check each agent directory for changes
67+ for agent_dir in $all_agents; do
68+ echo "Checking $agent_dir for changes..."
69+
70+ # Check if any files in this agent directory have changed
71+ if git diff --name-only $BASE_BRANCH HEAD | grep -q "^$agent_dir/"; then
72+ echo " ✅ Changes detected in $agent_dir"
73+ agents_to_build+=("$agent_dir")
74+ else
75+ echo " ⏭️ No changes in $agent_dir"
76+ fi
77+ done
78+
79+ echo "### 🔄 Changed Tutorial Agents" >> $GITHUB_STEP_SUMMARY
4780 fi
48- echo "✅ Agent path verified: ${{ inputs.agent_path }}"
4981
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
82+ # Convert array to JSON format and output summary
83+ if [ ${#agents_to_build[@]} -eq 0 ]; then
84+ echo "No agents to build"
85+ echo "agents=[]" >> $GITHUB_OUTPUT
86+ echo "has_agents=false" >> $GITHUB_OUTPUT
87+ else
88+ echo "Agents to build: ${#agents_to_build[@]}"
89+
90+ # Debug the array contents
91+ echo "DEBUG: Array contents:"
92+ for agent in "${agents_to_build[@]}"; do
93+ echo " - $agent"
94+ done
95+
96+ # Generate JSON properly
97+ agents_json=$(printf '%s\n' "${agents_to_build[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))')
98+ echo "agents=$agents_json" >> $GITHUB_OUTPUT
99+ echo "has_agents=true" >> $GITHUB_OUTPUT
100+
101+ echo "DEBUG: Generated JSON: $agents_json"
102+
103+ echo "" >> $GITHUB_STEP_SUMMARY
104+ for agent in "${agents_to_build[@]}"; do
105+ echo "- \`$agent\`" >> $GITHUB_STEP_SUMMARY
106+ done
107+ echo "" >> $GITHUB_STEP_SUMMARY
55108 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
109+
110+ build-agents :
111+ needs : find-agents
112+ if : ${{ needs.find-agents.outputs.has_agents == 'true' }}
113+ runs-on : ubuntu-latest
114+ timeout-minutes : 15
115+ strategy :
116+ matrix :
117+ agent_path : ${{ fromJson(needs.find-agents.outputs.agents) }}
118+ fail-fast : false
119+ name : build-${{ matrix.agent_path }}
120+
121+ steps :
122+ - name : Checkout repository
123+ uses : actions/checkout@v4
61124
62125 - name : Set up Docker Buildx
63126 uses : docker/setup-buildx-action@v3
@@ -80,35 +143,45 @@ jobs:
80143 id : image-name
81144 run : |
82145 # Remove examples/tutorials/ prefix and replace / with -
83- AGENT_NAME=$(echo "${{ inputs .agent_path }}" | sed 's|^examples/tutorials/||' | sed 's|/|-|g')
146+ AGENT_NAME=$(echo "${{ matrix .agent_path }}" | sed 's|^examples/tutorials/||' | sed 's|/|-|g')
84147 echo "AGENT_NAME=$AGENT_NAME" >> $GITHUB_ENV
85148 echo "agent_name=$AGENT_NAME" >> $GITHUB_OUTPUT
86149 echo "Agent name set to $AGENT_NAME"
87150
88151 - name : Login to GitHub Container Registry
152+ # Only login if we're going to push (main branch or rebuild_all)
153+ if : ${{ github.event_name == 'push' || inputs.rebuild_all }}
89154 uses : docker/login-action@v3
90155 with :
91156 registry : ghcr.io
92157 username : ${{ github.actor }}
93158 password : ${{ secrets.GITHUB_TOKEN }}
94159
95- - name : Build and Push Agent Image
160+ - name : Build and Conditionally Push Agent Image
96161 env :
97162 REGISTRY : ghcr.io
98163 run : |
99164 AGENT_NAME="${{ steps.image-name.outputs.agent_name }}"
100- VERSION_TAG="${{ inputs.version_tag }}"
101165 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
166+
167+ # Determine if we should push based on event type
168+ if [ "${{ github.event_name }}" = "push" ] || [ "${{ inputs.rebuild_all }}" = "true" ]; then
169+ SHOULD_PUSH=true
170+ VERSION_TAG="latest"
171+ echo "🚀 Building and pushing agent: ${{ matrix.agent_path }}"
172+ else
173+ SHOULD_PUSH=false
174+ VERSION_TAG="pr-${{ github.event.number }}"
175+ echo "🔍 Validating build for agent: ${{ matrix.agent_path }}"
176+ fi
177+
178+ # Build command - add --push only if we should push
179+ BUILD_ARGS="--manifest ${{ matrix.agent_path }}/manifest.yaml --registry ${REGISTRY} --tag ${VERSION_TAG} --platforms linux/amd64 --repository-name ${REPOSITORY_NAME}"
180+
181+ if [ "$SHOULD_PUSH" = "true" ]; then
182+ agentex agents build $BUILD_ARGS --push
183+ echo "✅ Successfully built and pushed: ${REGISTRY}/${REPOSITORY_NAME}:${VERSION_TAG}"
184+ else
185+ agentex agents build $BUILD_ARGS
186+ echo "✅ Build validation successful for: ${{ matrix.agent_path }}"
187+ fi
0 commit comments