honcho/.github/workflows/unittest.yml

159 lines
4.4 KiB
YAML

name: FastAPI Tests with PostgreSQL and uv
on:
push:
branches: [main]
paths:
- '**.py'
- '**.ts'
- '**.js'
- '**.tsx'
- '**.jsx'
- 'pyproject.toml'
- 'uv.lock'
- 'sdks/typescript/package.json'
- 'sdks/typescript/bun.lock'
- '.github/workflows/unittest.yml'
pull_request:
branches: [main]
paths:
- '**.py'
- '**.ts'
- '**.js'
- '**.tsx'
- '**.jsx'
- 'pyproject.toml'
- 'uv.lock'
- 'sdks/typescript/package.json'
- 'sdks/typescript/bun.lock'
- '.github/workflows/unittest.yml'
permissions:
contents: read
pull-requests: read
jobs:
# Determine which tests to run based on changed files
changes:
runs-on: ubuntu-latest
outputs:
python: ${{ steps.filter.outputs.python }}
typescript: ${{ steps.filter.outputs.typescript }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
python:
- '**.py'
- 'pyproject.toml'
- 'uv.lock'
- 'migrations/**'
- '.github/workflows/unittest.yml'
typescript:
- 'sdks/typescript/**'
- '.github/workflows/unittest.yml'
test-python:
needs: changes
if: ${{ needs.changes.outputs.python == 'true' }}
runs-on: ubuntu-latest
services:
database:
image: pgvector/pgvector:pg15
env:
POSTGRES_DB: test_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"
- name: Install the project
run: uv sync --all-extras --dev
- name: Run Tests
run: uv run pytest -x
env:
DB_CONNECTION_URI: postgresql+psycopg://postgres:postgres@localhost:5432/test_db
AUTH_USE_AUTH: false
SENTRY_ENABLED: false
LLM_OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
LLM_ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
LLM_OPENAI_COMPATIBLE_API_KEY: test-key
LLM_OPENAI_COMPATIBLE_BASE_URL: http://localhost:8000
DERIVER_PROVIDER: openai
DERIVER_MODEL: test
DIALECTIC_PROVIDER: openai
DIALECTIC_MODEL: test
DIALECTIC_QUERY_GENERATION_PROVIDER: openai
DIALECTIC_QUERY_GENERATION_MODEL: test
SUMMARY_PROVIDER: openai
SUMMARY_MODEL: test
test-typescript:
needs: changes
if: ${{ needs.changes.outputs.typescript == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install TypeScript SDK dependencies
run: |
cd sdks/typescript
bun install
- name: Run TypeScript SDK tests
run: |
cd sdks/typescript
bun run test
env:
HONCHO_API_KEY: test-key
HONCHO_BASE_URL: http://localhost:8000
# Status check for branch protection rules
# This job always runs and reports success only if all required jobs pass
test-status:
runs-on: ubuntu-latest
needs: [changes, test-python, test-typescript]
if: always()
steps:
- name: Check test results
run: |
if [[ "${{ needs.changes.outputs.python }}" == "true" && "${{ needs.test-python.result }}" != "success" && "${{ needs.test-python.result }}" != "skipped" ]]; then
echo "Python tests failed or were cancelled"
exit 1
fi
if [[ "${{ needs.changes.outputs.typescript }}" == "true" && "${{ needs.test-typescript.result }}" != "success" && "${{ needs.test-typescript.result }}" != "skipped" ]]; then
echo "TypeScript tests failed or were cancelled"
exit 1
fi
echo "All required tests passed!"