Skip to content

Add Github test workflow #1

Add Github test workflow

Add Github test workflow #1

Workflow file for this run

name: Run Tests
on:
push:
branches:
- main
- dev
pull_request:
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
container:
image: python:3.11-slim
env:
DATABASE_URL: postgresql://postgres:password@postgres:5432/postgres
ENVIRONMENT: test
JWT_SECRET: test_secret
API_KEY: test_key
AZURE_STORAGE_CONNECTION_STRING: test_connection_string
AZURE_STORAGE_CONTAINER: test_container
PYTHONUNBUFFERED: "1"
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Display Python version and environment info
run: |
python -V
pip -V
env | sort
- name: Install system dependencies
run: |
apt-get update
apt-get install -y postgresql-client
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements_dev.txt
pip list
- name: Check PostgreSQL connection
run: |
echo "Waiting for PostgreSQL to be ready..."
timeout 20s bash -c 'until pg_isready -h postgres -p 5432 -U postgres; do sleep 1; done'
env:
PGPASSWORD: password
- name: Initialize database
run: |
set -e
echo "Initializing database with schema..."
PGPASSWORD=password psql -h postgres -U postgres -d postgres -f sql/create_tables.sql -v ON_ERROR_STOP=1
echo "Verifying tables..."
PGPASSWORD=password psql -h postgres -U postgres -d postgres -c "\dt" -t | wc -l | xargs -I {} test {} -gt 0
echo "Database initialization completed successfully"
env:
PGPASSWORD: password
- name: Run tests
run: |
python -m pytest tests/ -v --cov=src --cov-report=xml --cov-report=term-missing