Add github actions CI (black, mypy, django tests)
This commit is contained in:
Ethan Roseman 2022-08-25 12:41:19 +09:00 committed by GitHub
parent 2624839689
commit 3e8b5809a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 66 additions and 20 deletions

40
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,40 @@
name: CI
on:
push:
branches:
- main
pull_request:
jobs:
full_test_and_build:
name: full test and build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.9
- uses: snok/install-poetry@v1
- run: poetry install
- name: Run backend tests
run: |-
poetry run python3 manage.py test
mypy:
name: mypy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.9
- uses: snok/install-poetry@v1
- run: |-
poetry install
poetry run mypy
black:
name: black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
with:
src: "."

View File

@ -2,5 +2,5 @@ from django.apps import AppConfig
class FrogApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'frog_api'
default_auto_field = "django.db.models.BigAutoField"
name = "frog_api"

View File

@ -8,7 +8,7 @@ class Migration(migrations.Migration):
initial = True
dependencies = []
dependencies: list[tuple[str, str]] = []
operations = [
migrations.CreateModel(

View File

@ -1,6 +1,8 @@
from typing import Any
from rest_framework import status
from rest_framework.exceptions import APIException
from rest_framework.response import Response
from rest_framework.request import Request
from rest_framework.views import APIView
from frog_api.models import Category, Entry, Project, Version
@ -19,7 +21,7 @@ class ProjectView(APIView):
API endpoint that allows projects to be viewed.
"""
def get(self, request, format=None):
def get(self, request: Request) -> Response:
"""
Return a list of all projects.
"""
@ -28,11 +30,9 @@ class ProjectView(APIView):
return Response(serializer.data)
def get_latest_entry(project, version, category) -> dict:
def get_latest_entry(project: str, version: str, category: str) -> dict[Any, Any]:
if not Project.objects.filter(slug=project).exists():
raise MissingModelException(
f"Project {project} not found", code=status.HTTP_404_NOT_FOUND
)
raise MissingModelException(f"Project {project} not found")
if not Version.objects.filter(slug=version, project__slug=project).exists():
raise MissingModelException(
@ -63,7 +63,7 @@ def get_latest_entry(project, version, category) -> dict:
return entry_data
def get_versions_digest_for_project(project) -> dict:
def get_versions_digest_for_project(project: str) -> dict[Any, Any]:
versions = {}
for version in Version.objects.filter(project__slug=project):
entry = get_latest_entry(project, version.slug, "total")
@ -77,7 +77,7 @@ class RootDigestView(APIView):
API endpoint that returns the most recent entry for each version of each project.
"""
def get(self, request):
def get(self, request: Request) -> Response:
"""
Return the most recent entry for ovreall progress for each version of each project.
"""
@ -96,7 +96,7 @@ class ProjectDigestView(APIView):
API endpoint that returns the most recent entry for each version of a project.
"""
def get(self, request, project):
def get(self, request: Request, project: str) -> Response:
"""
Return the most recent entry for overall progress for each version of a project.
"""
@ -118,7 +118,7 @@ class VersionDigestView(APIView):
API endpoint that returns the most recent entry for overall progress for a version of a project.
"""
def get(self, request, project, version):
def get(self, request: Request, project: str, version: str) -> Response:
"""
Return the most recent entry for overall progress for a version of a project.
"""
@ -133,7 +133,9 @@ class CategoryDigestView(APIView):
API endpoint that returns the most recent entry for a specific cagory and a version of a project.
"""
def get(self, request, project, version, category):
def get(
self, request: Request, project: str, version: str, category: str
) -> Response:
"""
Return the most recent entry for a specific cagory and a version of a project.
"""

View File

@ -11,6 +11,6 @@ import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'frogress.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "frogress.settings")
application = get_asgi_application()

View File

@ -25,7 +25,7 @@ SECRET_KEY = "django-insecure-4g&!7-muxr8a*6!pxk$agny_3z5w_bztudcbb7(*@ynco%$c6k
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
ALLOWED_HOSTS: list[str] = []
# Application definition

View File

@ -2,6 +2,6 @@ from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', include('frog_api.urls')),
path("", include("frog_api.urls")),
path("admin/", admin.site.urls),
]

View File

@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'frogress.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "frogress.settings")
application = get_wsgi_application()

View File

@ -6,7 +6,7 @@ import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'frogress.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "frogress.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
@ -18,5 +18,5 @@ def main():
execute_from_command_line(sys.argv)
if __name__ == '__main__':
if __name__ == "__main__":
main()

View File

@ -22,8 +22,12 @@ namespace_packages = True
disallow_untyped_defs = True
files =
frogress/**/*.py
frogress/**/*.py,
frog_api/**/*.py
plugins =
mypy_django_plugin.main,
mypy_drf_plugin.main
[mypy.plugins.django-stubs]
django_settings_module = frogress.settings