.PHONY: help clean test build check bump-version bump-major bump-minor bump-patch publish publish-patch publish-minor publish-major publish-test

PYTHON ?= uv run python

help:
	@$(PYTHON) -c "print('Targets:'); print('  make test          - run the test suite'); print('  make build         - build sdist and wheel'); print('  make check         - run twine check on built artifacts'); print('  make bump-version  - bump patch version in pyproject.toml and soigia/__init__.py'); print('  make bump-patch    - bump patch version'); print('  make bump-minor    - bump minor version'); print('  make bump-major    - bump major version'); print('  make publish       - one command: clean, test, bump patch, build, upload'); print('  make publish-patch - alias of make publish'); print('  make publish-minor - one command: clean, test, bump minor, build, upload'); print('  make publish-major - one command: clean, test, bump major, build, upload'); print('  make publish-test  - build/upload to TestPyPI with rollback on failure'); print('  make clean         - remove build artifacts')"

clean:
	@$(PYTHON) -c "import shutil; from pathlib import Path; [shutil.rmtree(p, ignore_errors=True) for p in [Path('build'), Path('dist'), Path('soigia.egg-info')]]"

test:
	@$(PYTHON) -m pytest tests

build:
	@uv build --out-dir dist

check: build
	@uv run twine check dist/*

bump-version:
	@$(PYTHON) scripts/release.py --bump-only

bump-patch:
	@$(PYTHON) scripts/release.py --bump-only --part patch

bump-minor:
	@$(PYTHON) scripts/release.py --bump-only --part minor

bump-major:
	@$(PYTHON) scripts/release.py --bump-only --part major

publish: clean test
	@$(PYTHON) scripts/release.py

publish-patch: clean test
	@$(PYTHON) scripts/release.py --part patch

publish-minor: clean test
	@$(PYTHON) scripts/release.py --part minor

publish-major: clean test
	@$(PYTHON) scripts/release.py --part major

publish-test: clean test
	@$(PYTHON) scripts/release.py --repository testpypi --prompt-label TestPyPI
