feat: add asp adk samples #538
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: checks | |
on: | |
pull_request_target: | |
jobs: | |
# JOB 1: Discover which specific agent folders have changed. | |
discover-changed-agents: | |
name: Discover Changed Agents | |
runs-on: ubuntu-latest | |
outputs: | |
# The output is a JSON array of agent directories to be built, e.g., ["agents/agent-a", "agents/agent-c"] | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v5 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
fetch-depth: 0 | |
- name: Get changed files | |
id: changed_files | |
uses: tj-actions/changed-files@v47 | |
with: | |
files: python/agents/** | |
- name: Create job matrix from changed files | |
id: set-matrix | |
run: | | |
TEMP_JSON_FILE=$(mktemp) | |
echo "[]" > "$TEMP_JSON_FILE" | |
echo "${{ steps.changed_files.outputs.all_changed_files }}" | \ | |
grep -o 'python/agents/[^/]*' | \ | |
sort -u | \ | |
while read -r dir; do | |
if [ -f "$dir/pyproject.toml" ]; then | |
# Check if the pyproject.toml contains [tool.agent-starter-pack] section | |
if grep -q '\[tool\.agent-starter-pack\]' "$dir/pyproject.toml"; then | |
deployment_targets=$(yq eval '.tool.agent-starter-pack.settings.deployment_targets[]' "$dir/pyproject.toml" 2>/dev/null || echo "") | |
if [ -z "$deployment_targets" ]; then | |
deployment_targets="agent_engine cloud_run" | |
fi | |
for target in $deployment_targets; do | |
lint_task=$(jq -n --arg dir "$dir" --arg target "$target" '{agent_path: $dir, deployment_target: $target, task: "lint"}') | |
test_task=$(jq -n --arg dir "$dir" --arg target "$target" '{agent_path: $dir, deployment_target: $target, task: "test"}') | |
jq ". + [$lint_task, $test_task]" "$TEMP_JSON_FILE" > "$TEMP_JSON_FILE.tmp" && mv "$TEMP_JSON_FILE.tmp" "$TEMP_JSON_FILE" | |
done | |
fi | |
fi | |
done | |
matrix_json=$(cat "$TEMP_JSON_FILE" | jq -c .) | |
rm "$TEMP_JSON_FILE" | |
echo "Detected changes in allow list agents: $matrix_json" | |
echo "matrix=$matrix_json" >> $GITHUB_OUTPUT | |
# JOB 2: Build, test, and interact with GCP for each changed agent. | |
test-agent-template: | |
name: ${{ matrix.task }} | ${{ matrix.agent_path }} (${{ matrix.deployment_target }}) | |
needs: discover-changed-agents | |
if: needs.discover-changed-agents.outputs.matrix != '[]' | |
runs-on: ubuntu-latest | |
# --- PERMISSIONS BLOCK FOR OIDC AUTHENTICATION --- | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
strategy: | |
fail-fast: false | |
matrix: | |
# Matrix includes agent_path, deployment_target, and task | |
include: ${{ fromJson(needs.discover-changed-agents.outputs.matrix) }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v5 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- id: 'auth' | |
name: 'Authenticate to Google Cloud' | |
uses: 'google-github-actions/auth@v3' | |
with: | |
workload_identity_provider: 'projects/628595556591/locations/global/workloadIdentityPools/github-pool/providers/github-provider' | |
create_credentials_file: true | |
project_id: adk-devops | |
# --- RUN THE TEMPLATE GENERATION AND TESTING USING CONTAINER --- | |
- name: ${{ matrix.task }} - ${{ matrix.agent_path }} (${{ matrix.deployment_target }}) | |
uses: docker://europe-west4-docker.pkg.dev/production-ai-template/starter-pack/e2e-tests | |
continue-on-error: ${{ matrix.task == 'lint' }} | |
with: | |
entrypoint: /bin/bash | |
args: | | |
-c " | |
set -e # Exit immediately if a command exits with a non-zero status. | |
set -x | |
# Extract agent name from path | |
TEMPLATE_PATH=\"${{ matrix.agent_path }}\" | |
AGENT_NAME=$(basename \"$TEMPLATE_PATH\") | |
DEPLOYMENT_TARGET=\"${{ matrix.deployment_target }}\" | |
# Use shorter prefix and truncate if needed to stay under 26 chars | |
TRUNCATED_NAME=$(echo \"$AGENT_NAME\" | cut -c1-21) | |
AGENT_GENERATED_NAME=\"test-$TRUNCATED_NAME\" | |
echo \"--- Testing template: $TEMPLATE_PATH with deployment target: $DEPLOYMENT_TARGET ---\" | |
# Generate agent from template with deployment target | |
uvx agent-starter-pack create \"$AGENT_GENERATED_NAME\" --agent \"local@$TEMPLATE_PATH\" -d \"$DEPLOYMENT_TARGET\" --auto-approve --skip-checks | |
echo \"Agent generated successfully at: $AGENT_GENERATED_NAME\" | |
# Install dependencies and run tests | |
cd $AGENT_GENERATED_NAME && make install | |
echo \"--- Current task: ${{ matrix.task }} ---\" | |
if [ \"${{ matrix.task }}\" = \"lint\" ]; then | |
echo \"--- Linting generated code ---\" | |
make lint | |
elif [ \"${{ matrix.task }}\" = \"test\" ]; then | |
echo \"--- Running tests ---\" | |
export AGENT_NAME=\"$DEPLOYMENT_TARGET-$AGENT_NAME\" | |
make test | |
echo \"--- Starting backend ---\" | |
make backend & | |
BACKEND_PID=$! | |
echo \"--- Waiting 10 seconds ---\" | |
sleep 10 | |
# Check if backend process is still running | |
if ! kill -0 $BACKEND_PID 2>/dev/null; then | |
echo \"ERROR: Backend process died during startup\" | |
exit 1 | |
fi | |
echo \"--- Stopping backend and all child processes ---\" | |
kill -TERM -$BACKEND_PID 2>/dev/null || true | |
sleep 2 | |
kill -KILL -$BACKEND_PID 2>/dev/null || true | |
else | |
echo \"--- Unknown task: ${{ matrix.task }} ---\" | |
exit 1 | |
fi |