Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
82 lines (69 loc) · 2.89 KB
/
Copy pathMakefile
File metadata and controls
82 lines (69 loc) · 2.89 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
78
79
80
81
82
MAKEFLAGS += --no-print-directory
VERSION ?= v1.0.0
BIN_DIR ?= bin
GO_LDFLAGS_PART := -s -w
GO_LDFLAGS_PART += -X "github.com/go-sdk/core/osx.iVersion=$(VERSION)"
GO_LDFLAGS := -ldflags '$(GO_LDFLAGS_PART)'
PROTOC_GEN_GO_VERSION ?= v1.36.12 # https://github.com/protocolbuffers/protobuf-go
PROTOC_GEN_GO_GRPC_VERSION ?= v1.6.2 # https://github.com/grpc/grpc-go
PROTOC_GEN_GRPC_GATEWAY_VERSION ?= v2.30.0 # https://github.com/grpc-ecosystem/grpc-gateway
PROTOC_GEN_OPENAPIV2_VERSION ?= v2.30.0 # https://github.com/grpc-ecosystem/grpc-gateway(与 protoc-gen-grpc-gateway 同仓库同版本)
PROTOC_GEN_GO_JSON_VERSION ?= v1.1.3 # https://github.com/protoc-contrib/protoc-gen-go-json
.PHONY: tidy
tidy: ##@ Tidy go.mod and go.sum.
@go mod tidy
.PHONY: prepare
prepare: ##@ Install buf local plugins.
@go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GO_GRPC_VERSION)
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@$(PROTOC_GEN_GRPC_GATEWAY_VERSION)
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@$(PROTOC_GEN_OPENAPIV2_VERSION)
@go install github.com/protoc-contrib/protoc-gen-go-json/cmd/protoc-gen-go-json@$(PROTOC_GEN_GO_JSON_VERSION)
.PHONY: generate
generate: ##@ Lint & Generate proto files.
@if command -v buf >/dev/null 2>&1; then \
rm -rf tests/pb tests/openapi && rm -f options/*.pb.go options/*.pb.json.go && \
buf lint && buf generate && echo "done."; \
else \
echo "buf is not installed. Please install it from https://github.com/bufbuild/buf"; \
exit 1; \
fi
.PHONY: lint
lint: tidy ##@ Lint all packages.
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run --timeout 5m && \
echo "done."; \
else \
echo "golangci-lint is not installed. Please install it from https://github.com/golangci/golangci-lint"; \
exit 1; \
fi
.PHONY: test
test: tidy ##@ Test all packages.
@if command -v gotestsum >/dev/null 2>&1; then \
gotestsum --format testname --format-icons text -- -race -count 1 -failfast -v ./...; \
else \
go test -race -count 1 -failfast -v ./...; \
fi
.PHONY: build
build: ##@ Build tests/server into bin.
@mkdir -p $(BIN_DIR)
@go build $(GO_LDFLAGS) -o $(BIN_DIR)/server ./tests/server
.PHONY: run
run: build ##@ Run tests/server example.
@$(BIN_DIR)/server
.PHONY: help
help: ##@ (Default) Show help.
@printf "\nUsage: make <command>\n"
@grep -F -h "##@" $(MAKEFILE_LIST) | grep -F -v grep -F | sed -e 's/\\$$//' | awk 'BEGIN {FS = ":*[[:space:]]*##@[[:space:]]*"}; \
{ \
if($$2 == "") \
pass; \
else if($$0 ~ /^#/) \
printf "\n%s\n", $$2; \
else if($$1 == "") \
printf " %-20s%s\n", "", $$2; \
else \
printf "\n \033[34m%-20s\033[0m %s\n", $$1, $$2; \
}'
@printf "\n"
.DEFAULT_GOAL := help