-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
158 lines (113 loc) · 4.87 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
.PHONY: install-goimport install-staticcheck install-ginkgo install-devtools \
format imports tidy vet staticcheck lint \
fetch-latest-client-protos-version install-protoc-from-client-protos install-protos-devtools update-protos build-protos update-and-build-protos \
build precommit \
test test-auth-service test-cache-service test-leaderboard-service test-storage-service test-topics-service test-http-service \
vendor build-examples run-docs-examples
GOFILES_NOT_NODE = $(shell find . -type f -name '*.go' -not -path "./examples/aws-lambda/infrastructure/*")
TEST_DIRS = momento/ auth/ batchutils/
GINKGO_OPTS = --no-color -v
install-goimport:
@if ! command -v goimports &> /dev/null; then \
echo "goimports not found, installing..."; \
go install golang.org/x/tools/cmd/[email protected]; \
fi
install-staticcheck:
@if ! command -v staticcheck &> /dev/null; then \
echo "staticcheck not found, installing..."; \
go install honnef.co/go/tools/cmd/[email protected]; \
fi
install-ginkgo:
@if ! command -v ginkgo &> /dev/null; then \
echo "ginkgo not found, installing..."; \
go install github.com/onsi/ginkgo/v2/[email protected]; \
fi
install-devtools: install-goimport install-staticcheck install-ginkgo
format:
@echo "Formatting code..."
gofmt -s -w ${GOFILES_NOT_NODE}
imports: install-goimport
@echo "Running goimports..."
goimports -l -w ${GOFILES_NOT_NODE}
tidy:
@echo "Running go mod tidy..."
go mod tidy
vet:
@echo "Running go vet..."
go vet ./...
staticcheck: install-staticcheck
@echo "Running staticcheck..."
staticcheck ./...
lint: format imports tidy vet staticcheck
install-protos-devtools:
@if ! command -v protoc-gen-go &> /dev/null; then \
echo "protoc-gen-go not found, installing..."; \
go install google.golang.org/protobuf/cmd/[email protected]; \
fi
@if ! command -v protoc-gen-go-grpc &> /dev/null; then \
echo "protoc-gen-go-grpc not found, installing..."; \
go install google.golang.org/grpc/cmd/[email protected]; \
fi
fetch-latest-client-protos-version:
@echo $$(git ls-remote --tags --sort="v:refname" https://github.com/momentohq/client_protos.git | tail -n 1 | sed 's!.*/!!')
install-protoc-from-client-protos: install-protos-devtools
@echo "Installing protoc from latest client_protos release..."
@temp_dir=$$(mktemp -d) && \
latest_tag=$(shell $(MAKE) fetch-latest-client-protos-version) && \
echo "Latest release tag: $$latest_tag" && \
git -c advice.detachedHead=false clone --branch "$$latest_tag" https://github.com/momentohq/client_protos.git $$temp_dir && \
cd $$temp_dir && \
./install_protoc.sh && \
rm -rf $$temp_dir
update-protos:
@echo "Updating .proto files from the latest release of the client_protos repository..."
# Note: httpcache.proto is not needed and causes errors, so make sure it's not present
@temp_dir=$$(mktemp -d) && \
latest_tag=$(shell $(MAKE) fetch-latest-client-protos-version) && \
echo "Latest release tag: $$latest_tag" && \
git -c advice.detachedHead=false clone --branch "$$latest_tag" https://github.com/momentohq/client_protos.git $$temp_dir && \
cp $$temp_dir/proto/*.proto internal/protos/ && \
rm -f internal/protos/httpcache.proto && \
rm -rf $$temp_dir
build-protos:
@echo "Generating go code from protos..."
@echo "Run `make install-protos-devtools` if you're missing the Go grpc tools."
protoc -I=internal/protos --go_out=internal/protos --go_opt=paths=source_relative --go-grpc_out=internal/protos --go-grpc_opt=paths=source_relative internal/protos/*.proto
$(MAKE) lint
update-and-build-protos: update-protos build-protos
build:
@echo "Building..."
go build ./...
precommit: lint test
test: install-ginkgo
@echo "Running tests..."
@ginkgo ${GINKGO_OPTS} ${TEST_DIRS}
prod-test: install-ginkgo
@echo "Running tests with consistent reads..."
@CONSISTENT_READS=1 ginkgo ${GINKGO_OPTS} ${TEST_DIRS}
test-auth-service: install-ginkgo
@echo "Testing auth service..."
@CONSISTENT_READS=1 ginkgo ${GINKGO_OPTS} --label-filter auth-service ${TEST_DIRS}
test-cache-service: install-ginkgo
@echo "Testing cache service..."
@CONSISTENT_READS=1 ginkgo ${GINKGO_OPTS} --label-filter cache-service ${TEST_DIRS}
test-leaderboard-service: install-ginkgo
@echo "Testing leaderboard service..."
@CONSISTENT_READS=1 ginkgo ${GINKGO_OPTS} --label-filter leaderboard-service ${TEST_DIRS}
test-storage-service: install-ginkgo
@echo "Testing storage service..."
@CONSISTENT_READS=1 ginkgo ${GINKGO_OPTS} --label-filter storage-service ${TEST_DIRS}
test-topics-service: install-ginkgo
@echo "Testing topics service..."
@CONSISTENT_READS=1 ginkgo ${GINKGO_OPTS} --label-filter topics-service ${TEST_DIRS}
test-http-service:
@echo "No tests for http service."
vendor:
@echo "Vendoring..."
go mod vendor
build-examples:
@echo "Building examples..."
cd examples && go build ./...
run-docs-examples:
@echo "Running docs examples..."
cd examples && go run docs-examples/main.go