VERSION = $(shell cat Cargo.toml | grep "^version" | sed -e 's-v--g' -e 's-.*= --g')

.PHONY: test build

docker-build:
	docker build -f Dockerfile.release -t okieoth/rvault:$(VERSION) .

docker-push:
	docker push okieoth/rvault:$(VERSION)

build:
	cargo test
	cargo build

test:
	cargo test

run-bin:
	cargo run

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

publish-cargo:
	cargo publish

version:
	cargo run -- -V

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-dry-run: check-uncommitted check-tag \
	test docker-build publish-cargo-dry-run

publish: check-uncommitted check-tag \
	test docker-build publish-cargo docker-push
