.PHONY: build-app test vet format css infra-init infra-plan infra-validate generate-inventory ansible-syntax deploy-ansible validate

build-app:
	$(MAKE) -C app build

test:
	cd app && go test ./...

vet:
	cd app && go vet ./...

format:
	cd app && gofmt -w $$(find . -name '*.go' -not -path './bin/*')
	tofu -chdir=infra fmt -recursive

css:
	$(MAKE) -C app css

infra-init:
	tofu -chdir=infra init -backend=false

infra-plan:
	tofu -chdir=infra plan -var-file=environments/prod/prod.tfvars -var-file=environments/staging/staging.tfvars

infra-validate: infra-init
	tofu -chdir=infra validate

generate-inventory:
	tofu -chdir=infra output -raw ansible_inventory > ansible/inventory/hosts.yml

ansible-syntax:
	cd ansible && ansible-playbook -i inventory/hosts.example.yml playbooks/setup-node.yml --syntax-check
	cd ansible && ansible-playbook -i inventory/hosts.example.yml playbooks/deploy-app.yml --syntax-check

deploy-ansible: generate-inventory
	cd ansible && ansible-playbook -i inventory/hosts.yml playbooks/setup-node.yml
	cd ansible && ansible-playbook -i inventory/hosts.yml playbooks/deploy-app.yml

validate: test vet infra-validate ansible-syntax
