-
Notifications
You must be signed in to change notification settings - Fork 16
/
Makefile
50 lines (39 loc) · 1.58 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
SOURCE_FILES?=./...
GOLANGCI_VERSION=v1.54.2
COVERAGE=coverage.out
export PATH := ./bin:$(PATH)
export GO111MODULE := on
.PHONY: setup
setup: ## Install dev tools
@echo "==> Installing dependencies..."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_VERSION)
.PHONY: link-git-hooks
link-git-hooks: ## Install git hooks
@echo "==> Installing all git hooks..."
find .git/hooks -type l -exec rm {} \;
find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \;
.PHONY: fmt
fmt: ## Format code
@echo "==> Formatting all files..."
find . -name '*.go' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done
.PHONY: test
test: ## Run tests
@echo "==> Running tests..."
go test -race -cover -count=1 -coverprofile ${COVERAGE} ${SOURCE_FILES}
.PHONY: lint
lint: ## Run linter
@echo "==> Linting all packages..."
golangci-lint run $(SOURCE_FILES)
.PHONY: check
check: test lint ## Run tests and linters
.PHONY: addlicense
addlicense:
find . -name '*.go' | while read -r file; do addlicense -c "MongoDB Inc" "$$file"; done
.PHONY: list
list: ## List all make targets
@${MAKE} -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
.PHONY: help
.DEFAULT_GOAL := help
help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'