# Add any tasks that are not dependent on files to the .PHONY list.
.PHONY: pip_dev dev lint test test_unit test_integration clean docker_unit_lint up_dev down_dev up_deploy down_deploy ci_unit_lint_clean ci_unit_lint

# Used by `docker compose` dev targets that use multiple yml files.
COMPOSE_DEV_FILES = -f docker-compose.yml -f docker-compose-dev.yml

env pip_dev:
	python3.13 -m venv env
	env/bin/pip3.13 install --upgrade pip
	env/bin/pip3.13 install -r requirements-dev.txt

dev: env
	env/bin/python3.13 dev.py

test: env
	env/bin/py.test --ignore=tests/integration tests

test_unit: env
	env/bin/py.test --ignore=tests/integration tests \
		--cov-report xml \
		--junitxml=pyunit.xml

test_integration:
	env/bin/py.test tests/integration

clean:
	rm -rf env

up_dev:
	docker compose $(COMPOSE_DEV_FILES) up \
		--detach \
		--remove-orphans \
		ows-contracts-dev

down_dev:
	docker compose $(COMPOSE_DEV_FILES) down ows-contracts-dev

up_deploy:
	docker compose build \
		--no-cache \
		ows-contracts-deploy
	docker compose $(COMPOSE_DEV_FILES) up \
		--detach \
		--remove-orphans \
		ows-contracts-deploy

down_deploy:
	docker compose $(COMPOSE_DEV_FILES) down ows-contracts-deploy

docker_unit_lint:
	docker compose up \
		--build \
		--exit-code-from unit-lint \
		--abort-on-container-exit \
		--remove-orphans \
		unit-lint

down_unit_lint:
	docker compose down unit-lint --remove-orphans

ci_unit_lint: ci_unit_lint_clean
	mkdir -p build
	chmod a+w build
	make docker_unit_lint

ci_unit_lint_clean: down_unit_lint
	rm -rf build

docker_test_integration:
	docker compose up \
		--build \
		--exit-code-from test-integration \
		--abort-on-container-exit \
		--remove-orphans \
		test-integration

ci_test_integration: docker_test_integration

down_test_integration:
	docker compose down test-integration --remove-orphans