-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
100 lines (79 loc) · 2.68 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
GOLANGCI_LINT_VERSION=v1.37.1
ifndef GOPATH
GOPATH := $(shell go env GOPATH)
endif
# Default target will fetch deps, build and run tests.
all: tidy generate build check test
generate:
oapi-codegen -generate types -package=validator client-v1.yaml > types.gen.go
tidy:
go mod tidy
build:
go build ./...
check: format lint sec
clean:
go clean
# Format go code and error if any changes are made
PHONY+= format
format:
@echo "Checking that go fmt does not make any changes..."
@test -z $$(go fmt $(go list ./...)) || (echo "go fmt would make a change. Please verify and commit the proposed changes"; exit 1)
@echo "Checking go fmt complete"
@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 $(GOPATH)/bin/golint
@echo "Linting $(1)"
@golint -set_exit_status ./...
@go vet ./...
@golangci-lint run \
-E asciicheck \
-E bodyclose \
-E exhaustive \
-E exportloopref \
-E gofmt \
-E goimports \
-E gosec \
-E noctx \
-E nolintlint \
-E rowserrcheck \
-E exportloopref \
-E sqlclosecheck \
-E stylecheck \
-E unconvert \
-E unparam
@echo "Lint-free"
#
# Install Tools
#
PHONY+= sec
sec: $(GOPATH)/bin/gosec
@echo "Checking for security problems ..."
@gosec -quiet -confidence high -severity medium ./...
@echo "No problems found"; \
$(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/golint:
@echo "🔘 Installing golint ... (`date '+%H:%M:%S'`)"
@GO111MODULE=off go get -u golang.org/x/lint/golint
$(GOPATH)/bin/goimports:
@echo "🔘 Installing goimports ... (`date '+%H:%M:%S'`)"
@GO111MODULE=off go get -u golang.org/x/tools/cmd/goimports
$(GOPATH)/bin/gosec:
@echo "🔘 Installing gosec ... (`date '+%H:%M:%S'`)"
@curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(GOPATH)/bin
$(GOPATH)/bin/oapi-codegen:
@echo "🔘 Installing oapicodegen ... (`date '+%H:%M:%S'`)"
@go get github.com/deepmap/oapi-codegen/cmd/[email protected]
PHONY+= tools
tools: $(GOPATH)/bin/golangci-lint $(GOPATH)/bin/golint $(GOPATH)/bin/gosec $(GOPATH)/bin/goimports $(GOPATH)/bin/oapi-codegen
PHONY+= update-tools
update-tools: delete-tools $(GOPATH)/bin/golangci-lint $(GOPATH)/bin/golint $(GOPATH)/bin/gosec $(GOPATH)/bin/goimports
PHONY+= delete-tools
delete-tools:
@rm $(GOPATH)/bin/golangci-lint
@rm $(GOPATH)/bin/gosec
@rm $(GOPATH)/bin/golint
@rm $(GOPATH)/bin/goimports
.PHONY: all tidy generate build clean test lint