SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c

.PHONY: clean sync format lint bump_version
UV_CREDS := UV_INDEX_JFROG_USERNAME="$${REPO21_USER}" UV_INDEX_JFROG_PASSWORD="$${REPO21_PASSWORD}"

clean:
	rm -rf .mypy_cache .pytest_cache tests/frogml/.pytest_cache .coverage coverage-reports dist

format:
	uv run black tests frogml/core frogml/storage frogml/sdk frogml/feature_store

sync:
	@if [ -z "$${REPO21_USER}" ] || [ -z "$${REPO21_PASSWORD}" ]; then \
		echo "REPO21_USER and REPO21_PASSWORD environment variables must be set"; \
		exit 1; \
	fi
	$(UV_CREDS) uv sync --all-groups --all-extras
	uv run ./scripts/gen-proto.sh

precommit:
	uv run pre-commit run --files frogml/core/** frogml/storage/** frogml/feature_store frogml/sdk

lint:
	uv run black --check tests frogml/core frogml/storage frogml/sdk frogml/feature_store --diff
	uv run flake8 tests frogml/core frogml/storage frogml/sdk frogml/feature_store
	uv run bandit -r frogml/core frogml/storage frogml/sdk frogml/feature_store -c pyproject.toml

test:
	PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python uv run coverage run -m pytest --disable-warnings tests --durations=0

unit-test:
	PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python uv run pytest --disable-warnings tests -m "not integration" --durations=0

coverage-report:
	uv run coverage xml -i

bump-version-dev:
	uv run bump2version --allow-dirty build VERSION
	$(UV_CREDS) uv lock

bump-version-prod:
	uv run bump2version --allow-dirty release VERSION
	$(UV_CREDS) uv lock

patch-version:
	uv run bump2version --allow-dirty patch VERSION
	$(UV_CREDS) uv lock

build:
	@test -d frogml/_proto || (echo "Error: frogml/_proto is missing. Run 'make sync' first to generate proto files." && exit 1)
	$(UV_CREDS) uv build --clear

prod-release: clean build
	UV_PUBLISH_TOKEN=$(PYPI_TOKEN) uv publish --publish-url https://upload.pypi.org/legacy/

dev-release:
	echo "No need to release dev version"
