Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quality checks and tests #6

Merged
merged 20 commits into from
Jun 25, 2024
24 changes: 24 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

- package-ecosystem: "pip"
directory: "backend/" # Location of package manifests
schedule:
interval: "weekly"
ignore:
- dependency-name: "django"
update-types: [ "version-update:semver-major", "version-update:semver-minor" ] # only allow auto update on django bug and security fixes

- package-ecosystem: "npm"
directory: "front-end/" # Location of package manifests
schedule:
interval: "weekly"
22 changes: 22 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
changelog:
categories:
- title: 🎉 Features
labels:
- '*'
exclude:
labels:
- dependencies
- Bug
- documentation

- title: 🛠 Bug fixes
labels:
- 'Bug'

- title: 📘 Documentation
labels:
- documentation

- title: ⤴ Dependencies
labels:
- dependencies
116 changes: 116 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Quality checks

on:
pull_request:
push:
branches:
- master
- main
- next

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DEBIAN_FRONTEND: noninteractive

jobs:
flake8:
name: Python Flake8 check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: ./backend/.python-version

- name: Install flake8
working-directory: ./backend
run: |
pip install flake8 -c dev-requirements.txt

- name: Flake8
working-directory: ./backend
run: |
flake8 project

isort:
name: Python iSort check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: ./backend/.python-version

- name: Install isort
working-directory: ./backend
run: |
pip install isort -c dev-requirements.txt

- name: iSort
working-directory: ./backend
run: |
isort -c project

black:
name: Python Black check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: ./backend/.python-version

- name: Install black
working-directory: ./backend
run: |
pip install black -c dev-requirements.txt

- name: black
working-directory: ./backend
run: |
black --check project

prettier:
name: JS Prettier check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ./front-end/.nvmrc
cache: 'npm'
cache-dependency-path: ./front-end/.nvmrc

- name: Install node dependencies
working-directory: ./front-end
run: |
npm ci --no-audit

- name: Prettier check
working-directory: ./front-end
run: |
npm run format:check

type:
name: JS Type check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ./front-end/.nvmrc
cache: 'npm'
cache-dependency-path: ./front-end/.nvmrc

- name: Install node dependencies
working-directory: ./front-end
run: |
npm ci --no-audit

- name: Type check
working-directory: ./front-end
run: |
npm run type:check
124 changes: 124 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Tests

on:
pull_request:
push:
branches:
- master
- main
- next

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DEBIAN_FRONTEND: noninteractive
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
CI: false

jobs:
python-unittests:
name: Python Unit tests
runs-on: ubuntu-latest
env:
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_HOST: 127.0.0.1

services:
postgres:
image: postgis/postgis:16-3.4
env:
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: ./backend/.python-version
cache: 'pip'
cache-dependency-path: |
./backend/requirements.txt
./backend/dev-requirements.txt

- name: Install system libraries
working-directory: ./backend
run: |
sudo apt-get -qq update
sudo apt-get -qq install -y libpq-dev gdal-bin gettext

- name: Install dependencies
working-directory: ./backend
run: |
pip install -r requirements.txt -r dev-requirements.txt

- name: Run django unit tests
working-directory: ./backend
run: |
coverage run --parallel-mode --concurrency=multiprocessing ./manage.py test --parallel -v 3
coverage combine
coverage xml -o coverage.xml

- uses: codecov/codecov-action@v4
with:
files: ./backend/coverage.xml
flags: python-unittests
token: ${{ secrets.CODECOV_TOKEN }}

js-build:
name: JS tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ./front-end/.nvmrc
cache: 'npm'
cache-dependency-path: ./front-end/.nvmrc

- name: Install node dependencies
working-directory: ./front-end
run: |
npm ci --no-audit

- name: npm build
working-directory: ./front-end
run: |
npm run build

docker-build:
name: Docker build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: .docker/Dockerfile
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: prod

1 change: 1 addition & 0 deletions front-end/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
3 changes: 3 additions & 0 deletions front-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "regard-d-altitude",
"version": "0.0.0",
"scripts": {
"type:check": "tsc --noEmit",
"format:write": "prettier --write \"**/*.{ts,tsx,mdx}\" --cache",
"format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache",
"ng": "ng",
"start": "ng serve",
"build": "ng build",
Expand Down