-
Notifications
You must be signed in to change notification settings - Fork 233
/
Copy pathMakefile.tmpl
156 lines (115 loc) · 4.69 KB
/
Makefile.tmpl
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
export PROJ_PATH={{.module}}
export DATE := $(shell date +%Y.%m.%d-%H%M)
export LATEST_COMMIT := $(shell git log --pretty=format:'%h' -n 1)
export BRANCH := $(shell git branch |grep -v "no branch"| grep \*|cut -d ' ' -f2)
export BUILT_ON_IP := $(shell [ $$(uname) = Linux ] && hostname -i || hostname )
export BIN_DIR=./bin
export PACKR2_EXECUTABLE := $(shell command -v packr2 2> /dev/null)
export SWAG_EXECUTABLE := $(shell command -v swag 2> /dev/null)
export RUNTIME_VER := $(shell go version)
export BUILT_ON_OS=$(shell uname -a)
ifeq ($(BRANCH),)
BRANCH := master
endif
export COMMIT_CNT := $(shell git rev-list HEAD | wc -l | sed 's/ //g' )
export BUILD_NUMBER := ${BRANCH}-${COMMIT_CNT}
export COMPILE_LDFLAGS=-s -X "main.BuildDate=${DATE}" \
-X "main.LatestCommit=${LATEST_COMMIT}" \
-X "main.BuildNumber=${BUILD_NUMBER}" \
-X "main.BuiltOnIP=${BUILT_ON_IP}" \
-X "main.BuiltOnOs=${BUILT_ON_OS}" \
-X "main.RuntimeVer=${RUNTIME_VER}"
build_info: check_prereq ## Build the container
@echo ''
@echo '---------------------------------------------------------'
@echo 'BUILT_ON_IP $(BUILT_ON_IP)'
@echo 'BUILT_ON_OS $(BUILT_ON_OS)'
@echo 'DATE $(DATE)'
@echo 'LATEST_COMMIT $(LATEST_COMMIT)'
@echo 'BRANCH $(BRANCH)'
@echo 'COMMIT_CNT $(COMMIT_CNT)'
@echo 'BUILD_NUMBER $(BUILD_NUMBER)'
@echo 'COMPILE_LDFLAGS $(COMPILE_LDFLAGS)'
@echo 'PATH $(PATH)'
@echo 'PACKR2_EXECUTABLE $(PACKR2_EXECUTABLE)'
@echo 'SWAG_EXECUTABLE $(SWAG_EXECUTABLE)'
@echo 'RUNTIME_VER $(RUNTIME_VER)'
@echo '---------------------------------------------------------'
@echo ''
####################################################################################################################
##
## help for each task - https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
##
####################################################################################################################
.PHONY: help
help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
####################################################################################################################
##
## Build of binaries
##
####################################################################################################################
all: example test ## build example and run tests
binaries: example ## build binaries in bin dir
create_dir:
@mkdir -p $(BIN_DIR)
check_prereq: create_dir
ifndef PACKR2_EXECUTABLE
go get -u github.com/gobuffalo/packr/v2/packr2
endif
$(warning "found packr2")
ifndef SWAG_EXECUTABLE
go get -u github.com/swaggo/swag/cmd/swag
endif
$(warning "found swag")
build_app: create_dir
packr2 build -o $(BIN_DIR)/$(BIN_NAME) -a -ldflags '$(COMPILE_LDFLAGS)' $(APP_PATH)
example: build_info ## build example binary in bin dir
@echo "build example server"
swag init --dir . --generalInfo ./app/server/main.go
make BIN_NAME=example APP_PATH=$(PROJ_PATH)/app/server build_app
@echo ''
@echo ''
####################################################################################################################
##
## Cleanup of binaries
##
####################################################################################################################
clean_binaries: clean_example ## clean all binaries in bin dir
clean_binary: ## clean binary in bin dir
rm -f $(BIN_DIR)/$(BIN_NAME)
clean_example: ## clean example
make BIN_NAME=example clean_binary
test: ## run tests
go test -v $(PROJ_PATH)
fmt: ## run fmt on project
#go fmt $(PROJ_PATH)/...
gofmt -s -d -w -l .
doc: ## launch godoc on port 6060
godoc -http=:6060
deps: ## display deps for project
{{.deps}} |grep "/" | grep -v $(PROJ_PATH)| grep "\." | sort |uniq
lint: ## run lint on the project
golint ./...
staticcheck: ## run staticcheck on the project
staticcheck -ignore "$(shell cat .checkignore)" .
vet: ## run go vet on the project
go vet .
tools: ## install dependent tools for code analysis
go get -u github.com/gogo/protobuf
go get -u github.com/gogo/protobuf/proto
go get -u github.com/gogo/protobuf/jsonpb
go get -u github.com/gogo/protobuf/protoc-gen-gogo
go get -u github.com/gogo/protobuf/gogoproto
go get -u honnef.co/go/tools
go get -u github.com/gordonklaus/ineffassign
go get -u github.com/fzipp/gocyclo
go get -u golang.org/x/lint/golint
go get -u github.com/gobuffalo/packr/v2/packr2
regen: ## regenerate generated code
{{.RegenCmdLine}}
{{if hasField . "ProtocCmdLine"}}
protoc: ## regenerate from .protofile
{{.ProtocCmdLine}}
{{end}}