# Add any tasks that are not dependant on files in the .PHONY list
.PHONY: dev lint pip_dev test test_unit test_integration test_load ci_unit_lint ci_unit_lint_clean ci_integration ci_integration_clean

dev:
	pipenv run python dev.py

lint:
	pipenv run flake8 analytics/ tests/

# Install all dependencies (including dev) as pinned in Pipfile.lock
pip_dev:
	pipenv --rm install --dev --ignore-pipfile

# Update Pipfile.lock and install all dependencies (including dev)
install_with_dev:
	pipenv --rm install --dev

test:
	pipenv run py.test tests/unit/

test_unit:
	pipenv run py.test \
		--ignore=tests/integration/load \
		--ignore=tests/integration/test_api.py \
		--ignore=tests/integration/models/test_geographics.py \
		--ignore=tests/integration/auth_rules \
		--cov analytics tests \
		--cov-report xml \
		--junitxml=../build/pyunit.xml

test_load:
	pipenv run bzt tests/integration/load/test.yml

ci_unit_lint: ci_unit_lint_clean  ## Run lint and unit tests in CI/CD
	mkdir -p build
	chmod a+w build
	docker compose up --exit-code-from unit-lint --abort-on-container-exit --build unit-lint

ci_unit_lint_clean:  ## Teardown lint and unit tests in CI/CD
	docker compose down unit-lint --remove-orphans
	rm -rf build

ci_integration:
	mkdir -p build
	chmod a+w build
	docker compose up --exit-code-from tests-integration --abort-on-container-exit --build tests-integration

ci_integration_clean:
	docker compose down tests-integration --remove-orphans
