squall-mesh 0.1.0

agentic software
# ───────────────────────────────────────────────────
# Makefile for building with nix & pushing to GHCR
# ───────────────────────────────────────────────────

FLAKE_URI      	?= .
NIX_ATTR       	?= dockerImage
OUT_LINK       	?= result

# ─ Registry / image coordinates ────────────────────
REGISTRY       	?= ghcr.io
ORG            	?= pleme-io
REPO           	?= squall-mesh
TAG            	?= $(shell date +%s)-$(shell git rev-parse --short HEAD)
IMAGE          	:= $(REGISTRY)/$(ORG)/$(REPO):$(TAG)

GITHUB_USER    	?= drzln
CRATE_DIR     	?= .
CRATE_NAME    	?= squall-mesh

.PHONY: all build load tag login push clean check-env publish-crate check-cargo-env

.PHONY: all build load tag login push clean

all: build load tag login push

build:
	@echo "⏳  nix build $(FLAKE_URI)#$(NIX_ATTR)$(OUT_LINK)"
	nix build "$(FLAKE_URI)#$(NIX_ATTR)" --out-link "$(OUT_LINK)"

load: build
	@echo "⏳  docker load < $(OUT_LINK)"
	docker load < "$(OUT_LINK)"

tag: load
	@echo "🏷  tagging image as $(IMAGE)"
	docker tag godin:latest "$(IMAGE)"

login:
ifndef GITHUB_PAT
	$(error GITHUB_PAT is undefined – export your GitHub PAT with write:packages scope)
endif
	@echo "🔐  Logging in to $(REGISTRY)"
	@echo "$$GITHUB_PAT" | \
	  docker login --username "$(GITHUB_USER)" --password-stdin "$(REGISTRY)"

push: tag login
	@echo "🚀  Pushing $(IMAGE)"
	docker push "$(IMAGE)"

clean:
	@echo "🧹  Removing $(OUT_LINK)"
	rm -rf "$(OUT_LINK)"
publish-crate: check-cargo-env
	@echo "📦  Publishing crate $(CRATE_NAME) to crates.io"
	cd "$(CRATE_DIR)" && \
	cargo publish --locked --token "$$CARGO_REGISTRY_TOKEN"

check-cargo-env:
	@[ -n "$$CARGO_REGISTRY_TOKEN" ] || (echo "CARGO_REGISTRY_TOKEN missing. Generate with 'cargo login' and export it." && exit 3)
	@[ -f "$(CRATE_DIR)/Cargo.toml" ] || (echo "Cargo.toml not found in $(CRATE_DIR)" && exit 4)
	@grep -q '^name *= *"$(CRATE_NAME)"' "$(CRATE_DIR)/Cargo.toml" || (echo "Cargo.toml does not match CRATE_NAME ($(CRATE_NAME))" && exit 5)

release: all publish-crate