Enhance FSMApplication state handling in agent_session.py #865
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: Build and Test | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| env: | |
| CONTAINER_NAME: agent-apiserver-1 | |
| ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | |
| GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} | |
| ECR_REGISTRY: 361769577597.dkr.ecr.us-west-2.amazonaws.com | |
| ECR_REPOSITORY: appdotbuild/agent-fullstack | |
| AWS_REGION: us-west-2 | |
| jobs: | |
| build-template: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - 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 | |
| # List of containers to check | |
| 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" # Add to the list of failed containers | |
| 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: ---" | |
| # Loop through failed containers and print logs | |
| 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 | |
| build-and-test-codegen: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 2 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| version: "0.7.3" | |
| - name: Run linters | |
| uses: astral-sh/ruff-action@v3 | |
| with: | |
| version: ">=0.11.5" | |
| args: check . | |
| - 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 tests | |
| working-directory: ./agent/ | |
| run: | | |
| echo "Running tests..." | |
| uv run test --verbose | |
| 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 | |
| - name: Check Container Health | |
| run: | | |
| 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: Determine if Release Build is Needed | |
| id: check_release | |
| run: | | |
| is_release="false" | |
| # we check two commits because the first commit is the merge commit | |
| if git log -2 --pretty=%s | tail -n 1 | grep -q "release"; then | |
| is_release="true" | |
| elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then | |
| is_release="true" | |
| fi | |
| echo "is_release=${is_release}" >> $GITHUB_OUTPUT | |
| - name: Calculate Build Tag | |
| # Only run if we determined it's a release build | |
| 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" # Set commit_short_sha as an 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: 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 Docker image with tag: $IMAGE_TAG ..." | |
| docker buildx build \ | |
| --platform linux/arm64 \ | |
| --target prod \ | |
| -t ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} \ | |
| -t ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.BRANCH_NAME }}-latest \ | |
| --push \ | |
| . | |
| echo "Docker image built and pushed successfully!" | |
| # This step will run even if the health check step fails | |
| - name: Clean up Docker Compose services | |
| working-directory: ./agent/ | |
| if: always() # Ensures this step runs even if previous steps fail | |
| run: | | |
| echo "Stopping and removing Docker Compose services..." | |
| docker compose down -v --remove-orphans # Stop, remove containers, networks, AND volumes (-v) | |
| echo "Cleanup complete." |