UV ?= uv
PACKAGE ?= remote-cluster-controller
DIST_FILES ?= dist/*
TESTPYPI_UPLOAD_URL ?= https://test.pypi.org/legacy/
TESTPYPI_CHECK_URL ?= https://test.pypi.org/simple/$(PACKAGE)/
PYPI_API_TOKEN ?=
PUBLISH_ENV = $(if $(PYPI_API_TOKEN),UV_PUBLISH_TOKEN="$(PYPI_API_TOKEN)")

.PHONY: help sync test lint format check clean build publish-dry-run publish-test publish

help:
	@printf '%s\n' 'Release targets:'
	@printf '  %-18s %s\n' 'make check' 'Run tests, lint, and format checks'
	@printf '  %-18s %s\n' 'make build' 'Run checks and build wheel + sdist into dist/'
	@printf '  %-18s %s\n' 'make publish-dry-run' 'Build and validate publish command without upload'
	@printf '  %-18s %s\n' 'make publish-test' 'Build and upload to TestPyPI'
	@printf '  %-18s %s\n' 'make publish' 'Build and upload to PyPI'
	@printf '%s\n' ''
	@printf '%s\n' 'Auth: set PYPI_API_TOKEN or UV_PUBLISH_TOKEN, UV_PUBLISH_USERNAME/PASSWORD, or use trusted publishing.'

sync:
	$(UV) sync

test:
	$(UV) run pytest -m "not integration"

lint:
	$(UV) run ruff check src tests

format:
	$(UV) run ruff format --check src tests

check: test lint format

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

build: clean check
	$(UV) build

publish-dry-run: build
	$(PUBLISH_ENV) $(UV) publish --dry-run $(DIST_FILES)

publish-test: build
	$(PUBLISH_ENV) $(UV) publish --publish-url $(TESTPYPI_UPLOAD_URL) --check-url $(TESTPYPI_CHECK_URL) $(DIST_FILES)

publish: build
	$(PUBLISH_ENV) $(UV) publish $(DIST_FILES)
