# Add any tasks that are not dependent on files to the .PHONY list.
.PHONY: dev test lint pip_dev test_unit test_integration clean

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

env:
	poetry install --only main

pip_dev:
	poetry install

dev:
	poetry run python dev.py

lint:
	poetry run ruff check promo_player/ tests/ dev.py

test:
	poetry run pytest tests/unit/ tests/functional/ \
		--cov promo_player \
		--cov-report term-missing

test_unit:
	poetry run pytest -v \
		tests/unit/ tests/functional/ \
		--cov promo_player tests \
		--cov-report xml \
		--junitxml=pyunit.xml

test_integration:
	poetry run pytest -v tests/integration

unit_lint: clean env pip_dev test_unit lint

up_dev:
	docker compose up \
		--detach \
		--remove-orphans \
		dev

down_dev:
	docker compose down dev

up_deploy:
	docker compose up \
		--detach \
		--remove-orphans \
		deploy

down_deploy:
	docker compose down deploy

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

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