Skip to content

Commit cb9b1b5

Browse files
committed
adding this
1 parent 0f38f51 commit cb9b1b5

File tree

1 file changed

+113
-56
lines changed

1 file changed

+113
-56
lines changed

.github/workflows/build-and-push-tutorial-agent.yml

Lines changed: 113 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,108 @@ name: Build and Push Tutorial Agent
33
on:
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

2822
permissions:
2923
contents: read
3024
packages: write
3125

3226
jobs:
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+
agents_to_build=($(echo "$all_agents"))
48+
49+
echo "### 🔄 Rebuilding All Tutorial Agents" >> $GITHUB_STEP_SUMMARY
50+
else
51+
# Determine the base branch for comparison
52+
if [ "${{ github.event_name }}" = "pull_request" ]; then
53+
BASE_BRANCH="origin/${{ github.base_ref }}"
54+
echo "Comparing against PR base branch: $BASE_BRANCH"
55+
else
56+
BASE_BRANCH="HEAD~1"
57+
echo "Comparing against previous commit: $BASE_BRANCH"
58+
fi
59+
60+
# Check each agent directory for changes
61+
for agent_dir in $all_agents; do
62+
echo "Checking $agent_dir for changes..."
63+
64+
# Check if any files in this agent directory have changed
65+
if git diff --name-only $BASE_BRANCH HEAD | grep -q "^$agent_dir/"; then
66+
echo " ✅ Changes detected in $agent_dir"
67+
agents_to_build+=("$agent_dir")
68+
else
69+
echo " ⏭️ No changes in $agent_dir"
70+
fi
71+
done
72+
73+
echo "### 🔄 Changed Tutorial Agents" >> $GITHUB_STEP_SUMMARY
4774
fi
48-
echo "✅ Agent path verified: ${{ inputs.agent_path }}"
4975
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
76+
# Convert array to JSON format and output summary
77+
if [ ${#agents_to_build[@]} -eq 0 ]; then
78+
echo "No agents to build"
79+
echo "agents=[]" >> $GITHUB_OUTPUT
80+
echo "has_agents=false" >> $GITHUB_OUTPUT
81+
else
82+
echo "Agents to build: ${#agents_to_build[@]}"
83+
printf -v agents_json '%s\n' "${agents_to_build[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))'
84+
echo "agents=$agents_json" >> $GITHUB_OUTPUT
85+
echo "has_agents=true" >> $GITHUB_OUTPUT
86+
87+
echo "" >> $GITHUB_STEP_SUMMARY
88+
for agent in "${agents_to_build[@]}"; do
89+
echo "- \`$agent\`" >> $GITHUB_STEP_SUMMARY
90+
done
91+
echo "" >> $GITHUB_STEP_SUMMARY
5592
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
93+
94+
build-agents:
95+
needs: find-agents
96+
if: ${{ needs.find-agents.outputs.has_agents == 'true' }}
97+
runs-on: ubuntu-latest
98+
timeout-minutes: 15
99+
strategy:
100+
matrix:
101+
agent_path: ${{ fromJson(needs.find-agents.outputs.agents) }}
102+
fail-fast: false
103+
name: build-${{ matrix.agent_path }}
104+
105+
steps:
106+
- name: Checkout repository
107+
uses: actions/checkout@v4
61108

62109
- name: Set up Docker Buildx
63110
uses: docker/setup-buildx-action@v3
@@ -80,35 +127,45 @@ jobs:
80127
id: image-name
81128
run: |
82129
# Remove examples/tutorials/ prefix and replace / with -
83-
AGENT_NAME=$(echo "${{ inputs.agent_path }}" | sed 's|^examples/tutorials/||' | sed 's|/|-|g')
130+
AGENT_NAME=$(echo "${{ matrix.agent_path }}" | sed 's|^examples/tutorials/||' | sed 's|/|-|g')
84131
echo "AGENT_NAME=$AGENT_NAME" >> $GITHUB_ENV
85132
echo "agent_name=$AGENT_NAME" >> $GITHUB_OUTPUT
86133
echo "Agent name set to $AGENT_NAME"
87134
88135
- name: Login to GitHub Container Registry
136+
# Only login if we're going to push (main branch or rebuild_all)
137+
if: ${{ github.event_name == 'push' || inputs.rebuild_all }}
89138
uses: docker/login-action@v3
90139
with:
91140
registry: ghcr.io
92141
username: ${{ github.actor }}
93142
password: ${{ secrets.GITHUB_TOKEN }}
94143

95-
- name: Build and Push Agent Image
144+
- name: Build and Conditionally Push Agent Image
96145
env:
97146
REGISTRY: ghcr.io
98147
run: |
99148
AGENT_NAME="${{ steps.image-name.outputs.agent_name }}"
100-
VERSION_TAG="${{ inputs.version_tag }}"
101149
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
150+
151+
# Determine if we should push based on event type
152+
if [ "${{ github.event_name }}" = "push" ] || [ "${{ inputs.rebuild_all }}" = "true" ]; then
153+
SHOULD_PUSH=true
154+
VERSION_TAG="latest"
155+
echo "🚀 Building and pushing agent: ${{ matrix.agent_path }}"
156+
else
157+
SHOULD_PUSH=false
158+
VERSION_TAG="pr-${{ github.event.number }}"
159+
echo "🔍 Validating build for agent: ${{ matrix.agent_path }}"
160+
fi
161+
162+
# Build command - add --push only if we should push
163+
BUILD_ARGS="--manifest ${{ matrix.agent_path }}/manifest.yaml --registry ${REGISTRY} --tag ${VERSION_TAG} --platforms linux/amd64 --repository-name ${REPOSITORY_NAME}"
164+
165+
if [ "$SHOULD_PUSH" = "true" ]; then
166+
agentex agents build $BUILD_ARGS --push
167+
echo "✅ Successfully built and pushed: ${REGISTRY}/${REPOSITORY_NAME}:${VERSION_TAG}"
168+
else
169+
agentex agents build $BUILD_ARGS
170+
echo "✅ Build validation successful for: ${{ matrix.agent_path }}"
171+
fi

0 commit comments

Comments
 (0)