-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
105 lines (89 loc) · 2.92 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
102
103
104
105
UT_COV=$(PWD)/cov.out
GOCMD=go
GOBUILD=$(GOCMD) build -race -v -trimpath
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test -race -timeout 2m -v -count=1 -coverprofile=$(UT_COV)
GOCOVER=$(GOCMD) tool cover
GOFMT=gofmt -w
GOVET=go vet
RUNNER_HOME=/tmp/runner
CERTS_DIR=$(RUNNER_HOME)/certs
OS := $(shell uname -s)
ifeq ($(OS),Darwin)
# https://github.com/golang/go/issues/49138#issuecomment-951401558
export MallocNanoZone=0
endif
CMDS=client server
build: $(CMDS:%=%.bin)
@# Help: Build binaries for client and server
install: build
@echo ">>>> Installing client and server binaries to /tmp/runner/bin"
cp -r $(PWD)/bin $(RUNNER_HOME)
@echo "<<<< Done installing binaries!"
@# Help: Install client and server binaries
format:
@echo ">>>> Formatting code..."
$(GOFMT) .
@echo "<<<< Done formatting code!"
@# Help: Auto-format source code
lint: protogen format
@echo ">>>> Running static analysis..."
$(GOVET) ./...
@echo "<<<< Done running static analysis!"
@# Help: Run static analysis
protogen:
@echo ">>>> Running protobuf bindings generation..."
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
pkg/proto/*.proto
@echo "<<<< Done running protobuf bindings generation!"
@# Help: Generate protobuf bindings
rootfs:
@echo ">>>> Setting up root filesystem..."
rm -rf $(RUNNER_HOME)/rootfs && \
mkdir -p $(RUNNER_HOME)/rootfs && \
tar -xzf resources/alpine-minirootfs-3.15.0-x86_64.tar.gz -C $(RUNNER_HOME)/rootfs/
@echo "<<<< Done settings up root filesystem!"
@# Help: Set up root filesystem
certs:
@echo ">>>> Generating certificates..."
mkdir -p $(RUNNER_HOME)/certs
cp -r resources/certs $(RUNNER_HOME)/
@echo "<<<< Done generating certificates!"
@# Help: Generate certificates
$(CMDS:%=%.bin): %.bin: format lint protogen rootfs
@echo ">>>> Building $* binary..."
mkdir -p $(PWD)/bin
cd $(PWD)/cmd/$* && \
$(GOBUILD) -o $(PWD)/bin/$(*F)
@echo "<<<< Done building $* binary!"
@# Help: Build binary for $*
clean:
@echo ">>>> Cleaning everything up..."
rm -rf $(RUNNER_HOME)
@echo "<<<< Done cleaning up!"
@# Help: Clean everything
test: lint protogen rootfs certs install
@echo ">>>> Running tests in $(PWD)..."
$(GOTEST) ./...
@echo "<<<< Done testing!"
@# Help: Run all the tests
integration.test: lint protogen rootfs certs install
@echo ">>>> Running integration tests..."
$(GOTEST) $(PWD)/integration
@echo "<<<< Done running integration tests!"
@# Help: Run integration tests
coverage:
$(GOCOVER) -html=$(UT_COV)
@# Help: Show unit test coverage in browser
help:
@printf "%-20s %s\n" "Target" "Description"
@printf "%-20s %s\n" "------" "-----------"
@make -pqR : 2>/dev/null \
| awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \
| sort \
| egrep -v -e '^[^[:alnum:]]' -e '^$@$$' \
| xargs -I _ sh -c 'printf "%-20s " _; make _ -nB | (grep -i "^# Help:" || echo "") | tail -1 | sed "s/^# Help: //g"'