forked from go-eagle/eagle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
150 lines (127 loc) · 3.87 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
146
147
148
149
SHELL := /bin/bash
BASEDIR = $(shell pwd)
# build with version infos
versionDir = "github.com/go-eagle/eagle/pkg/version"
gitTag = $(shell if [ "`git describe --tags --abbrev=0 2>/dev/null`" != "" ];then git describe --tags --abbrev=0; else git log --pretty=format:'%h' -n 1; fi)
buildDate = $(shell TZ=Asia/Shanghai date +%FT%T%z)
gitCommit = $(shell git log --pretty=format:'%H' -n 1)
gitTreeState = $(shell if git status|grep -q 'clean';then echo clean; else echo dirty; fi)
ldflags="-w -X ${versionDir}.gitTag=${gitTag} -X ${versionDir}.buildDate=${buildDate} -X ${versionDir}.gitCommit=${gitCommit} -X ${versionDir}.gitTreeState=${gitTreeState}"
PROJECT_NAME := "github.com/go-eagle/eagle"
PKG := "$(PROJECT_NAME)"
GO_VERSION=$(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
PKG_LIST := $(shell go list ${PKG}/... | grep -v examples | grep -v pkg)
GO_FILES := $(shell find . -name '*.go' | grep -v _test.go)
# init environment variables
export PATH := $(shell go env GOPATH)/bin:$(PATH)
export GOPATH := $(shell go env GOPATH)
export GO111MODULE := on
# make make all
.PHONY: all
all: lint test build
.PHONY: build
# make build, Build the binary file
build: dep
@go build -v -ldflags ${ldflags} .
.PHONY: dep
# make dep Get the dependencies
dep:
@go mod download
.PHONY: fmt
# make fmt
fmt:
@gofmt -s -w .
.PHONY: golint
# make golint
golint:
@if ! which golint &>/dev/null; then \
echo "Installing golint"; \
go get -u golang.org/x/lint/golint; \
fi
@golint -set_exit_status ${PKG_LIST}
.PHONY: lint
# make lint
lint:
@if ! which golangci-lint &>/dev/null; then \
echo "Installing golangci-lint"; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0; \
fi
${GOPATH}/bin/golangci-lint run ./...
.PHONY: test
# make test
test:
@go test -short ${PKG_LIST}
.PHONY: vet
# make vet
vet:
go vet ./... | grep -v vendor;true
.PHONY: cover
# make cover
cover:
@go test -short -coverprofile coverage.txt -covermode=atomic ${PKG_LIST}
.PHONY: view-cover
# make view-cover preview coverage
view-cover:
go tool cover -html=coverage.txt
.PHONY: docker
# make docker 生成docker镜像
docker:
docker build -t eagle:v1.0 -f Dockerfile .
.PHONY: clean
# make clean
clean:
@-rm -vrf eagle
@-rm -vrf cover.out
@-rm -vrf coverage.txt
@go mod tidy
@echo "clean finished"
.PHONY: docs
# gen swagger doc
docs:
@if ! which swag &>/dev/null; then \
echo "downloading swag"; \
go get -u github.com/swaggo/swag/cmd/swag; \
fi
@swag init
@echo "gen-docs done"
@echo "see docs by: http://localhost:8080/swagger/index.html"
.PHONY: graph
# make graph 生成交互式的可视化Go程序调用图(会在浏览器自动打开)
graph:
@export GO111MODULE="on"
@if ! which go-callvis &>/dev/null; then \
echo "downloading go-callvis"; \
go get -u github.com/ofabry/go-callvis; \
fi
@echo "generating graph"
@go-callvis github.com/go-eagle/eagle
.PHONY: mockgen
# make mockgen gen mock file
mockgen:
@echo "downloading mockgen"
@go get github.com/golang/mock/mockgen
cd ./internal && for file in `egrep -rnl "type.*?interface" ./dao | grep -v "_test" `; do \
echo $$file ; \
cd .. && mockgen -destination="./internal/mock/$$file" -source="./internal/$$file" && cd ./internal ; \
done
.PHONY: ca
# generate ca
ca:
openssl req -new -nodes -x509 -out config/server.crt -keyout config/server.key -days 3650 -subj "/C=DE/ST=NRW/L=Earth/O=Random Company/OU=IT/CN=127.0.0.1/emailAddress=xxxxx@qq.com"
# show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := all