Skip to content

Commit

Permalink
Copied latest fastapi templates and fixed github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamg9 committed May 8, 2024
1 parent adb7ea5 commit d4a0436
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Do NOT update manually; changes here will be overwritten by Copier
_commit: 3d28b2d
_commit: a1abb2b
_src_path: https://github.com/openg2p/openg2p-fastapi-template
github_ci_docker_build: true
github_ci_openapi_publish: true
Expand Down
22 changes: 13 additions & 9 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ jobs:
name: Docker Build and Push
runs-on: ubuntu-latest
env:
NAMESPACE: ${{ secrets.docker_hub_organisation }}
NAMESPACE: ${{ secrets.docker_hub_organisation | 'openg2p' }}
SERVICE_NAME: openg2p-selfservice-api
steps:
- uses: actions/checkout@v3
- name: Docker build and push
- name: Docker build
run: |
BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')
echo "${{ secrets.docker_hub_token }}" | docker login -u ${{ secrets.docker_hub_actor }} --password-stdin
if [ $? -ne 0 ];then
echo "::error::Failed to Login to dockerhub"
exit 1;
fi
IMAGE_ID=$NAMESPACE/$SERVICE_NAME
Expand All @@ -32,9 +27,18 @@ jobs:
fi
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo IMAGE_ID=$IMAGE_ID >> $GITHUB_ENV
echo VERSION=$VERSION >> $GITHUB_ENV
docker build . \
--file Dockerfile \
--tag $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
if [[ '${{ secrets.docker_hub_token }}' != '' && '${{ secrets.docker_hub_actor }}' != '' ]]; then
export DOCKER_PUSH="true"
echo DOCKER_PUSH=$DOCKER_PUSH >> $GITHUB_ENV
fi
- name: Docker push
if: env.DOCKER_PUSH == 'true'
run: |
echo "${{ secrets.docker_hub_token }}" | docker login -u ${{ secrets.docker_hub_actor }} --password-stdin
docker push ${{ env.IMAGE_ID }}:${{ env.VERSION }}
15 changes: 9 additions & 6 deletions .github/workflows/openapi-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ jobs:
python-version: "3.10"
- name: Install app
run: |
python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-fastapi-common\&subdirectory=openg2p-fastapi-common
python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-fastapi-auth\&subdirectory=openg2p-fastapi-auth
python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common@develop\#subdirectory=openg2p-fastapi-common
python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common@develop\#subdirectory=openg2p-fastapi-auth
python -m pip install .
- name: Generate openapi json
run: |
mkdir -p api-docs/generated
python3 main.py getOpenAPI api-docs/generated/openapi.json
if ! [ -z "$(git status --porcelain=v1 2>/dev/null -- api-docs/generated/openapi.json)" ]; then
export OPENAPI_CHANGED="true"
echo OPENAPI_CHANGED=$OPENAPI_CHANGED >> $GITHUB_ENV
shopt -s nocasematch
if [[ ${{ github.repository_owner }} == 'OpenG2P' ]]; then
export OPENAPI_CHANGED="true"
echo OPENAPI_CHANGED=$OPENAPI_CHANGED >> $GITHUB_ENV
fi
fi
- name: Commit Changes
uses: EndBug/add-and-commit@v7
Expand All @@ -38,10 +41,10 @@ jobs:
message: "Generated new openapi.json on push to ${{ github.event.inputs.git-ref }}"
add: "api-docs/generated/openapi.json"
- name: Setup nodejs
uses: actions/setup-node@v2
uses: actions/setup-node@v4
if: env.OPENAPI_CHANGED == 'true'
with:
node-version: '14'
node-version: '18'
- name: Publish to stoplight
if: env.OPENAPI_CHANGED == 'true'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.0
with:
extra_args: --all-files
extra_args: --all-files --show-diff-on-failure
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: Publish to PyPI

on:
release:
types:
- created
types: [published]

jobs:
publish-to-pypi:
Expand All @@ -13,6 +12,7 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: actions/checkout@v3
- name: Install build dependencies
run: pip install build
- name: Build distribution
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py }}
- name: Install tox
run: python -m pip install tox-gh>=1.2
- name: Setup test suite
run: tox -vv --notest
- name: Install test requirements
run: |
python -m pip install -r test-requirements.txt
python -m pip install -e .
- name: Run test suite
run: tox --skip-pkg-install
run: |
pytest --cov-branch --cov-report=term-missing --cov=openg2p_portal_api --cov=tests
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 0 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ignore = [
"B008", # do not perform function calls in argument defaults
"C901", # too complex
]
line-length = 110

[per-file-ignores]
"__init__.py" = ["F401"]
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ ADD --chown=${container_user}:${container_user_group} main.py /app
RUN python3 -m venv venv \
&& . ./venv/bin/activate
RUN python3 -m pip install \
git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-fastapi-common\&subdirectory=openg2p-fastapi-common \
git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-fastapi-auth\&subdirectory=openg2p-fastapi-auth \
git+https://github.com/openg2p/openg2p-fastapi-common@develop\#subdirectory=openg2p-fastapi-common \
git+https://github.com/openg2p/openg2p-fastapi-common@develop\#subdirectory=openg2p-fastapi-auth \
./src

CMD python3 main.py migrate; \
Expand Down
1 change: 1 addition & 0 deletions src/openg2p_portal_api/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ruff: noqa: E402

import asyncio

from .config import Settings
Expand Down
3 changes: 3 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest-cov
git+https://github.com/openg2p/openg2p-fastapi-common@develop#subdirectory=openg2p-fastapi-common
git+https://github.com/openg2p/openg2p-fastapi-common@develop#subdirectory=openg2p-fastapi-auth
16 changes: 0 additions & 16 deletions tests/base_setup.py

This file was deleted.

18 changes: 3 additions & 15 deletions tests/test_program_service.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
from fastapi.testclient import TestClient
from openg2p_fastapi_common.context import app_registry
from openg2p_portal_api.app import Initializer

# from .config import Settings
# _config = Settings.get_config()
from .base_setup import base_setup

base_setup()

client = TestClient(app_registry.get())


def test_read_main():
response = client.get("/programsummary")

assert response.status_code == 200
assert response.json() == {"msg": "Hello World"}
def test_program_service():
Initializer()
20 changes: 0 additions & 20 deletions tox.ini

This file was deleted.

0 comments on commit d4a0436

Please sign in to comment.