restructure CI into separate Python and Rust pipelines #2
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: Python Legacy Pipeline | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'agent/**' | |
| pull_request: | |
| paths: | |
| - 'agent/**' | |
| env: | |
| CONTAINER_NAME: agent-apiserver-1 | |
| ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | |
| GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} | |
| jobs: | |
| python-lint: | |
| name: Python Lint | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| version: "0.7.3" | |
| - name: Run Python linters | |
| uses: astral-sh/ruff-action@v3 | |
| with: | |
| version: ">=0.11.5" | |
| args: check ./agent | |
| continue-on-error: true | |
| python-tests: | |
| name: Python Tests | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| version: "0.7.3" | |
| - name: Run Python tests | |
| working-directory: ./agent/ | |
| run: | | |
| echo "Running Python tests..." | |
| uv run test --verbose --exclude e2e | |
| exit_code=$? | |
| if [ $exit_code -ne 0 ]; then | |
| echo "Tests failed with exit code $exit_code" | |
| exit $exit_code | |
| else | |
| echo "Tests passed successfully!" | |
| fi | |
| python-template-build: | |
| name: Build Python Template | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Set up Docker Compose | |
| uses: docker/setup-compose-action@v1 | |
| - name: Start Docker Compose services | |
| working-directory: ./agent/trpc_agent/template/ | |
| run: docker compose up -d --build | |
| - name: Check Container Health | |
| run: | | |
| sleep 10 | |
| containers_to_check="postgres app" | |
| all_healthy=true | |
| failed_containers="" | |
| for container_name in $containers_to_check; do | |
| echo "Checking health of container: $container_name" | |
| status=$(docker inspect --format='{{.State.Health.Status}}' $container_name) | |
| if [ "$status" = "healthy" ]; then | |
| echo "Container $container_name is healthy!" | |
| else | |
| echo "Container $container_name is not healthy (status: $status)." | |
| all_healthy=false | |
| failed_containers="$failed_containers $container_name" | |
| fi | |
| done | |
| if [ "$all_healthy" = "true" ]; then | |
| echo "All specified containers are healthy!" | |
| exit 0 | |
| else | |
| echo "Error: One or more containers are not healthy. Failing workflow." | |
| echo "--- Logs for failed containers: ---" | |
| for failed_container in $failed_containers; do | |
| echo "--- Logs for $failed_container ---" | |
| docker logs --tail 50 $failed_container || echo "Could not retrieve container logs for $failed_container." | |
| echo "------------------------------------" | |
| done | |
| exit 1 | |
| fi | |
| - name: Clean up Docker Compose services | |
| working-directory: ./agent/trpc_agent/template/ | |
| if: always() | |
| run: | | |
| echo "Stopping and removing Docker Compose services..." | |
| docker compose down -v --remove-orphans | |
| echo "Cleanup complete." | |
| python-health-check: | |
| name: Python Container Health Check | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Set up Docker Compose | |
| uses: docker/setup-compose-action@v1 | |
| - name: Start Docker Compose services | |
| working-directory: ./agent/ | |
| run: docker compose up -d --build | |
| - name: Check Container Health | |
| run: | | |
| sleep 30 | |
| echo "Checking health of container: ${{ env.CONTAINER_NAME }}" | |
| status=$(docker inspect --format='{{.State.Health.Status}}' ${{ env.CONTAINER_NAME }}) | |
| if [ "$status" = "healthy" ]; then | |
| echo "Container is healthy!" | |
| exit 0 | |
| else | |
| echo "Error: Container is not healthy (status: $status). Failing workflow." | |
| echo "--- Recent container logs: ---" | |
| docker logs --tail 50 ${{ env.CONTAINER_NAME }} || echo "Could not retrieve container logs." | |
| exit 1 | |
| fi | |
| - name: Clean up Docker Compose services | |
| working-directory: ./agent/ | |
| if: always() | |
| run: | | |
| echo "Stopping and removing Docker Compose services..." | |
| docker compose down -v --remove-orphans | |
| echo "Cleanup complete." | |
| python-e2e-tests: | |
| name: Python E2E Tests (${{ matrix.template }}) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| strategy: | |
| matrix: | |
| template: [trpc, laravel] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| version: "0.7.3" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Set up Docker Compose | |
| uses: docker/setup-compose-action@v1 | |
| - name: Start Docker Compose services | |
| working-directory: ./agent/ | |
| run: docker compose up -d --build | |
| - name: Run E2E tests | |
| working-directory: ./agent/ | |
| run: | | |
| echo "Running E2E tests for ${{ matrix.template }}..." | |
| uv run test_e2e ${{ matrix.template }} | |
| - name: Clean up Docker Compose services | |
| working-directory: ./agent/ | |
| if: always() | |
| run: docker compose down -v --remove-orphans | |
| build-and-push-python: | |
| name: Build and Push Python Docker Image | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| needs: [python-lint, python-tests, python-template-build, python-health-check, python-e2e-tests] | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| env: | |
| ECR_REGISTRY: 361769577597.dkr.ecr.us-west-2.amazonaws.com | |
| ECR_REPOSITORY: appdotbuild/agent-fullstack | |
| AWS_REGION: us-west-2 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Determine if Release Build is Needed | |
| id: check_release | |
| run: | | |
| is_release="false" | |
| if git log -2 --pretty=%s | tail -n 1 | grep -q "release"; then | |
| is_release="true" | |
| echo "Release build detected based on commit message." | |
| elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then | |
| is_release="true" | |
| echo "Release build detected based on push to main branch." | |
| fi | |
| echo "is_release=${is_release}" >> $GITHUB_OUTPUT | |
| - name: Calculate Build Tag | |
| if: steps.check_release.outputs.is_release == 'true' | |
| id: build_tag | |
| run: | | |
| BRANCH_NAME_RAW="${{ github.head_ref || github.ref_name }}" | |
| BRANCH_NAME=$(echo "$BRANCH_NAME_RAW" | sed -e 's#^refs/heads/##' -e 's#^refs/tags/##' -e 's#/#-#g' -e 's/[^a-zA-Z0-9.-]/-/g') | |
| SHORT_SHA=$(git rev-parse --short ${{ github.sha }}) | |
| echo "commit_short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT" | |
| TAG=${BRANCH_NAME}-${SHORT_SHA} | |
| echo "Calculated Tag: $TAG" | |
| echo "image_tag=$TAG" >> "$GITHUB_OUTPUT" | |
| echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT" | |
| - name: Configure AWS Credentials | |
| if: steps.check_release.outputs.is_release == 'true' | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.ECR_ACCESS_KEY }} | |
| aws-secret-access-key: ${{ secrets.ECR_SECRET_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to Amazon ECR | |
| if: steps.check_release.outputs.is_release == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.ECR_REGISTRY }} | |
| - name: Build and push Docker image to ECR | |
| if: steps.check_release.outputs.is_release == 'true' | |
| working-directory: ./agent/ | |
| env: | |
| IMAGE_TAG: ${{ steps.build_tag.outputs.image_tag }} | |
| BRANCH_NAME: ${{ steps.build_tag.outputs.branch_name }} | |
| run: | | |
| echo "Building and pushing Python Docker image with tag: $IMAGE_TAG ..." | |
| docker buildx build \ | |
| --platform linux/arm64 \ | |
| --target prod \ | |
| --no-cache \ | |
| -t ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:$IMAGE_TAG \ | |
| -t ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.BRANCH_NAME }}-latest \ | |
| --push \ | |
| . | |
| echo "Docker image built and pushed successfully!" |