-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
94 lines (68 loc) · 3.68 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
# make
# To run all lint checks: `LINT_OPTIONS= make lint`
.PHONY: all build clean docker-build fix fmt go-lint license lint proto-generate proto-lint sdk/sdk test tidy toolcheck
MODS=protocol/go lib/ocrypto lib/fixtures lib/flattening sdk service examples
HAND_MODS=lib/ocrypto lib/fixtures lib/flattening sdk service examples
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# LINT_OPTIONS?=--new
# LINT_OPTIONS?=-new-from-rev=main
LINT_OPTIONS?=-c $(ROOT_DIR)/.golangci.yaml
all: toolcheck clean build lint license test
toolcheck:
@echo "Checking for required tools..."
@which buf > /dev/null || (echo "buf not found, please install it from https://docs.buf.build/installation" && exit 1)
@which golangci-lint > /dev/null || (echo "golangci-lint not found, run 'go install github.com/golangci/golangci-lint/cmd/[email protected]'" && exit 1)
@which protoc-gen-doc > /dev/null || (echo "protoc-gen-doc not found, run 'go install github.com/pseudomuto/protoc-gen-doc/cmd/[email protected]'" && exit 1)
@golangci-lint --version | grep "version v\?1.61" > /dev/null || (echo "golangci-lint version must be v1.61 or later [$$(golangci-lint --version)]" && exit 1)
@which goimports >/dev/null || (echo "goimports not found, run 'go install golang.org/x/tools/cmd/goimports@latest'")
fix: tidy fmt
fmt:
for m in $(HAND_MODS); do (cd $$m && find ./ -name \*.go | xargs goimports -w) || exit 1; done
tidy:
for m in $(HAND_MODS); do (cd $$m && go mod tidy) || exit 1; done
license:
for m in $(HAND_MODS); do (cd $$m && go run github.com/google/[email protected] check --disallowed_types=forbidden --include_tests ./) || exit 1; done
lint: proto-lint go-lint
proto-lint:
buf lint service || (exit_code=$$?; \
if [ $$exit_code -eq 100 ]; then \
echo "Buf lint exited with code 100, treating as success"; \
else \
echo "Buf lint exited with code $$exit_code"; \
exit $$exit_code; \
fi)
go-lint:
for m in $(HAND_MODS); do (cd $$m && golangci-lint run $(LINT_OPTIONS) --path-prefix=$$m) || exit 1; done
proto-generate:
rm -rf protocol/go/[a-fh-z]* docs/grpc docs/openapi
buf generate service
buf generate service --template buf.gen.grpc.docs.yaml
buf generate service --template buf.gen.openapi.docs.yaml
buf generate buf.build/grpc-ecosystem/grpc-gateway -o tmp-gen
buf generate buf.build/grpc-ecosystem/grpc-gateway -o tmp-gen --template buf.gen.grpc.docs.yaml
buf generate buf.build/grpc-ecosystem/grpc-gateway -o tmp-gen --template buf.gen.openapi.docs.yaml
policy-sql-gen:
@which sqlc > /dev/null || { echo "sqlc not found, please install it: https://docs.sqlc.dev/en/stable/overview/install.html"; exit 1; }
sqlc generate -f service/policy/db/sqlc.yaml
policy-erd-gen:
@which mermerd > /dev/null || { echo "mermerd not found, please install it: https://github.com/KarnerTh/mermerd#installation"; exit 1; }
# Docs: https://github.com/KarnerTh/mermerd#parametersflags
mermerd -c 'postgresql://postgres:changeme@localhost:5432/opentdf' -e -o service/policy/db/schema_erd.md -s opentdf_policy --useAllTables --showDescriptions enumValues,columnComments
test:
for m in $(HAND_MODS); do (cd $$m && go test ./... -race) || exit 1; done
fuzz:
cd sdk && go test ./... -fuzztime=2m
bench:
for m in $(HAND_MODS); do (cd $$m && go test -bench ./... -benchmem) || exit 1; done
clean:
for m in $(MODS); do (cd $$m && go clean) || exit 1; done
rm -f opentdf examples/examples
build: proto-generate opentdf sdk/sdk examples/examples
opentdf: $(shell find service)
go build -o opentdf -v service/main.go
sdk/sdk: $(shell find sdk)
(cd sdk && go build ./...)
examples/examples: $(shell find examples)
(cd examples && go build -o examples .)
docker-build: build
docker build -t opentdf .