Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,53 @@ jobs:
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- name: Run backend tests
env:
SUPERADMIN_LOGIN: dummy_login
SUPERADMIN_PWD: dummy&P@ssw0rd!
SUPERADMIN_ORG: dummyorga
POSTGRES_USER: dummy_pg_user
POSTGRES_PASSWORD: dummy_pg_pwd
POSTGRES_DB: dummy_pg_db
# Build while PostgreSQL and S3 download and become healthy.
- parallel:
- name: Start test services
run: docker compose -f docker-compose.dev.yml up -d --wait db localstack
- name: Build the test image
run: UV_GROUPS="server test" docker compose -f docker-compose.dev.yml build backend
- name: Create isolated test databases
run: |
UV_GROUPS="server test" docker compose -f docker-compose.dev.yml up -d --build --wait
docker compose -f docker-compose.dev.yml exec -T backend pytest --cov=app --cov-report xml tests/
docker compose -f docker-compose.dev.yml cp backend:/app/coverage.xml ./coverage-src.xml
for shard in api remaining; do
docker compose -f docker-compose.dev.yml exec -T db createdb -U dummy_pg_user "dummy_pg_db_$shard"
done
# Share one runner; separate databases and container hostnames isolate DB rows and S3 buckets.
- parallel:
- name: Run slow API tests
run: >
docker compose -f docker-compose.dev.yml run --rm --no-deps -T
-e POSTGRES_URL=postgresql+asyncpg://dummy_pg_user:dummy_pg_pwd@db/dummy_pg_db_api
-e COVERAGE_FILE=/app/.coverage.api
backend sh -c 'alembic upgrade head && python app/db.py && exec "$@"' --
pytest -o cache_dir=/tmp/pytest-cache --cov=app --cov-report=xml:/app/coverage-api.xml
tests/endpoints/test_{detections,sequences,camera_proxy,temporal_validation}.py
- name: Run all remaining backend tests
run: >
docker compose -f docker-compose.dev.yml run --rm --no-deps -T
-e POSTGRES_URL=postgresql+asyncpg://dummy_pg_user:dummy_pg_pwd@db/dummy_pg_db_remaining
-e COVERAGE_FILE=/app/.coverage.remaining
backend sh -c 'alembic upgrade head && python app/db.py && exec "$@"' --
pytest -o cache_dir=/tmp/pytest-cache --cov=app --cov-report=xml:/app/coverage-remaining.xml
tests/ --ignore=tests/endpoints/test_{detections,sequences,camera_proxy,temporal_validation}.py
- name: Run Telegram end-to-end check
env:
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
TELEGRAM_TEST_CHAT_ID: ${{ secrets.TELEGRAM_TEST_CHAT_ID }}
run: |
if [ -n "$TELEGRAM_TOKEN" ] && [ -n "$TELEGRAM_TEST_CHAT_ID" ]; then
docker compose -f docker-compose.dev.yml exec -T -e TELEGRAM_TOKEN -e TELEGRAM_TEST_CHAT_ID backend pytest tests/services/test_telegram.py -v
docker compose -f docker-compose.dev.yml run --rm --no-deps -T -e TELEGRAM_TOKEN -e TELEGRAM_TEST_CHAT_ID backend pytest tests/services/test_telegram.py -v
else
echo "TELEGRAM_TOKEN / TELEGRAM_TEST_CHAT_ID secrets not set, skipping"
fi
- name: Stop the stack
if: always()
background: true
run: docker compose -f docker-compose.dev.yml down
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v7
with:
files: ./coverage-src.xml
files: ./src/coverage-api.xml,./src/coverage-remaining.xml
flags: backend
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
Expand Down
Loading