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

clean:
	rm -rf venv

env:
	python3.13 -m venv venv

pip_dev:
	venv/bin/pip install --upgrade pip
	venv/bin/pip install -r requirements.txt
	venv/bin/pip install -r requirements-dev.txt

dev:
	venv/bin/python dev.py

lint:
	venv/bin/python -m flake8 timed_release/ tests/ application.py dev.py

test_unit:
	venv/bin/pytest \
		--cov timed_release tests/unit/ \
		--cov-report xml \
		--junitxml=pyunit.xml \
		--ignore tests/integration

test_integration:
	venv/bin/py.test tests/integration --junitxml=pyunit.xml

unit_lint: clean env pip_dev test_unit lint

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

down_dev:
	docker compose down timed-release-dev

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

down_deploy:
	docker compose down timed-release-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 integration \
		--abort-on-container-exit \
		--remove-orphans \
		integration
