forked from anz-bank/pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
84 lines (57 loc) · 2.66 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
all: test check-coverage lint build-examples ## test, check coverage, lint and build examples
@if [ -e .git/rebase-merge ]; then git --no-pager log -1 --pretty='%h %s'; fi
@echo '$(COLOUR_GREEN)Success$(COLOUR_NORMAL)'
clean:: ## Remove generated files
.PHONY: all clean
# -- Test --------------------------------------------------------------
COVERFILE = coverage.out
COVERAGE = 82.0
test: ## Run tests and generate a coverage file
go test -covermode=atomic -coverprofile=$(COVERFILE) -race ./...
go mod tidy
integration: ## Run integration tests which interact over the network
go test -covermode=atomic -tags integration -race ./...
bench: ## Run benchmarks only
go test -run=NONE -bench=. ./...
check-coverage: test ## Check that test coverage meets the required level
@go tool cover -func=$(COVERFILE) | $(CHECK_COVERAGE) || $(FAIL_COVERAGE)
cover: test ## Show test coverage in your browser
go tool cover -html=$(COVERFILE)
clean::
rm -f $(COVERFILE)
CHECK_COVERAGE = awk -F '[ \t%]+' '/^total:/ {print; if ($$3 < $(COVERAGE)) exit 1}'
FAIL_COVERAGE = { echo '$(COLOUR_RED)FAIL - Coverage below $(COVERAGE)%$(COLOUR_NORMAL)'; exit 1; }
.PHONY: test check-coverage cover
# -- Lint --------------------------------------------------------------
GOLINT_VERSION = 1.24.0
GOLINT_INSTALLED_VERSION = $(or $(word 4,$(shell golangci-lint --version 2>/dev/null)),0.0.0)
GOLINT_MIN_VERSION = $(shell printf '%s\n' $(GOLINT_VERSION) $(GOLINT_INSTALLED_VERSION) | sort -V | head -n 1)
lint: ## Lint source code
ifeq ($(GOLINT_MIN_VERSION), $(GOLINT_VERSION))
golangci-lint run
else
lint: lint-with-docker
endif
lint-with-docker:
docker run --rm -v $(PWD):/src -w /src golangci/golangci-lint:v$(GOLINT_VERSION) golangci-lint run
.PHONY: lint
# -- Build examples ----------------------------------------------------
# The `_examples` directory by starting with `_` is ignored by the Go
# tools. We want to ignore it so we don't create empty godocs for it,
# but we also want to ensure that it still builds so add the special
# target `build-examples`:
build-examples:
go build -o log-examples ./log/_examples
.PHONY: build-examples
# -- Generate ----------------------------------------------------------
generate:
go generate ./...
.PHONY: generate
# -- 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)
help:
@awk -F ':.*## ' 'NF == 2 && $$1 ~ /^[A-Za-z0-9_-]+$$/ { printf "$(COLOUR_WHITE)%-30s$(COLOUR_NORMAL)%s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
.PHONY: help