Skip to content

Commit

Permalink
Test & Deploy Automation (#4)
Browse files Browse the repository at this point in the history
* gh workflow

* include tox in test deps

* update ci

* tweak ci env vars

* tweak creds path

* tweak ci

* add strategy

* fix ci bug

* new lint job

* update black

* update black args

* add Build-Deploy job to ci
  • Loading branch information
zachspar authored Dec 6, 2023
1 parent a1dbd33 commit 82238c8
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 8 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/test_build_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Test, Build & Deploy FireFrame
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
PROJECT_ID: ${{ secrets.FIREBASE_TEST_PROJECT_ID }}
jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: 'actions/checkout@v4'
- uses: 'psf/black@stable'
with:
version: '23.11.0'
src: './'
options: '--line-length 120 --check'
Test:
needs: Lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: 'actions/checkout@v4'
- uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
- run: |
gcloud config set project $PROJECT_ID
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[test]
- name: Run tests
env:
GOOGLE_CLOUD_PROJECT: ${{ secrets.FIREBASE_TEST_PROJECT_ID }}
run: |
export GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_GHA_CREDS_PATH
pytest -n 4
Build-Deploy:
needs: [Lint, Test]
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- uses: 'actions/checkout@v4'
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dev = [
test = [
"httpx==0.25.2",
"pytest==7.4.3",
"pytest-xdist==3.5.0",
]

[project.scripts]
Expand Down
25 changes: 24 additions & 1 deletion sample_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""A sample FireFrame API."""
from fireframe.core.api import FireFrameAPI
from fireframe.core.views import BaseListAPIView
from fireframe.core.viewsets import crud_viewset
from fireframe.core.models import Model
from fireframe.core.serializers import ModelSerializer
Expand Down Expand Up @@ -60,8 +61,30 @@ class Meta:
fields = ["name", "price", "is_offer", "stock"]


class ItemListView(BaseListAPIView):
"""
Item list view.
Inherits from FireFrame's BaseListAPIView.
"""

serializer_class = ItemSerializer


class UserListView(BaseListAPIView):
"""
User list view.
Inherits from FireFrame's BaseListAPIView.
"""

serializer_class = UserSerializer


app = FireFrameAPI(title="Sample FireFrame App", version="0.0.0")

# routes from mixin
# include routes from viewsets and views
app.include_router(crud_viewset(UserSerializer), tags=["Users"], prefix="/users")
app.include_router(UserListView(), tags=["Users"], prefix="/users")
app.include_router(crud_viewset(ItemSerializer), tags=["Items"], prefix="/items")
app.include_router(ItemListView(), tags=["Items"], prefix="/items")
2 changes: 1 addition & 1 deletion tests/views/test_create_api_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from fireframe.core.api import FireFrameAPI
from fireframe.core.serializers import ModelSerializer
from fireframe.core.views import BaseCreateAPIView
from ._fixtures import test_model_primitive_2
from ._fixtures import test_model_primitive_2, test_thread


class TestCreateAPIView:
Expand Down
2 changes: 1 addition & 1 deletion tests/views/test_delete_api_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from fireframe.core.api import FireFrameAPI
from fireframe.core.serializers import ModelSerializer
from fireframe.core.views import BaseDestroyAPIView
from ._fixtures import test_model_primitive_1
from ._fixtures import test_model_primitive_1, test_thread


class TestDestroyAPIView:
Expand Down
2 changes: 1 addition & 1 deletion tests/views/test_retrieve_api_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from fireframe.core.api import FireFrameAPI
from fireframe.core.serializers import ModelSerializer
from fireframe.core.views import BaseRetrieveAPIView
from ._fixtures import test_model_primitive_1
from ._fixtures import test_model_primitive_1, test_thread


class TestRetrieveAPIView:
Expand Down
2 changes: 1 addition & 1 deletion tests/views/test_update_api_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fireframe.core.api import FireFrameAPI
from fireframe.core.serializers import ModelSerializer
from fireframe.core.views import BaseUpdateAPIView
from ._fixtures import test_model_primitive_1
from ._fixtures import test_model_primitive_1, test_thread


class TestUpdateAPIView:
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
envlist = py38,py39,py310,py311

[testenv]
deps = pytest # PYPI package providing pytest
extras = test # Install test dependencies
commands = pytest {posargs} # substitute with tox' positional arguments
deps = pytest # PYPI package providing pytest
extras = test # Install test dependencies
commands = pytest -n 4 {posargs} # Substitute with tox positional arguments

0 comments on commit 82238c8

Please sign in to comment.