Skip to content

adding trends and insights agent #41

adding trends and insights agent

adding trends and insights agent #41

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@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v44
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@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
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
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 && uv sync --dev
echo \"--- Current task: ${{ matrix.task }} ---\"
if [ \"${{ matrix.task }}\" = \"lint\" ]; then
echo \"--- Linting generated code ---\"
uv sync --dev --extra lint
uv run codespell
uv run ruff check . --diff
uv run ruff format . --check --diff
uv run mypy .
elif [ \"${{ matrix.task }}\" = \"test\" ]; then
echo \"--- Running tests ---\"
uv run pytest tests/unit
uv run pytest tests/integration
else
echo \"--- Unknown task: ${{ matrix.task }} ---\"
exit 1
fi