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

Attempt to run trunk & check for FIXMEs on PR #96

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e9bd741
Attempt to run trunk & check for FIXMEs on PR
katybaulch Mar 7, 2024
932106a
Create initial Trunk config
katybaulch Mar 7, 2024
77bdc10
Run trunk on all files
katybaulch Mar 7, 2024
0de56fa
Add Trunk to code-quality check
katybaulch Mar 7, 2024
83c2565
Add blank line between module docstring and first import
katybaulch Mar 11, 2024
244f22a
Use isinstance instead of comparing types
katybaulch Mar 11, 2024
9273b48
Change ruff precommit repo to official
katybaulch Mar 11, 2024
f3dd2d0
Don't create virtual env in CI
katybaulch Mar 11, 2024
b7f193e
Don't trunk check all files
katybaulch Mar 11, 2024
cca6f36
Run isort
katybaulch Mar 11, 2024
e6c7b23
Use double instead of single quotes in yml
katybaulch Mar 11, 2024
047a4f0
Turn off markdownlint line length error for tables
katybaulch Mar 11, 2024
debcb49
Fix import ordering (isort) & double quote yml strings
katybaulch Mar 11, 2024
e500783
Disable isort as ruff is used
katybaulch Mar 11, 2024
370ebfb
Format with prettier
katybaulch Mar 11, 2024
3ca953f
Fix too few spaces before comment
katybaulch Mar 11, 2024
9136b5b
Fix line length error
katybaulch Mar 11, 2024
3a62d7e
Remove redundant quotes
katybaulch Mar 11, 2024
5e68d1f
Create virtual env
katybaulch Mar 11, 2024
043aa90
Revert "Create virtual env"
katybaulch Mar 11, 2024
cf9b64d
Export PYTHONPATH for trunk
katybaulch Mar 11, 2024
e279410
Export PYTHONPATH by adding to env
katybaulch Mar 11, 2024
a1e0071
Make PYTHONPATH current dir
katybaulch Mar 11, 2024
65106e6
Debug pwd
katybaulch Mar 11, 2024
418fef4
Set PYTHONPATH as pwd & install project root
katybaulch Mar 11, 2024
0264b20
Set PYTHONPATH as pwd
katybaulch Mar 11, 2024
c20302b
Commit trunk config for code quality
katybaulch Mar 11, 2024
3beb26f
List all files in pwd
katybaulch Mar 11, 2024
80ce81d
Don't run bandit on test files
katybaulch Mar 11, 2024
a1fd1e0
Remove isort
katybaulch Mar 11, 2024
e8933e4
Double quote to prevent globbing/word splitting
katybaulch Mar 11, 2024
c563af2
Double quote to prevent word splitting/globbing
katybaulch Mar 11, 2024
001d8f4
Pin poetry version and run pip with no cache to minimise size
katybaulch Mar 11, 2024
9f12378
Sort imports
katybaulch Mar 11, 2024
b619bd2
Rename project
katybaulch Mar 11, 2024
598a894
Enable trunk check and format as precommit
katybaulch Mar 11, 2024
872f59d
Moved trunk .gitignore to project .gitignore
katybaulch Mar 11, 2024
c528cd1
Added EOF new line
katybaulch Mar 11, 2024
ac50a8f
Configure isort to use black settings
katybaulch Mar 11, 2024
35b0ec4
Upgrade linters & enable isort & precommit-hooks
katybaulch Mar 11, 2024
bc3d3a5
Fix pyright version at 1.1.294
katybaulch Mar 11, 2024
d7669aa
Remove old precommit file
katybaulch Mar 11, 2024
2f8a990
Exit if we can't find root git project folder
katybaulch Mar 11, 2024
f9aaa95
Fix isort imports
katybaulch Mar 11, 2024
f97e8c2
Fix auto-fixable issue
katybaulch Mar 11, 2024
ed6b3d5
Run trunk in CI mode
katybaulch Mar 11, 2024
9fe3dd5
Downgrade black version
katybaulch Mar 11, 2024
fd34af0
Merge branch 'main' into PDCT-916/add-precommit-hooks-to-db-client-to…
katybaulch Mar 11, 2024
276db3b
Explicitly specify paths to include in final distribution
katybaulch Mar 11, 2024
997ef74
Remove blank line
katybaulch Mar 11, 2024
3fbf7a0
Upgrade pip and quote poetry version
katybaulch Mar 11, 2024
b6b6c4a
Make sure we are using latest version of docker-compose
katybaulch Mar 11, 2024
1811e90
Debug
katybaulch Mar 11, 2024
427f0b1
remove quotes
katybaulch Mar 11, 2024
41d84e4
Use --no-directory instead of --no-cache for poetry
katybaulch Mar 11, 2024
7b7d08f
Remove --no-directory
katybaulch Mar 11, 2024
2f79fd3
Revert "Remove --no-directory"
katybaulch Mar 11, 2024
98c9c16
Install project dependencies using no root
katybaulch Mar 11, 2024
717c477
Use reusable workflow for code quality checks
katybaulch Mar 11, 2024
7b471e6
Add job level permissions for code-quality job
katybaulch Mar 11, 2024
f437928
Update git_hooks makefile command to install and run trunk
katybaulch Mar 13, 2024
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
42 changes: 14 additions & 28 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,33 @@ name: CI/CD

on:
push:
tags: ['v*']
tags: ["v*"]
branches:
- main
pull_request:
branches:
- main

permissions: read-all

# https://github.com/marketplace/actions/docker-layer-caching
jobs:
code-quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install dependencies
run: |
python -m pip install "poetry==1.6.1" && poetry install && poetry run pre-commit install

- name: Run pre-commit checks
run: |
poetry run pre-commit run --all-files

- name: Check code contains no FIXME's
run: |
git grep -r --no-color ${case_sensitive} --line-number -e "FIXME" :^.github
if [[ $? -eq 0 ]]; then
# if we found any FIXME entries in checked in files, fail on main
exit 1
else
exit 0
fi
shell: bash {0}
permissions:
# For trunk to post annotations
checks: write
# For repo checkout
contents: read
uses: climatepolicyradar/reusable-workflows/.github/workflows/python-precommit-validator.yml@main

test:
runs-on: ubuntu-latest
steps:
- name: Install latest Docker Compose
uses: ndeloof/[email protected]
with:
legacy: false

- uses: actions/checkout@v4

- name: Configure test env variables
Expand Down
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,15 @@ load_blank.txt
load_default.txt

# PIP (because we want to use Poetry)
requirements.txt
requirements.txt

# Trunk miscellaneous
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
tmp
34 changes: 0 additions & 34 deletions .pre-commit-config.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions .trunk/configs/.hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Following source doesn't work in most setups
ignored:
- SC1090
- SC1091
2 changes: 2 additions & 0 deletions .trunk/configs/.isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile=black
11 changes: 11 additions & 0 deletions .trunk/configs/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Autoformatter friendly markdownlint config (all formatting rules disabled)
default: true
blank_lines: false
bullet: false
html: false
indentation: false
line_length: false
spaces: false
url: false
whitespace: false
tables: false
7 changes: 7 additions & 0 deletions .trunk/configs/.shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enable=all
source-path=SCRIPTDIR
disable=SC2154

# If you're having issues with shellcheck following source, disable the errors via:
# disable=SC1090
# disable=SC1091
10 changes: 10 additions & 0 deletions .trunk/configs/.yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
1 change: 1 addition & 0 deletions .trunk/configs/bandit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude_dirs: ["unit_tests", "integration_tests"]
4 changes: 4 additions & 0 deletions .trunk/configs/cspell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: "0.2"
# Suggestions can sometimes take longer on CI machines,
# leading to inconsistent results.
suggestionsTimeout: 5000 # ms
67 changes: 67 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
#
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.20.1

# Trunk provides extensibility via plugins.
# (https://docs.trunk.io/plugins)
plugins:
sources:
- id: trunk
ref: v1.4.4
uri: https://github.com/trunk-io/plugins

# Many linters and tools depend on runtimes - configure them here.
# (https://docs.trunk.io/runtimes)
runtimes:
enabled:
- [email protected]
- [email protected]
- [email protected]

# This is the section where you manage your linters.
# (https://docs.trunk.io/check/configuration)
lint:
definitions:
- name: bandit
direct_configs: [bandit.yaml]
commands:
- name: lint
run: bandit --exit-zero -c bandit.yaml --format json --output ${tmpfile} ${target}

enabled:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- git-diff-check
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]:
commands:
- end-of-file-fixer
- check-json
- detect-aws-credentials
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]

actions:
disabled:
- trunk-announce
- trunk-check-pre-push
enabled:
- trunk-check-pre-commit
- trunk-fmt-pre-commit
- trunk-upgrade-available
49 changes: 25 additions & 24 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,47 @@ The approach taken is influenced by:
- [The Twelve Factor App](https://12factor.net/)
- [SOLID principles](https://www.baeldung.com/solid-principles)
- [Domain Driven Design (DDD)](https://martinfowler.com/tags/domain%20driven%20design.html)
particularly [folder structure](https://dev.to/stevescruz/domain-driven-design-ddd-file-structure-4pja)
particularly [folder structure](https://dev.to/stevescruz/domain-driven-design-ddd-file-structure-4pja)

## Overview

There are three main layers to the application:

- **Routing Layer** - The responsibility here is to manage the network payloads
and any authentication middleware. All business logic is handed off to...
and any authentication middleware. All business logic is handed off to...
- **Service Layer** - Contains all validation and business logic for the
application. This in turn uses the...
application. This in turn uses the...
- **Repository Layer** - With the sole responsibility of managing how data is
stored and retrieved to/from the database.
**Note**, this split into responsibilities for separate entities, should the
need arise to create a transaction (for example creating two separate entities
atomically) - then this is the responsibility of the service layer to manage the
transaction.

Router
Service
┌───────┴───────┐
│ │
▼ ▼
Repository ──────► Client
(ext)
stored and retrieved to/from the database.
**Note**, this split into responsibilities for separate entities, should the
need arise to create a transaction (for example creating two separate entities
atomically) - then this is the responsibility of the service layer to manage the
transaction.

Router
Service
┌───────┴───────┐
│ │
▼ ▼

Repository ──────► Client
(ext)

## Testing Strategy

### Unit tests

- Routing Layer - this is tested my mocking out the required services by each
individual route. The tests should alter how the service behaves to test out the
routing layer responds.
individual route. The tests should alter how the service behaves to test out the
routing layer responds.

- Service Layer - the required repositories are mocked out so that the tests can
check the service returns/raises what is expected.
check the service returns/raises what is expected.

- Repository Layer - there are no unit tests.

Expand Down
21 changes: 11 additions & 10 deletions DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ At the moment we are using PyRight pegged at version 1.1.294.
## VS Code

- Although we use PyRight for linting (see [.pre-commit-config.yaml](./.pre-commit-config.yaml))
[PyRight recommends that you use PyLance when using VS Code](https://microsoft.github.io/pyright/#/installation?id=vs-code).
[PyRight recommends that you use PyLance when using VS Code](https://microsoft.github.io/pyright/#/installation?id=vs-code).

### Extensions

| Extension | Author | Description | Recommended/Optional |
|-----------|--------|-------------|-------------------------------|
| [Black Formatter](https://github.com/) | Microsoft | | Optional |
| [Code Spell Checker](https://github.com/) | Street Side Software | | Recommended |
| [Makefile Tools](https://github.com/) | Microsoft | | Recommended |
| [markdownlint](https://github.com/) | David Anson | | Recommended |
| [Markdown All in One](https://github.com/) | Yu Zhang | | Optional |
| [PyLance](https://github.com/) | Microsoft | | Recommended |
| [YAML](https://github.com/) | Red Hat | | Optional |
| Extension | Author | Recommended/Optional |
| ------------------------------------------ | -------------------- | -------------------- |
| [Black Formatter](https://github.com/) | Microsoft | Optional |
| [Code Spell Checker](https://github.com/) | Street Side Software | Recommended |
| [Makefile Tools](https://github.com/) | Microsoft | Recommended |
| [markdownlint](https://github.com/) | David Anson | Recommended |
| [Markdown All in One](https://github.com/) | Yu Zhang | Optional |
| [PyLance](https://github.com/) | Microsoft | Recommended |
| [YAML](https://github.com/) | Red Hat | Optional |
| [Ruff](https://github.com/) | Charlie R Marsh | Recommended |

### Recommended User Settings JSON

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ WORKDIR /usr/src
ENV PYTHONPATH=/usr/src

# Requirements
RUN pip install poetry
RUN pip install --no-cache-dir poetry==1.6.1
COPY poetry.lock pyproject.toml ./
RUN poetry config virtualenvs.create false && poetry install --no-cache
RUN poetry config virtualenvs.create false && poetry install --no-directory --no-root

# Now code
COPY ./app ./app
Expand Down
2 changes: 1 addition & 1 deletion GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Currently the deployment is manual, this required the following steps:

- Create a new tagged release [here](https://github.com/climatepolicyradar/navigator-admin-backend/releases)
- Wait for the `semver` Action to run in github - this creates and pushes the
image into ECR
image into ECR
- Log into the AWS console in the environment you wish to deploy.
- In AppRunner - find the running images and hit the `Deploy` button.

Expand Down
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ bootstrap:
pip3 install poetry
poetry install

git_hooks:
# Install & run git pre-commit hooks
poetry run pre-commit install --install-hooks
pre-commit run --all-files
install_trunk:
$(eval trunk_installed=$(shell trunk --version > /dev/null 2>&1 ; echo $$? ))
ifneq ($(trunk_installed),0)
$(eval OS_NAME=$(shell uname -s | tr A-Z a-z))
ifeq ($(OS_NAME),linux)
curl https://get.trunk.io -fsSL | bash
endif
ifeq ($(OS_NAME),darwin)
brew install trunk-io
endif
endif

git_hooks: install_trunk
trunk fmt
trunk check

build:
docker build -t navigator-admin-backend .
Expand Down
8 changes: 4 additions & 4 deletions app/api/api_v1/routers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .family import families_router
from .collection import collections_router
from .analytics import analytics_router
from .auth import auth_router
from .document import document_router
from .collection import collections_router
from .config import config_router
from .analytics import analytics_router
from .document import document_router
from .event import event_router
from .family import families_router
Loading
Loading