-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
101 lines (79 loc) · 2.63 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
96
97
98
99
100
101
# Define the paths to the source code and build artifacts
BUILDDIR=./build
# Define the name of the binary and Docker image
# Get a list of directories in ./examples
TARGETS := $(notdir $(shell find ./examples -mindepth 1 -maxdepth 1 -type d))
BUILD_TARGETS := $(addprefix build-,$(TARGETS))
# Find directories with Dockerfiles
DOCKER_DIRS := $(wildcard ./examples/*/Dockerfile)
DOCKER_TARGETS := $(notdir $(dir $(DOCKER_DIRS)))
BUILD_DOCKER_TARGETS := $(addprefix docker-,$(DOCKER_TARGETS))
# Define the build flags for go build
BUILD_FLAGS=-ldflags="-s -w"
.PHONY: all
all: test build build-docker
.PHONY: build
build: $(BUILD_TARGETS)
.PHONY: proto
proto:
cd proto && buf generate
.PHONY: mocks
mocks:
mockery
.PHONY: gen
gen:
# Run go generate to generate any required files
go generate ./...
$(BUILD_TARGETS):
# Build the production binary
go build $(BUILD_FLAGS) -o $(BUILDDIR)/$(@:build-%=%) ./cmd/$(@:build-%=%)
.PHONY: vulncheck
vulncheck: $(BUILDDIR)/
GOBIN=$(BUILDDIR) go install golang.org/x/vuln/cmd/govulncheck@latest
$(BUILDDIR)/govulncheck ./...
.PHONY: cover
cover:
go test -coverprofile=.coverage.tmp ./...
cat .coverage.tmp | grep -Ev '/mock_|/.*options.go' > .coverage
go tool cover -func=.coverage
ifeq (,$(COUNT))
COUNT := 3
endif
.PHONY: test
test:
go test ./... -vet=all -v -count $(COUNT)
.PHONY: bench
bench:
go test -bench=./...
ifeq (,$(N))
N := 100
endif
.PHONY: run-bench
run-bench:
for i in {1..$(N)}; do go run ./examples/bench $(ARGS) 2>&1; done
.PHONY: clean
clean:
# Remove the build artifacts
rm -rf $(BUILDDIR)
.PHONY: install-tools
install-tools:
go install github.com/vektra/mockery/[email protected]
.PHONY: help
help:
@echo "Makefile for building, testing, and Dockerizing a Go application"
@echo ""
@echo "Usage:"
@echo " make gen Generate necessary files"
@echo " make proto Compile proto files"
@echo " make mocks Update interface mocks"
@echo " make all Run tests, build binaries, and build docker images"
@echo " make build Build all binaries"
@echo " make build-{target} Build the production binary that is in ./cmd/{target}"
@echo " make vulncheck Test packages for known vulnerabilities"
@echo " make cover Run test coverage analysis"
@echo " make test Run all tests"
@echo " make bench Run benchmark tests"
@echo " make run-bench ARGS="" Run example benchmark, N argument for run count, ARGS as arguments to executable"
@echo " make clean Remove build artifacts"
@echo " make help Display this help message"
.DEFAULT_TARGET: help