Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devops: add GitHub action workflow for PRs #18

Merged
merged 2 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
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
Empty file removed .github/workflows/.gitkeep
Empty file.
61 changes: 61 additions & 0 deletions .github/workflows/fastapi-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: FastAPI Server

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
test-server:
runs-on: ubuntu-latest
environment: test
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Setup PostgreSQL with extensions and unprivileged user
uses: Daniel-Marynicz/postgresql-action@1.0.0
with:
postgres_image_tag: latest
postgres_image_name: postgis/postgis
postgres_user: postgres
postgres_db: postgres
postgres_password: postgres
postgres_extensions: postgis
# app_user: # optional, default is app
# app_user_password: # optional, default is app
# APP_DB - database or list of databases separated by space for unprivileged postgres user
# exposed_postgres_port: # optional, default is 5432
- name: Seed DB
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
PYTHONPATH: .:src
run: |
sleep 10;
poetry run alembic upgrade head
poetry run python server/seed_initial_data.py
- name: Run tests
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
PYTHONPATH: .:src
# TODO: incorporate coverage reporting
run: |
poetry run pytest
3 changes: 3 additions & 0 deletions server/core/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from functools import lru_cache

from dotenv import load_dotenv
from pydantic import BaseSettings

load_dotenv()

API_V1_STR = "/api/v1"


Expand Down
12 changes: 5 additions & 7 deletions server/schemas/buoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ class BuoyBase(BaseModel):
dart: Optional[str] = "n"
seq: Optional[int] = None # tao_seq

@validator("location", pre=True, allow_reuse=True, always=True)
def correct_location_format(cls, v):
if not isinstance(v, WKBElement):
raise ValueError("Must be a valid WKBE element")
return ewkb_to_wkt(v)


# Properties to receive on item creation
class BuoyCreate(BuoyBase):
Expand All @@ -48,7 +42,11 @@ class Config:

# Properties to return to client
class Buoy(BuoyInDBBase):
...
@validator("location", pre=True, allow_reuse=True, always=True)
def correct_location_format(cls, v):
if not isinstance(v, WKBElement):
raise ValueError("Must be a valid WKBE element")
return ewkb_to_wkt(v)


# Properties properties stored in DB
Expand Down
12 changes: 6 additions & 6 deletions server/schemas/coastline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ class CoastlineBase(BaseModel):
geom: str # Geography(geometry_type="MULTILINE")
station_id: str

@validator("geom", pre=True, allow_reuse=True, always=True)
def correct_geom_format(cls, v):
if not isinstance(v, WKBElement):
raise ValueError("Must be a valid WKBE element")
return ewkb_to_wkt(v)


# Properties to receive on item creation
class CoastlineCreate(CoastlineBase):
Expand All @@ -41,6 +35,12 @@ class Config:
class Coastline(CoastlineInDBBase):
buoy: Optional[Buoy]

@validator("geom", pre=True, allow_reuse=True, always=True)
def correct_geom_format(cls, v):
if not isinstance(v, WKBElement):
raise ValueError("Must be a valid WKBE element")
return ewkb_to_wkt(v)


# Properties properties stored in DB
class CoastlineInDB(CoastlineInDBBase):
Expand Down
1 change: 1 addition & 0 deletions server/seed_initial_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from server.db.init_db import init_db
from server.db.session import AsyncSessionLocal

# TODO: minimize DB query logs in CI/CD
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion server/services/buoy/seed_buoys.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def parse_activestations(stations):
for station in stations:
station = station.attrs
lon, lat = float(station.get("lon", 0.0)), float(station.get("lat", 0.0))
geo = f"Point({lon} {lat})"
geo = f"POINT({lon} {lat})"
kylejb marked this conversation as resolved.
Show resolved Hide resolved

parsed_stations_obj.append(
BuoyCreate(
Expand Down
2 changes: 0 additions & 2 deletions server/services/coastline/seed_coastline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from sqlalchemy.ext.asyncio import AsyncSession

from server.crud.crud_coastline import coastline
from server.schemas.coastline import CoastlineCreate

Expand Down