.PHONY: install lint format typecheck test-unit test-integration test coverage build check-build publish clean ci

VENV := .venv
PYTHON := $(VENV)/bin/python
PIP := $(VENV)/bin/pip

# not in the PHONY list so the target does nothing if the folder already exists
$(VENV):
	python3 -m venv $(VENV)

install: $(VENV)
	$(PIP) install --upgrade pip
	$(PIP) install -e ".[dev]"

lint: install
	$(VENV)/bin/ruff check src tests

format: install
	$(VENV)/bin/ruff format src tests

typecheck: install
	$(VENV)/bin/mypy src

test-unit: install
	$(VENV)/bin/pytest tests/unit

test-integration: install
	$(VENV)/bin/pytest tests/integration

test: test-unit test-integration

coverage: install
	$(VENV)/bin/pytest --cov=isynth_provisioning --cov-report=term-missing --cov-report=xml --cov-fail-under=60

build: install
	$(PYTHON) -m build

check-build: build
	$(VENV)/bin/twine check dist/*

# Uploads to real PyPI by default. twine reads these standard env vars if set,
# so no Makefile changes are needed to target somewhere else, e.g. a GitLab
# Package Registry:
#   TWINE_REPOSITORY_URL=https://gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/pypi
#   TWINE_USERNAME=<gitlab username, or gitlab-ci-token inside GitLab CI>
#   TWINE_PASSWORD=<personal/project/deploy access token, or $CI_JOB_TOKEN inside GitLab CI>
publish: install
	$(VENV)/bin/twine upload dist/*

clean:
	# rm -rf $(VENV) dist build *.egg-info .pytest_cache .mypy_cache .ruff_cache htmlcov .coverage coverage.xml src/isynth_provisioning/_version.py
	rm -rf dist build *.egg-info .pytest_cache .mypy_cache .ruff_cache htmlcov .coverage coverage.xml src/isynth_provisioning/_version.py

ci: lint typecheck test coverage build check-build
