Skip to content
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
46 changes: 40 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ jobs:
- name: Checkout Code Repository
uses: actions/checkout@v2
- name: Build the Stack
run: docker-compose -f local.yml build
run: docker compose -f local.yml build
- name: Make DB Migrations
run: docker-compose -f local.yml run --rm django python manage.py migrate
run: docker compose -f local.yml run --rm django python manage.py migrate
- name: Run the Stack
run: docker-compose -f local.yml up -d
run: docker compose -f local.yml up -d
- name: Run Django Tests
run: docker-compose -f local.yml exec -T django coverage run --rcfile=.pre-commit/setup.cfg -m pytest --disable-pytest-warnings;
run: docker compose -f local.yml exec -T django coverage run --rcfile=.pre-commit/setup.cfg -m pytest --disable-pytest-warnings;
- name: Print Coverage
run: docker-compose -f local.yml exec -T django coverage report
run: docker compose -f local.yml exec -T django coverage report
- name: Tear down the Stack
run: docker-compose -f local.yml down
run: docker compose -f local.yml down

deploy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -86,6 +86,40 @@ jobs:
heroku_email: ${{ secrets.HEROKU_EMAIL }}
remote_branch: master


publish-docker-image:
name: Publish Docker image to ghcr.io
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main'
needs:
- unittest
- precommit
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./compose/production/django/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

bump:
if: "github.event_name == 'push' && github.ref == 'refs/heads/main'"
runs-on: ubuntu-latest
Expand Down
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ repos:
repo: local

- hooks:
- exclude: (/settings/)
- exclude: (/settings/|/migrations/)
id: black
args:
- --config=.pre-commit/pyproject.toml
Expand All @@ -52,12 +52,13 @@ repos:
- --config=.pre-commit/setup.cfg
id: flake8
language_version: python3
exclude: (/settings/|/migrations/)
repo: https://github.com/PyCQA/flake8
rev: 7.0.0

- hooks:
- entry: pylint --rcfile=.pre-commit/.pylintrc
exclude: (/settings/)
exclude: (/settings/|/migrations/)
files: \.py$
id: system
language: system
Expand All @@ -66,6 +67,7 @@ repos:

- hooks:
- id: commitizen
exclude: (/settings/|/migrations/)
stages:
- commit-msg
args:
Expand All @@ -76,5 +78,6 @@ repos:
- hooks:
- id: bandit
args: [ --verbose, -ll, . ]
exclude: (/settings/|/migrations/)
repo: https://github.com/PyCQA/bandit
rev: 1.7.7
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ pre-commit:
pre-commit run --all-files

build:
docker-compose -f ${COMPOSE_ENV}.yml build
docker compose -f ${COMPOSE_ENV}.yml build

run: build
docker-compose -f ${COMPOSE_ENV}.yml up -d
docker compose -f ${COMPOSE_ENV}.yml up -d

migrate:
docker-compose -f ${COMPOSE_ENV}.yml exec -T django bash -c "python manage.py makemigrations && python manage.py migrate"
docker compose -f ${COMPOSE_ENV}.yml exec -T django bash -c "python manage.py makemigrations && python manage.py migrate"

test:
docker-compose -f ${COMPOSE_ENV}.yml exec -T django coverage run --rcfile=.pre-commit/setup.cfg -m pytest ${target} --disable-pytest-warnings;
docker compose -f ${COMPOSE_ENV}.yml exec -T django coverage run --rcfile=.pre-commit/setup.cfg -m pytest ${target} --disable-pytest-warnings;

test-one:
docker-compose -f ${COMPOSE_ENV}.yml exec -T django coverage run --rcfile=.pre-commit/setup.cfg -m pytest ${file} -k ${test_name} --disable-pytest-warnings;
docker compose -f ${COMPOSE_ENV}.yml exec -T django coverage run --rcfile=.pre-commit/setup.cfg -m pytest ${file} -k ${test_name} --disable-pytest-warnings;

cover:
docker-compose -f ${COMPOSE_ENV}.yml exec -T django coverage report
docker compose -f ${COMPOSE_ENV}.yml exec -T django coverage report

teardown:
docker-compose -f ${COMPOSE_ENV}.yml down -v
docker compose -f ${COMPOSE_ENV}.yml down -v

recreate: teardown run
1 change: 0 additions & 1 deletion config/api_router.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.urls import include, path
from rest_framework.routers import DefaultRouter

from tmh_registry.users.api.viewsets import UserViewSet

router = DefaultRouter()
Expand Down
2 changes: 0 additions & 2 deletions local.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

volumes:
local_postgres_data: {}
local_postgres_data_backups: {}
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ uvicorn[standard]==0.18.0 # https://github.com/encode/uvicorn
# Django
# ------------------------------------------------------------------------------
django-storages[boto3]==1.11.1 # https://github.com/jschneier/django-storages
django==3.1.3 # https://www.djangoproject.com/
django==3.2.25 # https://www.djangoproject.com/
django-environ==0.4.5 # https://github.com/joke2k/django-environ
django-model-utils==4.1.1 # https://github.com/jazzband/django-model-utils
django-crispy-forms==1.12.0 # https://github.com/django-crispy-forms/django-crispy-forms
Expand Down
40 changes: 20 additions & 20 deletions requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ watchgod==0.7 # https://github.com/samuelcolvin/watchgod

# Testing
# ------------------------------------------------------------------------------
mypy==0.790 # https://github.com/python/mypy
django-stubs==1.8.0 # https://github.com/typeddjango/django-stubs
pytest==6.1.2 # https://github.com/pytest-dev/pytest
pytest-sugar==0.9.4 # https://github.com/Frozenball/pytest-sugar
mock==4.0.3 # https://pypi.org/project/mock/
freezegun==1.1.0 # https://pypi.org/project/freezegun/0.1.11/
faker==8.5.1 # https://github.com/joke2k/faker
parameterized==0.8.1 # https://github.com/wolever/parameterized
mypy==1.5.1 # https://github.com/python/mypy
django-stubs==4.2.3 # https://github.com/typeddjango/django-stubs
pytest==7.4.3 # https://github.com/pytest-dev/pytest
pytest-sugar==0.9.7 # https://github.com/Frozenball/pytest-sugar
mock==5.1.0 # https://pypi.org/project/mock/
freezegun==1.2.2 # https://pypi.org/project/freezegun/
faker==19.3.1 # https://github.com/joke2k/faker
parameterized==0.9.0 # https://github.com/wolever/parameterized

# Code quality
# ------------------------------------------------------------------------------
flake8==3.8.4 # https://github.com/PyCQA/flake8
flake8-isort==4.0.0 # https://github.com/gforcada/flake8-isort
coverage==5.5 # https://github.com/nedbat/coveragepy
black==20.8b1 # https://github.com/ambv/black
pylint-django==2.5.4 # https://github.com/PyCQA/pylint-django
pre-commit==2.10.1 # https://github.com/pre-commit/pre-commit
isort==4.3.21 # https://github.com/PyCQA/isort
flake8==6.1.0 # https://github.com/PyCQA/flake8
flake8-isort==6.0.0 # https://github.com/gforcada/flake8-isort
coverage==7.3.2 # https://github.com/nedbat/coveragepy
black==23.9.1 # https://github.com/psycopg/black
pylint-django==2.5.3 # https://github.com/PyCQA/pylint-django
pre-commit==3.5.0 # https://github.com/pre-commit/pre-commit
isort==5.12.0 # https://github.com/PyCQA/isort

# Django
# ------------------------------------------------------------------------------
factory-boy==3.2.0 # https://github.com/FactoryBoy/factory_boy
django-debug-toolbar==3.1.1 # https://github.com/jazzband/django-debug-toolbar
django-extensions==3.1.3 # https://github.com/django-extensions/django-extensions
django-coverage-plugin==2.0.0 # https://github.com/nedbat/django_coverage_plugin
pytest-django==4.1.0 # https://github.com/pytest-dev/pytest-django
factory-boy==3.3.0 # https://github.com/FactoryBoy/factory_boy
django-debug-toolbar==4.2.0 # https://github.com/jazzband/django-debug-toolbar
django-extensions==3.2.3 # https://github.com/django-extensions/django-extensions
django-coverage-plugin==3.1.0 # https://github.com/nedbat/django_coverage_plugin
pytest-django==4.7.0 # https://github.com/pytest-dev/pytest-django
1 change: 0 additions & 1 deletion tmh_registry/common/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
HTTP_405_METHOD_NOT_ALLOWED,
HTTP_500_INTERNAL_SERVER_ERROR,
)

from tmh_registry.common.exceptions import ProjectAPIException

logger = getLogger(__name__)
Expand Down
1 change: 0 additions & 1 deletion tmh_registry/common/tests/test_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
HTTP_404_NOT_FOUND,
HTTP_405_METHOD_NOT_ALLOWED,
)

from tmh_registry.common.error_handling import (
error_handler,
get_exception_handling_dict,
Expand Down
17 changes: 13 additions & 4 deletions tmh_registry/registry/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
from django.contrib.auth.models import User
from import_export import resources
from import_export.admin import ExportMixin

from tmh_registry.registry.models import (
Announcement,
Discharge,
Episode,
FollowUp,
Hospital,
HospitalRegionMapping,
Patient,
PatientHospitalMapping,
PreferredHospital,
Zone,
Region,
HospitalRegionMapping,
RegionZoneMapping, Announcement,
RegionZoneMapping,
Zone,
)


Expand Down Expand Up @@ -43,33 +43,42 @@ class PatientAdmin(ExportMixin, admin.ModelAdmin):
class PatientHospitalMappingAdmin(ExportMixin, admin.ModelAdmin):
model = PatientHospitalMapping


@admin.register(PreferredHospital)
class PreferredHospitalAdmin(ExportMixin, admin.ModelAdmin):
model = PreferredHospital


@admin.register(Episode)
class EpisodeAdmin(ExportMixin, admin.ModelAdmin):
model = Episode


@admin.register(Zone)
class ZoneAdmin(ExportMixin, admin.ModelAdmin):
model = Zone


@admin.register(Region)
class RegionAdmin(ExportMixin, admin.ModelAdmin):
model = Region


@admin.register(HospitalRegionMapping)
class HospitalRegionMappingAdmin(ExportMixin, admin.ModelAdmin):
model = HospitalRegionMapping


@admin.register(RegionZoneMapping)
class RegionZoneMappingAdmin(ExportMixin, admin.ModelAdmin):
model = RegionZoneMapping


@admin.register(Announcement)
class AnnouncementAdmin(ExportMixin, admin.ModelAdmin):
model = Announcement


"""
To allow CSV export on User model
"""
Expand Down
Loading