--- name: Run Unit Tests on: push: branches: [main] pull_request: permissions: contents: read jobs: test: name: Test with Python ${{ matrix.python-version }} runs-on: ubuntu-latest if: github.repository == 'a2aproject/a2a-python' services: postgres: image: postgres:15-alpine env: POSTGRES_USER: a2a POSTGRES_PASSWORD: a2a_password POSTGRES_DB: a2a_test ports: - 5432:5432 options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 mysql: image: mysql:8.0 env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: a2a_test MYSQL_USER: a2a MYSQL_PASSWORD: a2a_password ports: - 3306:3306 options: >- --health-cmd="mysqladmin ping -h localhost -u root -proot" --health-interval=10s --health-timeout=5s --health-retries=5 strategy: matrix: python-version: ['3.10', '3.13'] steps: - name: Checkout code uses: actions/checkout@v6 - name: Set up test environment variables run: | echo "POSTGRES_TEST_DSN=postgresql+asyncpg://a2a:a2a_password@localhost:5432/a2a_test" >> $GITHUB_ENV echo "MYSQL_TEST_DSN=mysql+aiomysql://a2a:a2a_password@localhost:3306/a2a_test" >> $GITHUB_ENV - name: Install uv for Python ${{ matrix.python-version }} uses: astral-sh/setup-uv@v7 with: python-version: ${{ matrix.python-version }} - name: Add uv to PATH run: | echo "$HOME/.cargo/bin" >> $GITHUB_PATH - name: Install dependencies run: uv sync --locked # Coverage comparison for PRs (only on Python 3.13 to avoid duplicate work) - name: Checkout Base Branch if: github.event_name == 'pull_request' && matrix.python-version == '3.13' uses: actions/checkout@v6 with: ref: ${{ github.event.pull_request.base.ref || 'main' }} clean: true - name: Run coverage (Base) if: github.event_name == 'pull_request' && matrix.python-version == '3.13' run: | uv run pytest --cov=a2a --cov-report=json --cov-report=html:coverage mv coverage.json /tmp/coverage-base.json - name: Checkout PR Branch (Restore) if: github.event_name == 'pull_request' && matrix.python-version == '3.13' uses: actions/checkout@v6 with: clean: true - name: Run coverage (PR) if: github.event_name == 'pull_request' && matrix.python-version == '3.13' run: | uv run pytest --cov=a2a --cov-report=json --cov-report=html:coverage --cov-report=term --cov-fail-under=88 mv coverage.json coverage-pr.json cp /tmp/coverage-base.json coverage-base.json - name: Save Metadata if: github.event_name == 'pull_request' && matrix.python-version == '3.13' run: | echo ${{ github.event.number }} > ./PR_NUMBER echo ${{ github.event.pull_request.base.ref || 'main' }} > ./BASE_BRANCH - name: Upload Coverage Artifacts uses: actions/upload-artifact@v7 if: github.event_name == 'pull_request' && matrix.python-version == '3.13' with: name: coverage-data path: | coverage-base.json coverage-pr.json coverage/ PR_NUMBER BASE_BRANCH retention-days: 1 # Run standard tests (for matrix items that didn't run coverage PR) - name: Run tests (Standard) if: matrix.python-version != '3.13' || github.event_name != 'pull_request' run: uv run pytest --cov=a2a --cov-report term --cov-fail-under=88 - name: Upload Artifact (base) uses: actions/upload-artifact@v7 if: github.event_name != 'pull_request' && matrix.python-version == '3.13' with: name: coverage-report path: coverage retention-days: 14 - name: Show coverage summary in log run: uv run coverage report