-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
70 lines (53 loc) · 1.94 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
.DEFAULT: all
.PHONY: all
API_PROTO_FILES=$(shell find . -name \*.proto | grep -v third_party)
fmt: goimports
@$(GOIMPORTS) -w -local github.com/jibudata $(shell go list -f {{.Dir}} ./...)
vet: ## Run go vet against code.
go vet ./...
tidy:
go mod tidy
.PHONY: init
init:
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
go install golang.org/x/tools/cmd/goimports@latest
.PHONY: api
api:
protoc --proto_path=. \
--proto_path=./third_party \
--go_out=. --go_opt=paths=source_relative \
--go-errors_out=. --go-errors_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
--go-http_out=. --go-http_opt=paths=source_relative \
--openapi_out=enum_type=string:. --openapi_opt=paths=source_relative \
--validate_out=. --validate_opt=paths=source_relative --validate_opt=lang=go \
--openapiv2_out . \
--openapiv2_opt logtostderr=true \
--openapiv2_opt json_names_for_fields=false \
$(API_PROTO_FILES)
.PHONY: lint
lint: golangci-lint
$(golangci-lint) run --timeout=5m
GOIMPORTS = $(shell pwd)/build/bin/goimports
.PHONY: goimports
goimports: ## Download kustomize locally if necessary.
$(call go-get-tool,$(GOIMPORTS),golang.org/x/tools/cmd/[email protected])
golangci-lint = $(shell pwd)/build/bin/golangci-lint
.PHONY: golangci-lint
golangci-lint: ## Download golangci-lint locally if necessary.
$(call go-get-tool,$(golangci-lint),github.com/golangci/golangci-lint/cmd/[email protected])
build: vet
go build -gcflags=all="-N -l" client/client.go
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/build/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef