1# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
2
3.PHONY: check fmt lint test test-race vet test-cover-html help
4.DEFAULT_GOAL := help
5
6check: test-race fmt vet lint ## Run tests and linters
7
8test: ## Run tests
9	go test ./...
10
11test-race: ## Run tests with race detector
12	go test -race ./...
13
14fmt: ## Run gofmt linter
15	@for d in `go list` ; do \
16		if [ "`gofmt -l -s $$GOPATH/src/$$d | tee /dev/stderr`" ]; then \
17			echo "^ improperly formatted go files" && echo && exit 1; \
18		fi \
19	done
20
21lint: ## Run golint linter
22	@for d in `go list` ; do \
23		if [ "`golint $$d | tee /dev/stderr`" ]; then \
24			echo "^ golint errors!" && echo && exit 1; \
25		fi \
26	done
27
28vet: ## Run go vet linter
29	@if [ "`go vet | tee /dev/stderr`" ]; then \
30		echo "^ go vet errors!" && echo && exit 1; \
31	fi
32
33test-cover-html: ## Generate test coverage report
34	go test -coverprofile=coverage.out -covermode=count
35	go tool cover -func=coverage.out
36
37help:
38	@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
39