Skip to content

Commit

Permalink
[DI-2709] Adds CI worflow for the generated project
Browse files Browse the repository at this point in the history
- Adds `.guthub/workflows/ci.yml` with couple jobs to:
-- run pre-commit hooks on CI, inc. ruff linting & formatting;
-- run `api` tests;
- Update couple versions for pre-commit hooks
  • Loading branch information
bulya committed Oct 11, 2024
1 parent 87734e4 commit 55afefa
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 18 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ Run application:
```bash
make compose-up
```

We are using docker for running the app, so you don't have to keep your python env locally.
But we also use pre-commit hooks, and the `safety` hook requires `poetry` to be in your `PATH`.

> [!TIP]
> Ensure the poetry installed with the same python version as in `pyproject.toml`
53 changes: 53 additions & 0 deletions {{ cookiecutter.project_slug }}/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI
on: [push]

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


jobs:
linter:
runs-on: ubuntu-latest
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "{{ cookiecutter.python_version.lower() }}"

# We need `poetry` to run safety pre-commit hook
- name: Install Poetry
uses: snok/install-poetry@v1

- name: Run pre-commit
uses: pre-commit/[email protected]

# Tests & migrations checks
checks:
runs-on: ubuntu-latest
steps:

- name: Checkout Code Repository
uses: actions/checkout@v4

- name: Create .env file
run: |
cp ./api/.env.example ./api/.env
- name: Build the Stack
run: make compose-build

- name: Check missing DB migrations
run: make api-check-migrations

- name: Run DB Migrations
run: make api-migrate

- name: Run `api` Tests
run: make api-test

- name: Tear down the Stack
run: make compose-down
29 changes: 11 additions & 18 deletions {{ cookiecutter.project_slug }}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:
repos:
# General
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: check-added-large-files
args: ['--maxkb=10000']
Expand All @@ -19,29 +19,22 @@ repos:
- id: pretty-format-json
args: ['--autofix', '--indent 2', ]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.3.0
hooks:
- id: codespell
args: [ "--toml=api/pyproject.toml" ]
additional_dependencies:
- tomli

# API
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.265
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: ruff
args: ['--fix', '--exit-non-zero-on-fix']
args: [ '--fix', '--exit-non-zero-on-fix' ]
- id: ruff-format
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
rev: v1.3.1
rev: v1.3.3
hooks:
- id: python-safety-dependencies-check
entry: safety
args: [check]
files: ./api/requirements-build.txt
# TODO: Run this hook from docker container.
# - repo: local
# hooks:
# - id: migrations-check
# language: system
# name: Check for uncreated migrations.
# entry: sh -c "make api-check-migrations"
# files: models/*.*\.py$
# stages: [commit]
files: pyproject.toml
3 changes: 3 additions & 0 deletions {{ cookiecutter.project_slug }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ compose-down:

compose-build:
cd docker/ && docker compose build

api-migrate:
cd docker/ && docker compose run --rm api make migrate
3 changes: 3 additions & 0 deletions {{ cookiecutter.project_slug }}/api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ exclude_lines =[
]
show_missing = true

[tool.codespell]
skip = "*.lock"
ignore-words = "codespell-ignore-words.txt"

0 comments on commit 55afefa

Please sign in to comment.