# Developer + CI entrypoints.
#
# These targets are the single source of truth for the checks. The Gitea
# Actions workflow (.gitea/workflows/ci.yaml) invokes the SAME targets, so
# `make ci` locally runs exactly what the pipeline runs — no drift. Until a
# self-hosted runner is registered, `make ci` is the gate (see docs/runbooks/ci.md).

SLN        := services/bff/Bff.slnx
COMPOSE    := infra/docker-compose.yml
HEALTH_URL := http://localhost:8080/health

# On a rootless Podman dev box, point Docker CLI/Compose at the Podman socket —
# but only if that socket exists and DOCKER_HOST isn't already set, so real
# Docker hosts and CI runners are left untouched.
PODMAN_SOCK := /run/user/$(shell id -u)/podman/podman.sock
ifeq ($(wildcard $(PODMAN_SOCK)),$(PODMAN_SOCK))
ifeq ($(origin DOCKER_HOST),undefined)
export DOCKER_HOST := unix://$(PODMAN_SOCK)
endif
endif

.PHONY: ci lint build unit smoke down changelog help

## ci: run the full pipeline — lint, build, unit, smoke (mirrors Gitea Actions)
ci: lint build unit smoke

## lint: verify formatting (no changes)
lint:
	dotnet format $(SLN) --verify-no-changes

## build: release build
build:
	dotnet build $(SLN) -c Release

## unit: run unit tests
unit:
	dotnet test $(SLN) -c Release

## smoke: compose up (wait for healthy), curl /health, then tear down
smoke:
	docker compose -f $(COMPOSE) up -d --build --wait
	bash -c 'curl -fsS $(HEALTH_URL); rc=$$?; docker compose -f $(COMPOSE) down --volumes; exit $$rc'

## down: stop and remove the local stack
down:
	docker compose -f $(COMPOSE) down --volumes

## changelog: regenerate CHANGELOG.md from Conventional Commits (git-cliff)
changelog:
	git-cliff --output CHANGELOG.md

## help: list available targets
help:
	@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/^## //'
