Skip to content

Commit

Permalink
chore(conf): 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 3185cc3
Show file tree
Hide file tree
Showing 103 changed files with 846 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"
83 changes: 83 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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 conventional-changelog-conventionalcommits
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5
env:
GPG_KEY: ${{ secrets.GPG_KEY }}
with:
git_commit_gpgsign: true
git_committer_email: ${{ secrets.GIT_COMMITTER_EMAIL }}
git_committer_name: ${{ secrets.GIT_COMMITTER_NAME }}
git_tag_gpgsign: true
git_user_signingkey: true
gpg_private_key: ${{ secrets.GPG_KEY }}
passphrase: ${{ secrets.GPG_KEY_PASSPHRASE }}

# - name: Import GPG key
# run: echo $GPG_KEY | base64 -i --decode | gpg --batch --import
# env:
# GPG_KEY: ${{ secrets.GPG_KEY }}
#
# - name: Add the custom gpg signing program that passes the passphrase to the gpg CLI
# run: |
# rm -rf /tmp/gpg.sh
# echo '#!/bin/bash' >> /tmp/gpg.sh
# echo 'gpg --batch --pinentry-mode=loopback --passphrase $GPG_KEY_PASSPHRASE $@' >> /tmp/gpg.sh
# chmod +x /tmp/gpg.sh
#
# - name: Setup git
# run: |
# git config --global commit.gpgsign true
# git config --global tag.gpgsign true
# git config --global user.signingkey $GPG_KEY_ID
# git config --global gpg.program /tmp/gpg.sh
# env:
# GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}

- name: Test sign
run: |
echo 'Something' >> test.md
git add test.md
GIT_TRACE=2 git commit -m "test commit"
git verify-commit $( git rev-parse HEAD )
env:
GPG_KEY_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }}
GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }}
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }}
GIT_AUTHOR_NAME: SomeBot
GIT_AUTHOR_EMAIL: somebot@example.com

- name: Create a release
run: npx semantic-release
env:
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_COMMITTER_NAME }}
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }}
GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_KEY_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }}
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
50 changes: 50 additions & 0 deletions .releaserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
branches: ["chore-improve-project-configuration"]
debug: false
dryRun: false
plugins:
- ["@semantic-release/commit-analyzer", {
parserOpts: {
noteKeywords: [ "BREAKING CHANGE", "BREAKING CHANGES", "BREAKING" ],
},
preset: "angular",
releaseRules: [
{type: "chore", scope: "conf", release: "patch"},
{type: "chore", scope: "config", release: "patch"},
{type: "chore", scope: "core", release: "minor"},
{type: "chore", scope: "deps", release: "patch"}
]
}
]
- ["@semantic-release/release-notes-generator", {
parserOpts: {
noteKeywords: [ "BREAKING CHANGE", "BREAKING CHANGES", "BREAKING" ],
},
preset: "conventionalcommits",
presetConfig: {
types: [
{ type: "chore", scope: "deps", section: "Dependency Updates" },
{ type: "chore", section: "Refactors" },
{ type: "docs", hidden: true },
{ type: "feat", section: "Features" },
{ type: "fix", section: "Bug Fixes" },
{ type: "perf", hidden: true },
{ type: "refactor", section: "Refactors" },
{ type: "style", hidden: true },
{ type: "test", hidden: true }
]
},
writerOpts: {
commitsSort: [ "subject", "scope" ],
}
}
]
- ["@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.
Loading

0 comments on commit 3185cc3

Please sign in to comment.