forked from sourcenetwork/defradb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
474 lines (391 loc) · 13.3 KB
/
Copy pathMakefile
File metadata and controls
474 lines (391 loc) · 13.3 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# Make DefraDB!
# For compatibility, prerequisites are instead explicit calls to make.
ifndef VERBOSE
MAKEFLAGS+=--no-print-directory
endif
# Detect OS (`Linux`, `Darwin`, `Windows`)
# Note: can use `lsb_release --id --short` for more specfic linux distro information.
OS_GENERAL := Unknown
ifeq ($(OS),Windows_NT)
OS_GENERAL := Windows
else
OS_GENERAL := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
endif
# Detect OS specfic package manager if possible (`apt`, `yum`, `pacman`, `brew`, `choco`)
OS_PACKAGE_MANAGER := Unknown
ifeq ($(OS_GENERAL),Linux)
ifneq ($(shell which apt 2>/dev/null),)
OS_PACKAGE_MANAGER := apt
else ifneq ($(shell which yum 2>/dev/null),)
OS_PACKAGE_MANAGER := yum
else ifneq ($(shell which pacman 2>/dev/null),)
OS_PACKAGE_MANAGER := pacman
else ifneq ($(shell which dnf 2>/dev/null),)
OS_PACKAGE_MANAGER := dnf
endif
else ifeq ($(OS_GENERAL),Darwin)
OS_PACKAGE_MANAGER := brew
else ifeq ($(OS_GENERAL),Windows)
OS_PACKAGE_MANAGER := choco
endif
# Provide info from git to the version package using linker flags.
ifeq (, $(shell which git))
$(error "No git in $(PATH), version information won't be included")
else
VERSION_GOINFO=$(shell go version)
VERSION_GITCOMMIT=$(shell git rev-parse HEAD)
VERSION_GITCOMMITDATE=$(shell git show -s --date=short --format=%cd HEAD)
ifneq ($(shell git symbolic-ref -q --short HEAD),master)
VERSION_GITRELEASE=dev-$(shell git symbolic-ref -q --short HEAD)
else
VERSION_GITRELEASE=$(shell git describe --tags)
endif
$(info ----------------------------------------);
$(info OS = $(OS_GENERAL));
$(info PACKAGE_MANAGER = $(OS_PACKAGE_MANAGER));
$(info GOINFO = $(VERSION_GOINFO));
$(info GITCOMMIT = $(VERSION_GITCOMMIT));
$(info GITCOMMITDATE = $(VERSION_GITCOMMITDATE));
$(info GITRELEASE = $(VERSION_GITRELEASE));
$(info ----------------------------------------);
BUILD_FLAGS=-trimpath -ldflags "\
-X 'github.com/sourcenetwork/defradb/version.GoInfo=$(VERSION_GOINFO)'\
-X 'github.com/sourcenetwork/defradb/version.GitRelease=$(VERSION_GITRELEASE)'\
-X 'github.com/sourcenetwork/defradb/version.GitCommit=$(VERSION_GITCOMMIT)'\
-X 'github.com/sourcenetwork/defradb/version.GitCommitDate=$(VERSION_GITCOMMITDATE)'"
endif
ifdef BUILD_TAGS
BUILD_FLAGS+=-tags $(BUILD_TAGS)
endif
TEST_FLAGS=-race -shuffle=on -timeout 10m
JS_TEST_DIRS=./tests/integration/... ./event/... ./node/...
JS_TEST_FLAGS=-exec="$$(go env GOROOT)/lib/wasm/go_js_wasm_exec" -shuffle=on -timeout 10m
COVERAGE_DIRECTORY=$(PWD)/coverage
COVERAGE_FILE=coverage.txt
COVERAGE_FLAGS=-covermode=atomic -coverpkg=./... -args -test.gocoverdir=$(COVERAGE_DIRECTORY)
CHANGE_DETECTOR_TEST_DIRECTORY=tests/change_detector
DEFAULT_TEST_DIRECTORIES=./...
default:
@go run $(BUILD_FLAGS) cmd/defradb/main.go
.PHONY: install
install:
@go install $(BUILD_FLAGS) ./cmd/defradb
install-wizard: install
@defradb wizard
.PHONY: install\:manpages
install\:manpages:
ifeq ($(OS_GENERAL),Linux)
cp build/man/* /usr/share/man/man1/
endif
ifneq ($(OS_GENERAL),Linux)
@echo "Direct installation of Defradb's man pages is not supported on your system."
endif
# Usage:
# - make build
# - make build path="path/to/defradb-binary"
.PHONY: build
build:
ifeq ($(path),)
@go build $(BUILD_FLAGS) -o build/defradb cmd/defradb/main.go
else
@go build $(BUILD_FLAGS) -o $(path) cmd/defradb/main.go
endif
# Usage: make cross-build platforms="{platforms}"
# platforms is specified as a comma-separated list with no whitespace, e.g. "linux/amd64,linux/arm,linux/arm64"
# If none is specified, build for all platforms.
.PHONY: cross-build
cross-build:
bash tools/scripts/cross-build.sh $(platforms)
.PHONY: start
start:
@$(MAKE) build
./build/defradb start
.PHONY: client\:dump
client\:dump:
./build/defradb client dump
.PHONY: client\:collection-add
client\:collection-add:
./build/defradb client collection add -f examples/collection/bookauthpub.graphql
.PHONY: deps\:lint-go
deps\:lint-go:
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.3
.PHONY: deps\:lint-yaml
deps\:lint-yaml:
ifeq (, $(shell which yamllint))
$(info YAML linter 'yamllint' not found on the system, please install it.)
$(info Can try using your local package manager: $(OS_PACKAGE_MANAGER))
else
$(info YAML linter 'yamllint' already installed.)
endif
.PHONY: deps\:vulncheck
deps\:vulncheck:
go install golang.org/x/vuln/cmd/govulncheck@latest
.PHONY: deps\:lint
deps\:lint:
@$(MAKE) deps:lint-go && \
$(MAKE) deps:lint-yaml
.PHONY: deps\:test
deps\:test:
go install gotest.tools/gotestsum@latest
rustup target add wasm32-unknown-unknown
@$(MAKE) -C ./tests/lenses build
.PHONY: deps\:test\:js
deps\:test\:js:
npm install graphql-introspection-json-to-sdl --prefix tests
.PHONY: deps\:bench
deps\:bench:
go install golang.org/x/perf/cmd/benchstat@latest
.PHONY: deps\:chglog
deps\:chglog:
go install github.com/git-chglog/git-chglog/cmd/git-chglog@latest
.PHONY: deps\:modules
deps\:modules:
go mod download
.PHONY: deps\:mocks
deps\:mocks:
go install github.com/vektra/mockery/v3@v3.5.2
.PHONY: deps\:playground
deps\:playground:
go generate -tags playground ./playground/...
.PHONY: deps\:ollama
deps\:ollama:
ifeq ($(OS_GENERAL),Linux)
curl -fsSL https://ollama.com/install.sh | sh
else ifeq ($(OS_GENERAL),Darwin)
brew install ollama
else
@echo "Makefile installation of Ollama is not supported for your system. Please install manually."
endif
.PHONY: deps
deps:
@$(MAKE) deps:modules && \
$(MAKE) deps:bench && \
$(MAKE) deps:chglog && \
$(MAKE) deps:lint && \
$(MAKE) deps:vulncheck && \
$(MAKE) deps:test && \
$(MAKE) deps:mocks
.PHONY: mocks
mocks:
@$(MAKE) deps:mocks && \
find . -type d -name "mocks" -exec rm -r {} + && \
mockery --config="tools/configs/mockery.yaml"
.PHONY: ollama
ollama:
# run ollama in the background
nohup ollama serve > ollama.log 2>&1 &
.PHONY: ollama\:nomic
ollama\:nomic:
# make sure ollama is running before continuing
time curl --retry 5 --retry-connrefused --retry-delay 0 -sf http://localhost:11434
tools/scripts/ollama-pull.sh nomic-embed-text
.PHONY: dev\:start
dev\:start:
@$(MAKE) build
DEFRA_ENV=dev ./build/defradb start
# Note: In some situations `verify` can modify `go.sum` file, but until a
# read-only version is available we have to rely on this.
# Here are some relevant issues:
# - https://github.com/golang/go/issues/31372
# - https://github.com/cosmos/cosmos-sdk/issues/4165
.PHONY: verify
verify:
@if go mod verify | grep -q 'all modules verified'; then \
echo "Success!"; \
else \
echo "Failure:"; \
go mod verify; \
exit 2; \
fi;
.PHONY: tidy
tidy:
go mod tidy
.PHONY: clean
clean:
go clean cmd/defradb/main.go
rm -f build/defradb
.PHONY: clean\:test
clean\:test:
go clean -testcache
.PHONY: clean\:coverage
clean\:coverage:
rm -rf $(COVERAGE_DIRECTORY)
rm -f $(COVERAGE_FILE)
# Example: `make tls-certs path="~/.defradb/certs"`
.PHONY: tls-certs
tls-certs:
ifeq ($(path),)
openssl ecparam -genkey -name secp384r1 -out server.key
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 365
else
mkdir -p $(path)
openssl ecparam -genkey -name secp384r1 -out $(path)/server.key
openssl req -new -x509 -sha256 -key $(path)/server.key -out $(path)/server.crt -days 365
endif
.PHONY: test
test:
gotestsum --format pkgname -- $(DEFAULT_TEST_DIRECTORIES) $(TEST_FLAGS)
.PHONY: test\:quick
test\:quick:
gotestsum --format pkgname -- $(DEFAULT_TEST_DIRECTORIES)
# Only build the tests (don't execute them).
.PHONY: test\:build
test\:build:
gotestsum --format pkgname -- $(DEFAULT_TEST_DIRECTORIES) $(TEST_FLAGS) -run=nope
.PHONY: test\:gql-mutations
test\:gql-mutations:
DEFRA_MUTATION_TYPE=gql DEFRA_BADGER_MEMORY=true gotestsum --format pkgname -- $(DEFAULT_TEST_DIRECTORIES)
# This action and the test:col-named-mutations (below) runs the test suite with any supporting mutation test
# actions running their mutations via their corresponding named [Collection] call.
#
# For example, CreateDoc will call [Collection.Create], and
# UpdateDoc will call [Collection.Update].
.PHONY: test\:col-named-mutations
test\:col-named-mutations:
DEFRA_MUTATION_TYPE=collection-named DEFRA_BADGER_MEMORY=true gotestsum --format pkgname -- $(DEFAULT_TEST_DIRECTORIES)
.PHONY: test\:source-hub
test\:source-hub:
DEFRA_DOCUMENT_ACP_TYPE=source-hub gotestsum --format pkgname -- $(DEFAULT_TEST_DIRECTORIES)
.PHONY: test\:go
test\:go:
go test $(DEFAULT_TEST_DIRECTORIES) $(TEST_FLAGS)
.PHONY: test\:http
test\:http:
DEFRA_CLIENT_HTTP=true go test $(DEFAULT_TEST_DIRECTORIES) $(TEST_FLAGS)
.PHONY: test\:cli
test\:cli:
DEFRA_CLIENT_CLI=true go test $(DEFAULT_TEST_DIRECTORIES) $(TEST_FLAGS)
.PHONY: test\:c
test\:c:
DEFRA_CLIENT_C=true go test $(DEFAULT_TEST_DIRECTORIES) $(TEST_FLAGS)
.PHONY: test\:names
test\:names:
gotestsum --format testname -- $(DEFAULT_TEST_DIRECTORIES) $(TEST_FLAGS)
.PHONY: test\:verbose
test\:verbose:
gotestsum --format standard-verbose -- $(DEFAULT_TEST_DIRECTORIES) $(TEST_FLAGS)
.PHONY: test\:watch
test\:watch:
gotestsum --watch -- $(DEFAULT_TEST_DIRECTORIES)
.PHONY: test\:clean
test\:clean:
@$(MAKE) clean:test && $(MAKE) test
.PHONY: test\:bench
test\:bench:
@$(MAKE) -C ./tests/bench/ bench
.PHONY: test\:bench-short
test\:bench-short:
@$(MAKE) -C ./tests/bench/ bench:short
.PHONY: test\:scripts
test\:scripts:
@$(MAKE) -C ./tools/scripts/ test
.PHONY: test\:coverage
test\:coverage:
@$(MAKE) clean:coverage
mkdir $(COVERAGE_DIRECTORY)
ifeq ($(path),)
gotestsum --format pkgname-and-test-fails -- ./... $(TEST_FLAGS) $(COVERAGE_FLAGS)
else
gotestsum --format pkgname-and-test-fails -- $(path) $(TEST_FLAGS) $(COVERAGE_FLAGS)
endif
go tool covdata textfmt -i=$(COVERAGE_DIRECTORY) -o $(COVERAGE_FILE)
.PHONY: test\:coverage-func
test\:coverage-func:
@$(MAKE) test:coverage
go tool cover -func=$(COVERAGE_FILE)
.PHONY: test\:coverage-html
test\:coverage-html:
@$(MAKE) test:coverage path=$(path)
go tool cover -html=$(COVERAGE_FILE)
@$(MAKE) clean:coverage
.PHONY: test\:coverage-js
test\:coverage-js:
@$(MAKE) clean:coverage
mkdir $(COVERAGE_DIRECTORY)
GOOS=js GOARCH=wasm gotestsum --format pkgname -- $(JS_TEST_DIRS) $(JS_TEST_FLAGS) $(COVERAGE_FLAGS)
go tool covdata textfmt -i=$(COVERAGE_DIRECTORY) -o $(COVERAGE_FILE)
.PHONY: test\:changes
test\:changes:
gotestsum --format testname -- ./$(CHANGE_DETECTOR_TEST_DIRECTORY)/... -timeout 20m --tags change_detector
.PHONY: test\:js
test\:js:
GOOS=js GOARCH=wasm gotestsum --format testname -- $(JS_TEST_DIRS) $(JS_TEST_FLAGS)
# This test scans all the test files to find ones that include the npx build tag
# then runs only those tests and their respective packages
# Note: simply include `-tags npx` isnt sufficient since go test still includes
# all the other tests and packages that arent tagged.
.PHONY: test\:npx
test\:npx:
@npx_files=$$(grep -rl --include='*_test.go' -E '^//go:build.*\bnpx\b|^// \+build.*\bnpx\b' .); \
if [ -z "$$npx_files" ]; then \
echo "No npx-tagged tests found"; \
exit 0; \
fi; \
packages=$$(echo "$$npx_files" | xargs -n1 dirname | sort -u | sed 's|^\./||' | sed 's|^|./|'); \
test_pattern=$$(echo "$$npx_files" | xargs grep -h -E '^func (Test[A-Za-z0-9_]+)' | sed -E 's/^func (Test[A-Za-z0-9_]+).*/\1/' | paste -sd '|' -); \
echo "$$packages" | xargs gotestsum --format pkgname -- -tags=npx -run "^($$test_pattern)$$"
.PHONY: validate\:codecov
validate\:codecov:
curl --data-binary @.github/codecov.yml https://codecov.io/validate
.PHONY: validate\:circleci
validate\:circleci:
circleci config validate
.PHONY: lint
lint:
golangci-lint config verify --config=tools/configs/golangci.yaml
golangci-lint run --config=tools/configs/golangci.yaml
yamllint -c tools/configs/yamllint.yaml .
.PHONY: lint\:fix
lint\:fix:
golangci-lint run --config=tools/configs/golangci.yaml --fix
.PHONY: lint\:todo
lint\:todo:
rg "nolint" -g '!{Makefile}'
.PHONY: lint\:list
lint\:list:
golangci-lint linters --config=tools/configs/golangci.yaml
.PHONY: chglog
chglog:
git-chglog -c "tools/configs/chglog/config.yml" --next-tag v0.x.0 -o CHANGELOG.md
.PHONY: docs
docs:
@$(MAKE) docs\:cli
@$(MAKE) docs\:manpages
@$(MAKE) docs\:http
@$(MAKE) toc
.PHONY: docs\:cli
docs\:cli:
rm -f docs/website/references/cli/*.md
go run cmd/genclidocs/main.go -o docs/website/references/cli
.PHONY: docs\:http
docs\:http:
go run cmd/genopenapi/main.go | python -m json.tool > docs/website/references/http/openapi.json
.PHONY: docs\:manpages
docs\:manpages:
go run cmd/genmanpages/main.go -o build/man/
.PHONY: docs\:godoc
docs\:godoc:
godoc -http=:6060
# open http://localhost:6060/pkg/github.com/sourcenetwork/defradb/
.PHONY: toc
toc:
bash tools/scripts/md-toc/gh-md-toc --insert --no-backup --hide-footer --skip-header README.md
.PHONY: fix
fix:
@$(MAKE) deps
@$(MAKE) lint\:fix
@$(MAKE) tidy
@$(MAKE) mocks
@$(MAKE) docs
.PHONY build-c-shared-linux:
build-c-shared-linux:
@tools/scripts/build-c-shared-linux.sh $(BUILD_FLAGS)
# Usage: API_LEVEL will be the Android SDK.API level targeted by the build.
# For more information, see: https://apilevels.com/
# The minimum supported API level is 21, which is the default.
#
# ANDROID_NDK should be the path to the installed Android NDK on your system
API_LEVEL ?= 21
.PHONY: build-c-shared-android
build-c-shared-android:
@tools/scripts/build-c-shared-android.sh $(ANDROID_NDK) $(API_LEVEL) "$(BUILD_FLAGS)"