# Auto-detect docker or podman (prefer docker, fall back to podman)

VERSION     = $(shell grep '^version' Cargo.toml | sed 's/.*= "\(.*\)"/\1/')

.PHONY: build test check-uncommitted check-tag tag \
        publish-dry-run publish version

# ── Development ───────────────────────────────────────────────────────────────

build:
	cargo test
	cargo build --release

test:
	cargo test

# ── Release ───────────────────────────────────────────────────────────────────

version:
	@echo $(VERSION)

check-uncommitted:
	@if [ -n "$$(git status -s)" ]; then \
		echo "there are uncommitted changes ... cancel"; \
		exit 1; \
	else \
		echo "nothing to commit :) ..."; \
	fi

check-tag:
	@if git tag -l | grep -qx "$(VERSION)"; then \
		echo "the required version \"$(VERSION)\" is already tagged ... cancel"; \
		exit 1; \
	else \
		echo "tag available :) ..."; \
	fi

tag:
	git tag $(VERSION)

publish-cargo-dry-run:
	cargo publish --dry-run

publish-cargo:
	cargo publish


publish-dry-run: check-uncommitted check-tag test publish-cargo-dry-run
	@echo "dry-run ok — would push version $(VERSION)"

publish: check-uncommitted check-tag test tag publish-cargo
