-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (104 loc) · 3.77 KB
/
Makefile
File metadata and controls
122 lines (104 loc) · 3.77 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
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
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
GEN_OUT := $(ROOT_DIR)/out
PROTO_FILES := $(shell find $(ROOT_DIR) -name "*.proto" -not -path "*/third_party/*")
TOOLS_OUT := $(ROOT_DIR)/tools/bin
TOOL_PKGS := $(shell go tool | grep -E '^(github.com|google.golang.org)')
TOOL_CMDS := $(foreach tool,$(notdir ${TOOL_PKGS}),${TOOLS_OUT}/${tool})
$(foreach cmd,${TOOL_CMDS},$(eval $(notdir ${cmd})Cmd := ${cmd}))
export PATH := $(TOOLS_OUT):$(PATH)
.PHONY: lint
lint:
@if [ -z "$(TARGET)" ]; then \
golangci-lint run; \
else \
golangci-lint run $(TARGET)/...; \
fi
.PHONY: fix
fix:
@echo "🔧 Running golangci-lint with --fix..."
@golangci-lint run --fix
@echo "✅ Auto-fixes applied"
.PHONY: test
test: test-staticcheck test-vet test-unit
test-unit: gen-proto
@go test $$(go list ./... | grep -v '/examples/' | grep -v 'test$$' | grep -v 'tests$$') -cover
test-vet:
@go vet ./...
test-staticcheck:
@staticcheck ./...
.PHONY: test-coverage
test-coverage: gen-proto
@if [ -z "$(TARGET)" ]; then \
TARGET_PATH="$$(go list ./... | grep -v '/examples/' | grep -v 'test$$' | grep -v 'tests$$')"; \
else \
TARGET_PATH="$(TARGET)"; \
fi; \
if [ "$(PORCELAIN)" = "1" ]; then \
echo "🧪 Generating test coverage report..."; \
go test $$TARGET_PATH -coverprofile cover.out.tmp; \
cat cover.out.tmp | grep -v ".pb.go" | grep -v ".pb.gw.go" > cover.out; \
rm cover.out.tmp; \
go tool cover -func cover.out; \
echo ""; \
echo "📊 Full coverage report saved to cover.out"; \
echo "💡 View HTML report with: go tool cover -html=cover.out"; \
else \
echo "🧪 Running tests with coverage..."; \
echo ""; \
go test $$TARGET_PATH -coverprofile cover.out.tmp; \
cat cover.out.tmp | grep -v ".pb.go" | grep -v ".pb.gw.go" > cover.out; \
rm cover.out.tmp; \
echo ""; \
echo "📊 Coverage Summary (excluding generated files):"; \
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"; \
go tool cover -func cover.out | tail -1; \
echo ""; \
echo "💾 Full report saved to cover.out"; \
echo "💡 View detailed HTML report: go tool cover -html=cover.out"; \
echo "🤖 Machine-readable output: make test-coverage PORCELAIN=1"; \
fi
.PHONY: clean-proto
clean-proto:
@rm -f gen-proto.touchfile
@find . -name "*.pb.go" -type f -delete
@find . -name "*.pb.gw.go" -type f -delete
@echo "👷🏽♀️ Generated proto files removed"
.PHONY: clean-coverage
clean-coverage:
@rm -f cover.out cover.out.tmp
@echo "🧹 Coverage files removed"
.PHONY: gen-proto
gen-proto: gen-proto.touchfile
gen-proto.touchfile: $(GEN_OUT)/openapiv2 $(PROTO_FILES) tools.touchfile
@protoc -I$(ROOT_DIR)/proto \
-I$(ROOT_DIR)/proto/third_party/googleapis \
--go_out=$(GOPATH)src/ \
--grpc_out=$(GOPATH)src/ \
--grpc-gateway_out $(GOPATH)src \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt generate_unbound_methods=false \
--grpc-gateway_opt omit_package_doc=true \
--openapiv2_out $(GEN_OUT)/openapiv2 \
--openapiv2_opt logtostderr=true \
--openapiv2_opt use_go_templates=true \
--openapiv2_opt simple_operation_ids=true \
--openapiv2_opt openapi_naming_strategy=fqn \
--openapiv2_opt disable_default_errors=true \
--openapiv2_opt allow_merge=true \
$(PROTO_FILES)
@touch gen-proto.touchfile
@echo "👷🏽♀️ Protos generated"
$(GEN_OUT)/openapiv2:
@mkdir -p $(GEN_OUT)/openapiv2
go.mod:
@go mod tidy
@touch go.mod
${TOOL_CMDS}: go.mod
@mkdir -p $(TOOLS_OUT)
@go build -o $@ $(filter %/$(@F),${TOOL_PKGS})
.PHONY: tools
tools: tools.touchfile
tools.touchfile: ${TOOL_CMDS}
@# protoc looks for a different cmd name than what is installed by go.
@touch tools.touchfile
@cp $(TOOLS_OUT)/protoc-gen-go-grpc $(TOOLS_OUT)/protoc-gen-grpc