Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: uv sync --locked --group dev

- name: Check code
run: uv run make check
run: uv run make check-ci

- name: Test with Docker
env:
Expand Down
29 changes: 28 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ MAKEFLAGS += --no-print-directory
# User-configurable variables (edit this)
# INFRA_SERVICES: long-running infra (db, broker, cache, ...)
# INFRA_INIT_SERVICES: one-shot services that prepare INFRA_SERVICES
# MIGRATION_DB_SERVICE: transactional db service used by alembic (empty = no migrations)
# STAIRWAY_TEST: path to stairway test (empty = skip stairway step)
# -----------------------------
PROJECT_NAME ?= $(notdir $(abspath .))
INFRA_SERVICES ?= db_pg
INFRA_INIT_SERVICES ?=
MIGRATION_DB_SERVICE ?= db_pg
STAIRWAY_TEST ?= tests/integration/with_infra/test_stairway.py

# -----------------------------
# Internal vars / aliases
Expand All @@ -24,6 +28,7 @@ DOCKER_ENV := scripts/makefile/docker_env.sh
LOCAL_ENV := scripts/makefile/local_env.sh
DOCKER_PRUNE := scripts/makefile/docker_prune.sh
PYCACHE_DEL := scripts/makefile/pycache_del.sh
MIGRATION := scripts/makefile/migration.sh
DISHKA_PLOT_DATA := scripts/dishka/plot_dependencies_data.py

# Test stack is isolated by project name
Expand Down Expand Up @@ -60,7 +65,7 @@ pip-audit:
$(PIP_AUDIT)

# Code quality
.PHONY: slotscheck lint test check
.PHONY: slotscheck lint test check check-ci
slotscheck:
$(SLOTSCHECK) src

Expand All @@ -82,6 +87,20 @@ test:
check: lint test
coverage html

check-ci:
ruff check
ruff format --check
tombi format --check
tombi lint
deptry
$(MAKE) slotscheck
lint-imports
mypy
pytest -v \
$(PYTEST_PATHS_LIGHT) \
$(PYTEST_ARGS_COV)
coverage html

# Docker compose
.PHONY: docker-env local-env upd up upd-local up-local down stop-all
docker-env:
Expand All @@ -108,6 +127,14 @@ down:
stop-all:
docker ps -q | xargs -r docker stop

# Migrations
.PHONY: migration
migration: local-env
PROJECT_NAME=$(PROJECT_NAME) \
MIGRATION_DB_SERVICE=$(MIGRATION_DB_SERVICE) \
STAIRWAY_TEST=$(STAIRWAY_TEST) \
$(MIGRATION) "$(msg)"

# Tests (with infra)
.PHONY: test-docker
test-docker: docker-env
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Test (all paths)
make test-docker
```

Generate a migration
```shell
make migration msg=<msg>
```

See [Makefile](Makefile) for more commands

Thanks for your patience and support
Expand Down
22 changes: 22 additions & 0 deletions scripts/makefile/migration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# The script is called from Makefile
set -eu -o pipefail

if [ "$#" -ne 1 ] || [ -z "$1" ]; then
echo 'ERROR: msg is required, e.g. make migration msg="add users"' >&2
exit 2
fi
slug="$1"

: "${PROJECT_NAME:?must be set in Makefile}"
: "${MIGRATION_DB_SERVICE:?must be set in Makefile (transactional db service for alembic)}"

trap 'docker compose -p "$PROJECT_NAME" stop "$MIGRATION_DB_SERVICE" >/dev/null' EXIT

docker compose -p "$PROJECT_NAME" up -d --build --wait --wait-timeout 180 "$MIGRATION_DB_SERVICE"
alembic upgrade head
alembic revision --autogenerate -m "$slug"

if [ -n "${STAIRWAY_TEST:-}" ]; then
ALLOW_DESTRUCTIVE_TEST_CLEANUP=1 pytest -s -vv "$STAIRWAY_TEST"
fi