-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
77 lines (63 loc) · 2.27 KB
/
Copy pathMakefile
File metadata and controls
77 lines (63 loc) · 2.27 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
ifndef GOPATH
GOPATH := $(shell go env GOPATH)
endif
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)
.PHONY: all
all: help
# Format go code and error if any changes are made
.PHONY: format
format: $(GOPATH)/bin/goimports ## Format files using goimports
@echo "Runing gofumpt"
@gofumpt -l -w .
@echo "Running goimports"
@test -z $$(goimports -w ./..) || (echo "goimports would make a change. Please verify and commit the proposed changes"; exit 1)
.PHONY: lint
lint: $(GOPATH)/bin/golangci-lint ## Run golangci-lint
@golangci-lint run -v
.PHONY: test
test: ## Run unit tests with coverage
@go clean -testcache
@go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
.PHONY: coverage
coverage: test
@go tool cover -func=coverage.out
.PHONY: coverage-html
coverage-html: test
@go tool cover -html=coverage.out
##################################################
# tools managment rules
##################################################
$(GOPATH)/bin/golangci-lint:
@echo "🔘 Installing golangci-lint... (`date '+%H:%M:%S'`)"
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin
$(GOPATH)/bin/goimports:
@echo "🔘 Installing goimports ... (`date '+%H:%M:%S'`)"
@go install golang.org/x/tools/cmd/goimports@latest
$(GOPATH)/bin/gofumpt:
@echo "🔘 Installing gofumpt ... (`date '+%H:%M:%S'`)"
@go install mvdan.cc/gofumpt@latest
.PHONY: tools
tools: $(GOPATH)/bin/golangci-lint $(GOPATH)/bin/goimports $(GOPATH)/bin/gofumpt ## Install tools
.PHONY: update-tools
update-tools: delete-tools tools ## Update tools
.PHONY: delete-tools
delete-tools: ## Delete installed tools
@rm $(GOPATH)/bin/golangci-lint || true
@rm $(GOPATH)/bin/goimports || true
@rm $(GOPATH)/bin/gofumpt || true
## Help:
.PHONY: help
help: ## Show this help.
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)