-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
59 lines (49 loc) · 1.67 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
LINTER_VERSION=v1.57.1
LINTER=./bin/golangci-lint
ifeq ($(OS),Windows_NT)
LINTER=./bin/golangci-lint.exe
endif
pkgs=$(shell go list ./... | grep -v /cmd/)
.PHONY: all
all: clean setup lint test ## Run sequentially clean, setup, lint and test.
.PHONY: lint
lint: ## Run linter and detect go mod tidy changes.
$(LINTER) run -c ./.golangci-lint.yml --fix
@make tidy
@if ! git diff --quiet; then \
echo "'go mod tidy' resulted in changes or working tree is dirty:"; \
git --no-pager diff; \
fi
.PHONY: setup
setup: ## Download dependencies.
go mod download
@if [ ! -f "$(LINTER)" ]; then \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(LINTER_VERSION); \
fi
.PHONY: test
test: ## Run tests (with race condition detection).
go test -race -timeout=10m $(pkgs)
.PHONY: bench
bench: ## Run benchmarks.
go test -race -timeout=15m -benchmem -benchtime=2x -bench .
.PHONY: cover
cover: ## Run tests with coverage. Generates "cover.out" profile and its html representation.
go test -race -timeout=10m -coverprofile=cover.out -coverpkg=./... $(pkgs)
go tool cover -html=cover.out -o cover.html
.PHONY: tidy
tidy: ## Simply runs 'go mod tidy'.
go mod tidy
.PHONY: clean
clean: ## Clean up go tests cache and coverage generated files.
go clean -testcache
@for file in cover.html cover.out; do \
if [ -f $$file ]; then \
echo "rm -f $$file"; \
rm -f $$file; \
fi \
done
.PHONY: help
# Absolutely awesome: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help