# Add any tasks that are not dependent on files to the .PHONY list.
.PHONY: dev pip_dev lint test test_unit test_integration clean docker_dev docker_down docker_unit_lint docker_test_integration docker_test_integration ci_unit_lint_clean ci_unit_lint

pip_dev:
	poetry install

dev:
	poetry run python dev.py

lint:
	poetry run ruff check artist/ tests/ dev.py application.py

test:
	poetry run pytest tests/ \
		--ignore tests/integration \
		--cov artist/ \
		--cov-report term-missing

test_unit:
	poetry run pytest -v \
		--cov artist tests \
		--cov-report xml \
		--junitxml=pyunit.xml

test_integration:
	poetry run pytest -v \
		--cov artist tests/integration \
		--cov-report xml \
		--junitxml=pyunit.xml

clean:
	rm -rf \
		env \
		.coverage \
		.pytest_cache \
		.cache \
		coverage.xml \
		pyunit.xml
	find . | grep -E '__pycache__|\.pyc|\.pyo$\' | xargs rm -rf

docker_dev:
	docker compose up --build dev

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

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

up_dev:  # Bring up dockerized dev service (supports hot-reload)
	docker compose up \
		--detach \
		--remove-orphans \
		dev

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 integration-test \
		--abort-on-container-exit \
		--remove-orphans \
		integration-test

ci_test_integration: docker_test_integration

up_deploy:
	docker compose build \
		--no-cache \
		deploy
	docker compose up \
		--detach \
		--remove-orphans \
		deploy

down_deploy:
	docker compose down deploy
