SHELL := /bin/bash
CURRENT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
GIT_COMMIT := $(shell $(CURRENT_DIR)/scripts/ci/git_commit)

IMAGE_NAME := liverecs/octarine
DOCKER_REGISTRY_URL := docker.pkgs.xarth.tv/$(IMAGE_NAME)
TAGGED_IMAGE_URL=$(DOCKER_REGISTRY_URL):$(GIT_COMMIT)

.PHONY: deploy
deploy:
	$(CURRENT_DIR)/scripts/ci/deploy $(TAGGED_IMAGE_URL)

.PHONY: build
build:
	$(CURRENT_DIR)/scripts/ci/build $(TAGGED_IMAGE_URL)

.PHONY: push
push:
	docker push $(TAGGED_IMAGE_URL)

.PHONY: tag
tag:
	$(CURRENT_DIR)/scripts/ci/git_tag

.PHONY: lint-check
lint-check: 
	docker build -t $(TAGGED_IMAGE_URL) .
	docker run -t $(TAGGED_IMAGE_URL) python -m black --check --exclude r"*feature_schema_pb2.py" .
	docker run -t $(TAGGED_IMAGE_URL) python -m isort --profile black --check-only --skip ./octarine/clients/TwitchFeatureIngestionClient/feature_schema_pb2.py .
	docker run -t $(TAGGED_IMAGE_URL) find . -regex '^.*\/octarine_[^\/\.]*' -exec mypy {} \;

.PHONY: lint
lint:
	python -m black . 
	python -m isort --profile black .
	find $(CURRENT_DIR) -regex '^.*\/octarine_[^\/\.]*' -exec mypy {} \;

.PHONY: test
test:
	docker run -t ${TAGGED_IMAGE_URL} python -m unittest discover -s tests

.PHONY: clean
clean:
	-find . -regex '.*egg-info' -exec rm -rf {} \; > /dev/null
	-find . -regex '.*eggs' -exec rm -rf {} \; > /dev/null
	-find . -regex '.*octarine.*__pycache__' -exec rm -rf {} \; > /dev/null
	-rm -rf dist/ build/


SRC_DIR := $(CURRENT_DIR)/octarine/clients/TwitchFeatureIngestionClient

.PHONY: generate
generate:
	protoc -I $(CURRENT_DIR)/submodule/TwitchFeatureSchema --python_out $(SRC_DIR) $(wildcard $(CURRENT_DIR)/submodule/TwitchFeatureSchema/*.proto)
