-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (100 loc) · 4.26 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
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
export PROJ_PATH=github.com/alexj212/webmgmt
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 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.DATE=${DATE}" \
-X "main.LATEST_COMMIT=${LATEST_COMMIT}" \
-X "main.BUILD_NUMBER=${BUILD_NUMBER}" \
-X "main.BUILT_ON_IP=${BUILT_ON_IP}" \
-X "main.BUILT_ON_OS=${BUILT_ON_OS}"
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 '---------------------------------------------------------'
@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
####################################################################################################################
##
## Code vetting tools
##
####################################################################################################################
tools: ## install dependent tools for code analysis
go install github.com/gordonklaus/ineffassign@latest
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
go install golang.org/x/lint/golint@latest
go install github.com/gojp/goreportcard/cmd/goreportcard-cli@latest
go install github.com/goreleaser/goreleaser@latest
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
go list -f '{{ join .Deps "\n"}}' . |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 .
reportcard: ## run goreportcard-cli
goreportcard-cli -v
####################################################################################################################
##
## Build of binaries
##
####################################################################################################################
all: example test ## build examples and run tests
binaries: example ## build binaries in bin dir
create_dir:
@mkdir -p $(BIN_DIR)
@rm -f $(BIN_DIR)/web
@ln -s ../web $(BIN_DIR)/web
check_prereq: create_dir
build_app: create_dir
go build -o $(BIN_DIR)/$(BIN_NAME) -a -ldflags '$(COMPILE_LDFLAGS)' $(APP_PATH)
example: build_info ## build example binary in bin dir
@echo "build 1"
@cd example
make BIN_NAME=example APP_PATH=. 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
check_http: ## check http server
http http://localhost:1099/admin/version