-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMakefile
95 lines (68 loc) · 2.99 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
# Requires protoc, protoc-gen-go and goimports.
# Hack: globally force any shell commands to run inside
# a bash shell with saner defaults set. If this is not done
# then multi-statement shell recipes such as run-arrai can
# fail in a way that is not noticed by make.
SHELL=/bin/bash -o pipefail -o errexit
all: test-arrai test check-coverage lint auto-test ## Tests, lints and checks coverage
.PHONY: all clean
# -- Lint ----------------------------------------------------------------------
lint: ## Lint Go Source Code
golangci-lint run
check-tidy: ## Check go.mod and go.sum is tidy
go mod tidy && git diff --exit-code HEAD -- ":(top)go.mod" ":(top)go.sum"
.PHONY: lint check-tidy
# -- Test (arrai) --------------------------------------------------------------
test-arrai:
arrai test
.PHONY: test-arrai
# -- Test (go) --------------------------------------------------------------------
COVERFILE=coverage.out
COVERAGE = 50
test: ## Run all tests, apart from auto-test
go test -coverprofile=$(COVERFILE) -tags codeanalysis ./...
check-coverage: test ## Check that test coverage meets the required level
@go tool cover -func=$(COVERFILE) | $(CHECK_COVERAGE) || $(FAIL_COVERAGE)
coverage: test ## Show test coverage in your browser
go tool cover -html=$(COVERFILE)
ALL_TESTS = $(sort $(dir $(wildcard codegen/arrai/auto/tests/*/Makefile)))
auto-test: $(patsubst %,auto-test-%.dummy,$(ALL_TESTS))
auto-test-%/.dummy:
$(MAKE) -C $*
update-auto-test-go-mod: $(patsubst %,go-mod-%.dummy,$(ALL_TESTS)) ## Update go.mod and go.sum files within auto tests
go-mod-%/.dummy:
cd $* && go mod download && go mod tidy
clean: $(patsubst %,clean-%.dummy,$(ALL_TESTS))
rm -f $(COVERFILE)
clean-%/.dummy:
$(MAKE) -C $* clean
ALL_GRPC_TESTS = $(sort $(dir $(wildcard codegen/arrai/auto/tests/*grpc*/Makefile)))
update-auto-test-proto-pb: $(patsubst %,proto-pb-%.dummy,$(ALL_GRPC_TESTS)) ## Update protos within auto tests
proto-pb-%/.dummy:
$(MAKE) -C $* -B protos
CHECK_COVERAGE = awk -F '[ \t%]+' '/^total:/ && $$3 < $(COVERAGE) {exit 1}'
FAIL_COVERAGE = { echo '$(COLOUR_RED)FAIL - Coverage below $(COVERAGE)%$(COLOUR_NORMAL)'; exit 1; }
.PHONY: check-coverage coverage test auto-test
# --- Utilities ---------------------------------------------------------------
COLOUR_NORMAL = $(shell tput sgr0 2>/dev/null)
COLOUR_RED = $(shell tput setaf 1 2>/dev/null)
COLOUR_GREEN = $(shell tput setaf 2 2>/dev/null)
COLOUR_WHITE = $(shell tput setaf 7 2>/dev/null)
BOLD = $(shell tput bold 2>/dev/null)
help:
@awk -F ':.*## ' 'NF == 2 && $$1 ~ /^[A-Za-z0-9_-]+$$/ { printf "$(BOLD)$(COLOUR_WHITE)%-20s$(COLOUR_NORMAL)%s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
.PHONY: help
docker:
docker build . -t sysl-go
.PHONY: docker
protos: core/testdata/proto/test.pb.go
.PHONY: protos
%.pb.go: %.proto
protoc \
--go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
$^
go-work:
if [ ! -f go.work ]; then go work init; fi
find . -name go.mod -execdir go work use . \;
.PHONY: go-work