GIT := git
CARGO := cargo
m ?= chore: update
define git_commit_if_needed
@if [ -n "$$($(GIT) status --porcelain)" ]; then \
$(GIT) add .; \
$(GIT) commit -m "$(m)"; \
else \
echo "Nothing to commit"; \
fi
endef
define git_push_if_needed
@if [ -n "$$($(GIT) status --porcelain)" ]; then \
$(GIT) add .; \
$(GIT) commit -m "$(m)"; \
$(GIT) push; \
else \
echo "Nothing to commit"; \
fi
endef
.DEFAULT_GOAL := help
.PHONY: help build build-full build-release check test lint fmt fmt-check doc clean \
dry-run publish git-commit git-push audit
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}'
build:
@echo "===> cargo build"
$(CARGO) build -p neocrates
build-full:
@echo "===> cargo build --features full"
$(CARGO) build -p neocrates --features full
build-release:
@echo "===> cargo build --release"
$(CARGO) build --release -p neocrates
check:
@echo "===> cargo check"
$(CARGO) check -p neocrates --features full
test:
@echo "===> cargo test"
$(CARGO) test -p neocrates
test-full:
@echo "===> cargo test --features full"
$(CARGO) test -p neocrates --features full
lint:
@echo "===> cargo clippy"
$(CARGO) clippy -p neocrates --features full -- -D warnings
fmt:
@echo "===> cargo fmt"
$(CARGO) fmt
fmt-check:
@echo "===> cargo fmt --check"
$(CARGO) fmt --check
doc:
@echo "===> cargo doc"
$(CARGO) doc -p neocrates --features full --no-deps --open
doc-check:
@echo "===> cargo doc (no open)"
$(CARGO) doc -p neocrates --features full --no-deps
audit:
@echo "===> cargo audit"
$(CARGO) audit
clean:
@echo "===> cargo clean"
$(CARGO) clean
dry-run:
@echo "===> dry-run publish"
$(call git_commit_if_needed)
$(CARGO) publish -p neocrates --dry-run --registry crates-io
publish:
@echo "===> publish neocrates"
$(call git_commit_if_needed)
$(CARGO) publish -p neocrates --registry crates-io
$(CARGO) clean
git-commit: ## Stage, commit (requires m="message")
$(call git_commit_if_needed)
git-run: ## Stage, commit, and push (requires m="message")
$(call git_push_if_needed)