-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
89 lines (69 loc) · 2.5 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
OUTPUT_DIR = ./bin
ORCHESTRATOR_BIN = $(OUTPUT_DIR)/orchestrator
PROJECT_ROOT = .
MIGRATIONS_DIR = $(PROJECT_ROOT)/server/standalone/migration
VERSION = dirty-$(shell git rev-parse --short HEAD)
protos = $(PROJECT_ROOT)/lib/asset
go_src = $(shell find . -type f -name '*.go')
files_to_lint := $(shell goimports -l . | grep -vE '\.pb\.go$$')
sql_migrations = $(wildcard $(MIGRATIONS_DIR)/*.sql)
protobufs = $(wildcard $(protos)/*.proto)
pbgo = $(protobufs:.proto=.pb.go)
# Disable cgo since we don't use it and linking is broken with some version of go1.18 on macos
build_env = CGO_ENABLED=0
.PHONY: all
all: orchestrator ## Build all binaries
.PHONY: orchestrator
orchestrator: $(ORCHESTRATOR_BIN) ## Build server binary
.PHONY: codegen
codegen: $(pbgo) $(migrations_binpack) ## Build codegen tool
.PHONY: goimports
goimports: goimports -l .
.PHONY: lint-goimports ## Lint the codebase with gimports
lint-goimports:
@if [ "$(files_to_lint)" ]; then \
echo "Following files should be linted:"; \
echo "$(files_to_lint)"; \
exit 1; \
fi
.PHONY: lint
lint: codegen mocks lint-goimports ## Analyze the codebase
golangci-lint run
.PHONY: format
format: codegen # Format codebase
goimports -w .
$(ORCHESTRATOR_BIN): $(pbgo) $(go_src) $(OUTPUT_DIR) $(lib_generated)
$(build_env) go build -o $(ORCHESTRATOR_BIN) -ldflags="-X 'github.com/substra/orchestrator/server/common.Version=$(VERSION)'" ./server
$(OUTPUT_DIR):
mkdir $(OUTPUT_DIR)
$(pbgo): %.pb.go: %.proto
protoc --proto_path=$(protos) \
--go_opt=paths=source_relative \
--go-grpc_opt=paths=source_relative \
--go-grpc_out=$(protos) \
--go_out=$(protos) \
$<
.PHONY: proto-codegen
proto-codegen: $(pbgo) ## Generate go code from proto files
.PHONY: mocks
mocks: ## Generate mocks for public interfaces
mockery --dir $(PROJECT_ROOT) --all --inpackage --quiet
.PHONY: clean
clean: clean-protos clean-mocks ## Remove all generated code
rm -rf $(OUTPUT_DIR)
.PHONY: test
test: codegen mocks ## Run unit-tests
go test -race -cover ./... -short -timeout 30s
.PHONY: clean-mocks
clean-mocks: ## Remove generated mocks
find $(PROJECT_ROOT) -name "mock_*.go" -delete
.PHONY: clean-protos
clean-protos: ## Remove go code generated from proto files
-rm $(wildcard $(protos)/*.pb.go)
.PHONY: docs-charts
docs-charts: ## Generate Helm chart documentation
$(MAKE) -C charts doc
### Makefile
.PHONY: help
help: ## Display this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'