forked from anz-bank/sysl-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
72 lines (50 loc) · 2.42 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
# 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 check-tidy 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 && 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)
ALLTESTS = $(sort $(dir $(wildcard codegen/arrai/auto/tests/*/Makefile)))
auto-test: $(ALLTESTS)
$(foreach dir,$^,$(MAKE) -C $(dir);)
update-auto-test-go-mod: $(ALLTESTS) ## Update go.mod and go.sum files within auto tests
$(foreach dir,$^,pushd $(dir) && go mod download && go mod tidy && popd;)
clean: $(ALLTESTS)
rm -f $(COVERFILE)
@$(foreach dir,$^,$(MAKE) -C $(dir) clean;)
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