-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
115 lines (94 loc) · 3.67 KB
/
Copy pathMakefile
File metadata and controls
115 lines (94 loc) · 3.67 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
.PHONY: build build-flo install test lint generate tidy proto proto-clean coverage coverage-report coverage-summary coverage-check
PROTO_DIR := proto
PROTO_GO_OUT := api
API_DIR := api
# Binaries
BIN_DIR := bin
BINARY_NAME := flo
## Coverage
COVERAGE_FILE := coverage.out
THRESHOLD ?= $(or $(COVERAGE_THRESHOLD),50)
build:
go build ./...
dashboard-build:
cd dashboard && ( [ -f package-lock.json ] && npm ci || npm install ) && npm run build
@# Sync built assets into internal/ui/static for embedding
rm -rf internal/ui/static
mkdir -p internal/ui/static
cp -R dashboard/dist/* internal/ui/static/
# Build the flo CLI binary
build-flo:
@mkdir -p $(BIN_DIR)
go build -o $(BIN_DIR)/$(BINARY_NAME) ./cmd/flo
## Install binaries to GOPATH/bin (fallback to $(HOME)/go/bin if GOPATH unset)
install: build-flo dashboard-build
@echo "Installing $(BINARY_NAME)..."
@install -m 755 $(BIN_DIR)/$(BINARY_NAME) $(GOPATH)/bin/ 2>/dev/null || install -m 755 $(BIN_DIR)/$(BINARY_NAME) $(HOME)/go/bin/
@echo "Installation completed!"
install-dashboard: dashboard-build
@echo "Installing dashboard..."
@install -m 755 dashboard/dist/* $(HOME)/go/bin/
@echo "Installation completed!"
install-flo: build-flo
@echo "Installing $(BINARY_NAME)..."
@install -m 755 $(BIN_DIR)/$(BINARY_NAME) $(GOPATH)/bin/ 2>/dev/null || install -m 755 $(BIN_DIR)/$(BINARY_NAME) $(HOME)/go/bin/
@echo "Installation completed!"
test:
go test ./...
lint:
golangci-lint run
generate:
$(MAKE) proto
tidy:
go mod tidy
# Protobuf helpers (via protoc)
proto:
@mkdir -p $(PROTO_GO_OUT)
@if ! command -v protoc >/dev/null 2>&1; then \
echo "protoc not found. Please install Protocol Buffers compiler:"; \
echo " - macOS: brew install protobuf"; \
echo " - Ubuntu: apt-get install protobuf-compiler"; \
echo " - Windows: download from https://github.com/protocolbuffers/protobuf/releases"; \
exit 1; \
fi
@echo "Installing/updating Go protoc plugins (protoc-gen-go, protoc-gen-go-grpc)"
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
@PROTO_FILES=$$(find $(PROTO_DIR) -name "*.proto" 2>/dev/null); \
if [ -z "$$PROTO_FILES" ]; then \
echo "No .proto files under $(PROTO_DIR)/; skipping generation."; \
else \
echo "Generating Go stubs..."; \
protoc -I $(PROTO_DIR) \
--go_out=$(PROTO_GO_OUT) --go_opt=paths=source_relative \
--go-grpc_out=$(PROTO_GO_OUT) --go-grpc_opt=paths=source_relative \
$$PROTO_FILES; \
echo "Protos generated in $(PROTO_GO_OUT)"; \
fi
proto-clean:
rm -rf $(PROTO_DIR)/gen
# Coverage helpers
coverage:
go test -coverprofile=$(COVERAGE_FILE) ./...
coverage-report:
@if [ ! -f $(COVERAGE_FILE) ]; then \
echo "Error: $(COVERAGE_FILE) not found. Run 'make coverage' first."; \
exit 1; \
fi
go tool cover -html=$(COVERAGE_FILE) -o coverage.html
@echo "Coverage report generated at coverage.html"
coverage-summary:
@if [ ! -f $(COVERAGE_FILE) ]; then \
echo "Error: $(COVERAGE_FILE) not found. Run 'make coverage' first."; \
exit 1; \
fi
@go tool cover -func=$(COVERAGE_FILE) | grep total | awk '{print "Total coverage: " $$3}'
coverage-check:
@echo "Checking unit test coverage threshold: $(THRESHOLD)%"
@if [ ! -f $(COVERAGE_FILE) ]; then \
echo "Error: $(COVERAGE_FILE) not found. Run 'make coverage' first."; \
exit 1; \
fi
@unit_cov=$$(go tool cover -func=$(COVERAGE_FILE) | grep total: | awk '{print $$3}' | sed 's/%//'); \
echo "Unit test coverage: $$unit_cov%"; \
awk -v a="$$unit_cov" -v b="$(THRESHOLD)" 'BEGIN { exit (a>=b)?0:1 }' && echo "✅ Coverage ("$$unit_cov"%) meets threshold ($(THRESHOLD)%)" || (echo "❌ Coverage ("$$unit_cov"%) below threshold ($(THRESHOLD)%)" && exit 1)