-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMakefile
More file actions
270 lines (238 loc) · 9.96 KB
/
Makefile
File metadata and controls
270 lines (238 loc) · 9.96 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
SHELL := /bin/bash
OS := $(shell uname -s | awk '{print tolower($$0)}')
ARCH := $(shell uname -m)
GO_VERSION := 1.22.4
GOFMT_VERSION := latest-0.3
GOIMPORTS_VERSION := v0.22.0
PRE_COMMIT_VERSION := 3.7.0
PRETTIER_VERSION := 3.2.5
REVIVE_VERSION := v1.3.7
SHFMT_VERSION := v3.8.0
JUNIT_VERSION := 2.1.0
STATICCHECK_VERSION := 2025.1
OUT_DIR := grpc
TEST_DIR := $(shell realpath .)
TEST_NUM_MODULE_BUILDS := 1
TEST_NUM_PARALLEL := 20
AHNLICH_DIR := $(shell realpath ../../ahnlich)
PROTOS_DIR := $(shell realpath ../../protos)
.PHONY: all \
install-go-junit install-go-test-sum install-gofmt install-goimports \
install-pre-commit install-prettier install-revive update-shell-config \
install-shfmt install-staticcheck install-dependencies \
format-check format lint-check pre-commit-check \
generate \
test-sequential test-race test-coverage test
all: install-dependencies
install-go-junit:
@mkdir -p /tmp/temp && rm -rf /tmp/temp/*
ifeq ($(CI),1)
@export PATH=$$PATH:/usr/local/go/bin:$(shell go env GOPATH)/bin; \
go install github.com/jstemmer/go-junit-report@v1
else
@ARC=$(ARCH); \
if [ "$$ARC" = "x86_64" ]; then ARC=amd64; \
elif [ "$$ARC" = "aarch64" ]; then ARC=arm64; fi; \
wget -nv https://github.com/jstemmer/go-junit-report/releases/download/v$(JUNIT_VERSION)/go-junit-report-v$(JUNIT_VERSION)-$(OS)-$$ARC.tar.gz -P /tmp/temp; \
tar -xzvf /tmp/temp/go-junit-report-v$(JUNIT_VERSION)-$(OS)-$$ARC.tar.gz -C /tmp/temp; \
mv -v /tmp/temp/go-junit-report $$(go env GOPATH)/bin
endif
install-go-test-sum:
@mkdir -p /tmp/temp && rm -rf /tmp/temp/*
@export PATH=$$PATH:/usr/local/go/bin:$(shell go env GOPATH)/bin; \
go install gotest.tools/gotestsum@latest
install-gofmt:
docker pull cytopia/gofmt:$(GOFMT_VERSION)
install-goimports:
ifeq ($(CI),1)
@export PATH=$$PATH:/usr/local/go/bin; \
GOBIN=/usr/local/bin go install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)
else
@GOBIN=$$HOME/.local/bin go install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)
endif
install-pre-commit:
python3 -m pip install pre-commit==$(PRE_COMMIT_VERSION)
pre-commit install --hook-type commit-msg --allow-missing-config
install-prettier:
docker pull tmknom/prettier:$(PRETTIER_VERSION)
install-revive:
@mkdir -p /tmp/temp && rm -rf /tmp/temp/*
ifeq ($(CI),1)
@export PATH=$$PATH:/usr/local/go/bin:$(shell go env GOPATH)/bin; \
wget -nv https://github.com/mgechev/revive/releases/download/$(REVIVE_VERSION)/revive_linux_amd64.tar.gz -P /tmp/temp; \
tar -xzvf /tmp/temp/revive_linux_amd64.tar.gz -C /tmp/temp; \
mv -v /tmp/temp/revive $$(go env GOPATH)/bin
else
@wget -q https://github.com/mgechev/revive/releases/download/$(REVIVE_VERSION)/revive_$(OS)_amd64.tar.gz -P /tmp/temp && \
tar -xzvf /tmp/temp/revive_$(OS)_amd64.tar.gz -C /tmp/temp && \
mv -v /tmp/temp/revive $$(go env GOPATH)/bin || \
(echo "No prebuilt for $(OS)/amd64; installing from source" && \
go install github.com/mgechev/revive@$(REVIVE_VERSION))
endif
update-shell-config:
@if [ -f ~/.zshrc ]; then \
grep -qx 'PATH=$$PATH:~/.local/bin' ~/.zshrc || echo 'PATH=$$PATH:~/.local/bin' >> ~/.zshrc; \
echo "Reload zsh: source ~/.zshrc"; \
fi
@if [ -f ~/.bashrc ]; then \
grep -qx 'PATH=$$PATH:~/.local/bin' ~/.bashrc || echo 'PATH=$$PATH:~/.local/bin' >> ~/.bashrc; \
echo "Reload bash: source ~/.bashrc"; \
fi
install-shfmt:
@mkdir -p /tmp/temp && rm -rf /tmp/temp/*
ifeq ($(CI),1)
@wget -nv -O /tmp/temp/shfmt https://github.com/mvdan/sh/releases/download/$(SHFMT_VERSION)/shfmt_$(SHFMT_VERSION)_linux_amd64; \
chmod +x /tmp/temp/shfmt; \
mv -v /tmp/temp/shfmt /usr/local/bin
else
@wget -q -O /tmp/temp/shfmt https://github.com/mvdan/sh/releases/download/$(SHFMT_VERSION)/shfmt_$(SHFMT_VERSION)_$(OS)_amd64 && \
chmod +x /tmp/temp/shfmt && \
mv -v /tmp/temp/shfmt $$HOME/.local/bin || \
(echo "No prebuilt for $(OS)/amd64; installing from source" && \
GOBIN=$$HOME/.local/bin go install mvdan.cc/sh/v3/cmd/gosh@$(SHFMT_VERSION))
endif
$(MAKE) update-shell-config
install-staticcheck:
@mkdir -p /tmp/temp && rm -rf /tmp/temp/*
ifeq ($(CI),1)
@wget -nv https://github.com/dominikh/go-tools/releases/download/$(STATICCHECK_VERSION)/staticcheck_linux_amd64.tar.gz -P /tmp/temp; \
tar -xzvf /tmp/temp/staticcheck_linux_amd64.tar.gz -C /tmp/temp; \
mv -v /tmp/temp/staticcheck/staticcheck $$(go env GOPATH)/bin; \
rm -rf /tmp/temp/staticcheck
else
@wget -q https://github.com/dominikh/go-tools/releases/download/$(STATICCHECK_VERSION)/staticcheck_$(OS)_amd64.tar.gz -P /tmp/temp && \
tar -xzvf /tmp/temp/staticcheck_$(OS)_amd64.tar.gz -C /tmp/temp && \
mv -v /tmp/temp/staticcheck/staticcheck $$HOME/.local/go/bin && \
rm -rf /tmp/temp/staticcheck || \
(echo "No prebuilt for $(OS)/amd64; installing from source" && \
GOBIN=$$HOME/.local/go/bin go install honnef.co/go/tools/cmd/staticcheck@$(STATICCHECK_VERSION))
endif
install-dependencies: install-go-junit \
install-gofmt \
install-goimports \
install-pre-commit \
install-prettier \
install-revive \
install-shfmt \
install-staticcheck \
install-go-test-sum
format-check:
# docker run --rm -u "$$(id -u):$$(id -g)" -v "$$(pwd)":/work tmknom/prettier:$(PRETTIER_VERSION) --check "**/*.md"
# docker run --rm -u "$$(id -u):$$(id -g)" -v "$$(pwd)":/work tmknom/prettier:$(PRETTIER_VERSION) --check "**/*.yml"
# shfmt -f . | grep -v 'internal/' | grep -v 'tmp/' | xargs shfmt -i 4 -ci -d
test -z "$$(find . -type f -name '*.go' ! -path './internal/*' | xargs goimports -local github.com/deven96/ahnlich/sdk/ahnlich-client-go -l)"
test -z "$$(find . -type f -name '*.go' ! -path './internal/*' | xargs gofmt -l)"
format:
# docker run --rm -u "$$(id -u):$$(id -g)" -v "$$(pwd)":/work tmknom/prettier:$(PRETTIER_VERSION) --write "**/*.md"
# docker run --rm -u "$$(id -u):$$(id -g)" -v "$$(pwd)":/work tmknom/prettier:$(PRETTIER_VERSION) --write "**/*.yml"
# shfmt -f . | grep -v 'internal/' | grep -v 'tmp/' | xargs shfmt -i 4 -ci -w
find . -type f -name '*.go' ! -path './internal/*' | xargs goimports -local github.com/deven96/ahnlich/sdk/ahnlich-client-go -w
find . -type f -name '*.go' ! -path './internal/*' | xargs gofmt -w
lint-check:
ifeq ($(CI),1)
@export PATH=$$PATH:/usr/local/go/bin:$(shell go env GOPATH)/bin;
endif
go list $(TEST_DIR)/... | grep -v 'internal/' | xargs go vet
# go list $(TEST_DIR)/... | grep -v 'internal/' | xargs staticcheck
revive $$(find . -type f -name '*.go' -not -path './internal/*')
.PHONY: simple-lint
simple-lint:
@echo "➜ Running go vet"
@go vet ./...
@echo "➜ Running staticcheck"
# @staticcheck ./...
@echo "➜ Running revive"
@revive $(find . -type f -name '*.go' -not -path './internal/*')
pre-commit-check: format-check lint-check
generate:
@echo "➜ Generating Go protobuf code from proto definitions"
cd $(PROTOS_DIR) && buf generate
@echo "✅ Proto generation complete."
.PHONY: help-bins
help-bins:
@echo "→ ahnlich build"
pushd "$(AHNLICH_DIR)" && \
cargo build && \
echo "→ ahnlich build complete" && \
popd
@echo
test-sequential:
make help-bins
ifeq ($(CI),1)
@export PATH=$$PATH:/usr/local/go/bin:$(shell go env GOPATH)/bin;
endif
ifneq ($(CACHE),1)
ifeq ($(REPORT),1)
CGO_ENABLED=0 go test -count=1 -p $(TEST_NUM_MODULE_BUILDS) -failfast -v $$(go list $(TEST_DIR)/...) && gotestsum --junitfile go.xml
else
CGO_ENABLED=0 go test -count=1 -p $(TEST_NUM_MODULE_BUILDS) -failfast -v $$(go list $(TEST_DIR)/...)
endif
else
ifeq ($(REPORT),1)
CGO_ENABLED=0 go test -p $(TEST_NUM_MODULE_BUILDS) -failfast -v $$(go list $(TEST_DIR)/...) && gotestsum --junitfile go.xml
else
CGO_ENABLED=0 go test -p $(TEST_NUM_MODULE_BUILDS) -failfast -v $$(go list $(TEST_DIR)/...)
endif
endif
test-parallel:
make help-bins
ifeq ($(CI),1)
@export PATH=$$PATH:/usr/local/go/bin:$(shell go env GOPATH)/bin;
endif
ifneq ($(CACHE),1)
ifeq ($(REPORT),1)
CGO_ENABLED=0 go test -count=1 -parallel $(TEST_NUM_PARALLEL) -p $(TEST_NUM_MODULE_BUILDS) -failfast -v $$(go list $(TEST_DIR)/...) && gotestsum --junitfile go.xml
else
CGO_ENABLED=0 go test -count=1 -parallel $(TEST_NUM_PARALLEL) -p $(TEST_NUM_MODULE_BUILDS) -failfast -v $$(go list $(TEST_DIR)/...)
endif
else
ifeq ($(REPORT),1)
CGO_ENABLED=0 go test -p $(TEST_NUM_MODULE_BUILDS) -parallel $(TEST_NUM_PARALLEL) -failfast -v $$(go list $(TEST_DIR)/...) && gotestsum --junitfile go.xml
else
CGO_ENABLED=0 go test -p $(TEST_NUM_MODULE_BUILDS) -parallel $(TEST_NUM_PARALLEL) -failfast -v $$(go list $(TEST_DIR)/...)
endif
endif
test-race:
ifeq ($(CI),1)
@export PATH=$$PATH:/usr/local/go/bin:$(shell go env GOPATH)/bin;
endif
ifneq ($(CACHE),1)
ifeq ($(REPORT),1)
CGO_ENABLED=1 go test -race -count=1 -v $$(go list $(TEST_DIR)/...) && gotestsum --junitfile go.xml
else
CGO_ENABLED=1 go test -race -count=1 -v $$(go list $(TEST_DIR)/...)
endif
else
ifeq ($(REPORT),1)
CGO_ENABLED=1 go test -race -v $$(go list $(TEST_DIR)/...) && gotestsum --junitfile go.xml
else
CGO_ENABLED=1 go test -race -v $$(go list $(TEST_DIR)/...)
endif
endif
test-coverage:
ifeq ($(CI),1)
@export PATH=$$PATH:/usr/local/go/bin:$(shell go env GOPATH)/bin;
endif
go test $(TEST_DIR)/... -coverpkg=$(TEST_DIR)/... -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
.PHONY: simple-test
simple-test:
@echo "Running tests... Please wait."
@go test $(TEST_DIR)/... -v
@echo "✅ All tests passed successfully."
.PHONY: simple-install
simple-install:
@echo "Installing Go module dependencies..."
@go mod tidy
@go mod download
@go mod verify
@echo "✅ Go module dependencies installed."
.PHONY: clean
PB_FILES := $(shell find $(OUT_DIR) -name "*.pb.gw.go")
PBW_FILES := $(shell find $(OUT_DIR) -name "*.pb.go")
GRPC_PB_FILES := $(shell find $(OUT_DIR) -name "*.grpc.pb.go")
clean:
@echo "🧹 Cleaning generated files..."
rm -f $(PB_FILES) $(PBW_FILES) $(GRPC_PB_FILES)
@echo "✅ Clean complete."
test: test-parallel