.PHONY: ci tag deploy clean

-include .env
export

ci:
	pip install -e ".[dev]"
	ruff check .
	pytest -q

tag:
ifndef VERSION
	$(error VERSION is not set. Usage: make tag VERSION=1.2.3)
endif
	@if ! git diff --quiet || ! git diff --cached --quiet; then \
		echo "Error: working tree is not clean. Commit or stash changes first."; \
		exit 1; \
	fi
	git tag v$(VERSION)
	git push origin v$(VERSION)

deploy:
ifndef VERSION
	$(error VERSION is not set. Usage: make deploy VERSION=1.2.3)
endif
ifndef PYPI_TOKEN
	$(error PYPI_TOKEN is not set. Add it to .env or pass it directly.)
endif
	$(MAKE) clean
	python -m build
	twine upload dist/* --username __token__ --password $(PYPI_TOKEN)

clean:
	rm -rf dist/ build/ *.egg-info
