# obi-kit: obi extension of crate-kit. It includes crate-kit and delegates to it: the extension and the cluster
# (the parent folder) are set here, crate-kit knows neither obi nor its registry.
# Crates declare KIT_SRC ?= ../obi-kit in their Makefile (make adopt).
CRATE_KIT ?= $(abspath ../crate-kit)
export CRATE_KIT
export KIT_OVERLAY := $(CURDIR)/overlay
export CLUSTER_DIR := $(abspath ..)

# Registry, forge, token: read from org.mk (passed on to release-all).
-include overlay/kit/org.mk
export REGISTRY REGISTRY_INDEX

# Kit release: the same as crate-kit's (jjrelease, jjpush, bump-version, dist).
KIT_NAME = obi-kit
VERSION_FILE = overlay/kit/VERSION
RELEASE_PROJECT_DESC = obi-kit (obi extension of crate-kit)
DIST_DIR = overlay
include $(CRATE_KIT)/tools/kit-release.mk

.DEFAULT_GOAL := help
.PHONY: help test ci update-all check-all needs-commit-all release-plan release-run release-dry-run claude-install adopt

help:
	@echo "make test              kit tests"
	@echo "make ci                checks before release (test)"
	@echo "make jjrelease         kit release: version, notes, push, tag"
	@echo "make update-all        updates the kit of all the crates of the cluster (FORCE=1: also stale release workflows)"
	@echo "make check-all         lists the crates whose kit differs (read-only)"
	@echo "make needs-commit-all  lists the crates with changes outside the kit"
	@echo "make release-plan      release order (release-run, release-dry-run: execution)"
	@echo "make claude-install    installs Claude hooks and agents in the cluster (.claude)"
	@echo "make adopt CRATE=../xxx [KIND=kind]   adopts the kit in a crate"

test:
	@set -e; for t in tests/*.sh; do echo "== $$t"; bash $$t; done

ci: test

update-all check-all needs-commit-all release-plan release-run release-dry-run:
	@$(MAKE) --no-print-directory -C "$(CRATE_KIT)" $@

claude-install:
	@bash "$(CRATE_KIT)/claude/install.sh"

adopt:
	@test -n "$(CRATE)" || { echo "usage: make adopt CRATE=../xxx [KIND=kind]"; exit 2; }
	@"$(CRATE_KIT)/adopt.sh" --kit-src "$(CURDIR)" $(if $(KIND),--kind $(KIND)) "$(abspath $(CRATE))"
