-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
95 lines (70 loc) · 2.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
GO_VERSION_SHORT:=$(shell echo `go version` | sed -E 's/.* go(.*) .*/\1/g')
ifneq ("1.16","$(shell printf "$(GO_VERSION_SHORT)\n1.16" | sort -V | head -1)")
$(error NEED GO VERSION >= 1.16. Found: $(GO_VERSION_SHORT))
endif
export GO111MODULE=on
SERVICE_NAME=srv-verification-api
SERVICE_PATH=ozonmp/srv-verification-api
PGV_VERSION:="v0.6.1"
BUF_VERSION:="v0.56.0"
OS_NAME=$(shell uname -s)
OS_ARCH=$(shell uname -m)
GO_BIN=$(shell go env GOPATH)/bin
BUF_EXE=$(GO_BIN)/buf$(shell go env GOEXE)
ifeq ("NT", "$(findstring NT,$(OS_NAME))")
OS_NAME=Windows
endif
.PHONY: run
run:
go run cmd/grpc-server/main.go
.PHONY: lint
lint:
golangci-lint run ./...
.PHONY: test
test:
go test -v -race -timeout 30s -coverprofile cover.out ./...
go tool cover -func cover.out | grep total | awk '{print $$3}'
# ----------------------------------------------------------------
.PHONY: generate
generate: .generate-install-buf .generate-go .generate-python .generate-finalize-go .generate-finalize-python
.PHONY: generate
generate-go: .generate-install-buf .generate-go .generate-finalize-go
.generate-install-buf:
@ command -v buf 2>&1 > /dev/null || (echo "Install buf" && \
curl -sSL0 https://github.com/bufbuild/buf/releases/download/$(BUF_VERSION)/buf-$(OS_NAME)-$(OS_ARCH)$(shell go env GOEXE) --create-dirs -o "$(BUF_EXE)" && \
chmod +x "$(BUF_EXE)")
.generate-go:
$(BUF_EXE) generate
.generate-python:
$(BUF_EXE) generate --template buf.gen.python.yaml
.generate-finalize-go:
mv pkg/$(SERVICE_NAME)/github.com/$(SERVICE_PATH)/pkg/$(SERVICE_NAME)/* pkg/$(SERVICE_NAME)
rm -rf pkg/$(SERVICE_NAME)/github.com/
cd pkg/$(SERVICE_NAME) && ls go.mod || (go mod init github.com/$(SERVICE_PATH)/pkg/$(SERVICE_NAME) && go mod tidy)
.generate-finalize-python:
find pypkg/srv-verification-api -type d -exec touch {}/__init__.py \;
# ----------------------------------------------------------------
.PHONY: deps
deps: deps-go .deps-python
.PHONY: deps-go
deps-go:
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
go install github.com/grpc-ecosystem/grpc-gateway/v2/[email protected]
go install github.com/grpc-ecosystem/grpc-gateway/v2/[email protected]
go install github.com/envoyproxy/protoc-gen-validate@$(PGV_VERSION)
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@latest
.deps-python:
python3 -m pip install grpcio-tools grpclib protobuf # python3 for my machine
.PHONY: build
build: generate .build
.PHONY: build-go
build-go: generate-go .build
.build:
go mod download && CGO_ENABLED=0 go build \
-tags='no_mysql no_sqlite3' \
-ldflags=" \
-X 'github.com/$(SERVICE_PATH)/internal/config.version=$(VERSION)' \
-X 'github.com/$(SERVICE_PATH)/internal/config.commitHash=$(COMMIT_HASH)' \
" \
-o ./bin/grpc-server$(shell go env GOEXE) ./cmd/grpc-server/main.go