Merge pull request #1 from peterrrock2/dev #46
This file contains 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: GerryDB client tests | |
on: | |
workflow_dispatch: | |
push: | |
pull_request: | |
jobs: | |
run: | |
name: Run tests Linux | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgis/postgis:16-3.4 | |
ports: | |
- 54320:5432 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: dev | |
POSTGRES_DB: gerrydb | |
options: >- | |
--health-cmd "pg_isready -U postgres" | |
--health-interval 10s | |
--health-timeout 20s | |
--health-retries 10 | |
strategy: | |
matrix: | |
python-version: ['3.10', '3.12'] | |
env: | |
OS: ${{ matrix.os }} | |
PYTHON: ${{ matrix.python-version }} | |
GERRYDB_DATABASE_URI: "postgresql://postgres:dev@localhost:54320/gerrydb" | |
GERRYDB_TEST_SERVER: "localhost:8000" | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: dev | |
POSTGRES_DB: gerrydb | |
steps: | |
- name: Checkout repository into custom directory | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install PostgreSQL client tools | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y postgresql-client | |
- name: Install GDAL | |
run: | | |
sudo apt-get install -y gdal-bin | |
- name: Clone backend repo | |
run: | | |
git clone --branch dev https://github.com/mggg/gerrydb-meta.git ../gerrydb-meta | |
- name: Install dependencies | |
run: | | |
cd .. | |
python -m venv .venv | |
source .venv/bin/activate | |
pip install --upgrade pip | |
pip install poetry | |
pip install black isort | |
pip install ./gerrydb-client-py/ | |
pip install ./gerrydb-meta/ | |
- name: Set up GerryDB and get API key | |
run: | | |
cd .. | |
source .venv/bin/activate | |
cd ./gerrydb-meta | |
echo "export GERRYDB_TEST_API_KEY=$(python init.py --name test --email test --reset)" > ../.env | |
echo "export GERRYDB_TEST_SERVER=localhost:8000" >> ../.env | |
- name: Wait for PostgreSQL to be ready | |
run: | | |
until pg_isready -h 127.0.0.1 -p 54320 -U postgres; do | |
echo "Waiting for PostgreSQL to be ready..." | |
sleep 2 | |
done | |
- name: Check the postgres | |
run: | | |
PGPASSWORD=dev psql -h 127.0.0.1 -p 54320 -U postgres -c '\l' | |
PGPASSWORD=dev psql -h 127.0.0.1 -p 54320 -U postgres -d gerrydb -c 'SELECT postgis_version();' | |
- name: Start the uvicorn server | |
run: | | |
source ../.venv/bin/activate | |
source ../.env | |
cd ../gerrydb-meta | |
nohup uvicorn gerrydb_meta.main:app --host 0.0.0.0 --port 8000 --log-level trace > uvicorn.log 2>&1 & | |
- name: Wait for Uvicorn to be ready | |
run: | | |
until curl -s http://localhost:8000/api/v1 > /dev/null; do | |
echo "Waiting for Uvicorn to be ready..." | |
sleep 2 | |
done | |
- name: Run tests and generate coverage report | |
run: | | |
source ../.venv/bin/activate | |
source ../.env | |
pip install pytest pytest-cov | |
pytest -v -s tests --cov=./ --cov-report=xml | |
- name: Print Uvicorn logs on Failure | |
if: failure() | |
run: | | |
echo "Displaying Uvicorn logs:" | |
cat ../gerrydb-meta/uvicorn.log | |