Skip to content

Commit

Permalink
chore: improve project configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kennedykori committed Aug 9, 2022
1 parent 5e83a5e commit 397a2cf
Show file tree
Hide file tree
Showing 103 changed files with 762 additions and 407 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
.pre-commit-config.yaml
.readthedocs.yml
.travis.yml
venv
venv
35 changes: 22 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ name: CI
on: [push]

env:
DOCKER_BUILDKIT: 1 # Enable Buildkit and let compose use it to speed up image building
COMPOSE_DOCKER_CLI_BUILD: 1
DJANGO_DEBUG: true
DJANGO_EMAIL_BACKEND: "${{ secrets.DJANGO_EMAIL_BACKEND }}"
DJANGO_GCP_STORAGE_BUCKET_NAME: "${{ secrets.DJANGO_GCP_STORAGE_BUCKET_NAME }}"
DJANGO_SECRET_KEY: "${{ secrets.DJANGO_SECRET_KEY }}"
USE_DOCKER: no
DOCKER_BUILDKIT: 1 # Enable Buildkit and let compose use it to speed up image building
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
GOOGLE_APPLICATION_CREDENTIALS: "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}"
POSTGRES_DB: postgres
POSTGRES_HOST: localhost
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: 5432
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
GOOGLE_APPLICATION_CREDENTIALS: "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}"
DJANGO_GCP_STORAGE_BUCKET_NAME: "${{ secrets.DJANGO_GCP_STORAGE_BUCKET_NAME }}"
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
DJANGO_EMAIL_BACKEND: "${{ secrets.DJANGO_EMAIL_BACKEND }}"
TEST_POSTGRES_DB: idr_server_test
TEST_POSTGRES_HOST: localhost
TEST_POSTGRES_PASSWORD: postgres
TEST_POSTGRES_PORT: 5432
TEST_POSTGRES_USER: postgres
USE_DOCKER: no

jobs:
build:
Expand Down Expand Up @@ -51,15 +56,19 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

# Run all pre-commit hooks on all the files.
# Getting only staged files can be tricky in case a new PR is opened
# since the action is run on a branch in detached head state
- name: Install and run pre-commit
uses: pre-commit/action@v3.0.0

- name: Install Requirements
run: |
sudo apt-get update
sudo apt-get install postgis gdal-bin libgdal-dev
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m pip install tox tox-gh-actions
npm ci
- name: Setup Django
run: |
python manage.py migrate
python manage.py collectstatic --noinput
- name: Test with tox
run: tox -re "py39,py310,coveralls"
33 changes: 33 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release

on:
push:
branches:
- chore-improve-project-configuration

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: 'lts/*'

- name: Install requirements
run: |
sudo apt-get update
sudo apt-get install python3.10 nodejs
npm install @semantic-release/changelog @semantic-release/git
# pip install -r requirements/base.txt

- name: Create a release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: "docs|node_modules|migrations|.git|.tox"
default_stages: [commit]
# fail_fast: true
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black

- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
hooks:
- id: isort
args: ["--profile", "black"]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
args: ["--config=tox.ini"]
additional_dependencies: [flake8-isort]

# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
ci:
autoupdate_schedule: weekly
skip: []
submodules: false
16 changes: 16 additions & 0 deletions .releaserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
branches: ["chore-improve-project-configuration"]
dryRun: false
plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- ["@semantic-release/changelog",
changelogFile: "docs/CHANGELOG.md"
]
- ["@semantic-release/git", {
"assets": [ "docs/*" ],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
- "@semantic-release/github"

tagFormat: v${version}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# IDR Server

IDR(Integrated Data Repository) Server is a service that houses metadata
for/and receives extracted data from ICDR Clients.
IDR(Integrated Data Repository) Server is a service that houses extract metadata
for/and receives extracted data from [IDR Clients](https://github.com/savannahghi/idr-client).

[![Coverage Status](https://coveralls.io/repos/github/savannahghi/idr-server/badge.svg)](https://coveralls.io/github/savannahghi/idr-server)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
3 changes: 0 additions & 3 deletions apps/app_auth/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.contrib import admin

# Register your models here.
1 change: 1 addition & 0 deletions apps/app_auth/apiviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

class LoginView(KnoxLoginView):
"""The default endpoint for API login."""

authentication_classes = (BasicAuthentication,)
3 changes: 0 additions & 3 deletions apps/app_auth/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.db import models

# Create your models here.
2 changes: 1 addition & 1 deletion apps/app_auth/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.test import TestCase
# from django.test import TestCase

# Create your tests here.
5 changes: 2 additions & 3 deletions apps/app_auth/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from django.urls import path
from knox.views import LogoutView, LogoutAllView
from knox.views import LogoutAllView, LogoutView

from .apiviews import LoginView


urlpatterns = [
path("auth/login/", LoginView.as_view(), name="api_login"),
path("auth/logout/", LogoutView.as_view(), name="api_logout"),
path("auth/logoutall/", LogoutAllView.as_view(), name="api_logoutall")
path("auth/logoutall/", LogoutAllView.as_view(), name="api_logoutall"),
]
2 changes: 1 addition & 1 deletion apps/app_auth/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.shortcuts import render
# from django.shortcuts import render

# Create your views here.
1 change: 1 addition & 0 deletions apps/common/apiviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

class GenericSourceViewSet(AuditBaseViewSet):
"""Generic Source API."""

queryset = GenericSource.objects.all()
serializer_class = GenericSourceSerializer
8 changes: 5 additions & 3 deletions apps/common/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Generated by Django 4.0.4 on 2022-06-09 07:38

import apps.core.models
import uuid

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid

import apps.core.models


class Migration(migrations.Migration):
Expand Down
3 changes: 2 additions & 1 deletion apps/common/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from apps.core.models import AbstractDataSource


# =============================================================================
# COMMON MODELS
# =============================================================================


class GenericSource(AbstractDataSource):
"""This is a generic data source."""

...
1 change: 0 additions & 1 deletion apps/common/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class GenericSourceSerializer(AuditBaseSerializer):

class Meta:
model = GenericSource
fields = "__all__"
2 changes: 1 addition & 1 deletion apps/common/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.test import TestCase
# from django.test import TestCase

# Create your tests here.
6 changes: 1 addition & 5 deletions apps/common/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from django.urls import include, path

from rest_framework.routers import DefaultRouter

from .apiviews import GenericSourceViewSet


router = DefaultRouter()
router.register("generic_sources", GenericSourceViewSet)


urlpatterns = [
path("", include(router.urls))
]
urlpatterns = [path("", include(router.urls))]
2 changes: 1 addition & 1 deletion apps/common/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.shortcuts import render
# from django.shortcuts import render

# Create your views here.
19 changes: 14 additions & 5 deletions apps/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class BaseModelAdmin(admin.ModelAdmin):
"""
This is the base `ModelAdmin` for this project
"""

...


Expand All @@ -13,6 +14,7 @@ class AuditBaseModelAdmin(BaseModelAdmin):
This is the base `ModelAdmin` for all `AuditBaseModel` models in this
project.
"""

date_hierarchy = "updated_at"

def __init__(self, *args, **kwargs):
Expand All @@ -21,7 +23,10 @@ def __init__(self, *args, **kwargs):
# self.audit_details_fieldset,
# )
self.readonly_fields = (
"created_at", "created_by", "updated_at", "updated_by"
"created_at",
"created_by",
"updated_at",
"updated_by",
)

@property
Expand All @@ -33,12 +38,16 @@ def audit_details_fieldset(self):
:return: a field set of fields that define/hold audit data.
"""
return (
"Audit Details", {
"Audit Details",
{
"classes": ("collapse",),
"fields": (
"created_at", "created_by", "updated_at", "updated_by"
)
}
"created_at",
"created_by",
"updated_at",
"updated_by",
),
},
)

def save_model(self, request, obj, form, change):
Expand Down
2 changes: 2 additions & 0 deletions apps/core/apiviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ class BaseViewSet(ModelViewSet):
"""
This is the base `ViewSet` from which all other view sets are derived from.
"""

...


class AuditBaseViewSet(BaseViewSet):
"""
This is the base `ViewSet` for all `AuditBase` models in this project.
"""

...
Loading

0 comments on commit 397a2cf

Please sign in to comment.