-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
65 lines (51 loc) · 1.86 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
PACKAGE = $(notdir $(patsubst %/,%,$(dir $(realpath $(lastword $(MAKEFILE_LIST))))))
OUT_DIR ?= build
RESULTS_DIR ?= results
DOCKER_REGISTRY ?= local
DOCKER_TAG ?= latest
LINT_BIN := ./bin/golangci-lint
SHELL=/bin/bash
.SHELLFLAGS=-c -eo pipefail
#######################################
## Local set up.
#######################################
.PHONY: init deps deps-upgrade fmt test lint lint-shell gen
init:
git config core.hooksPath .githooks
go install golang.org/x/tools/cmd/goimports
go install github.com/maxbrunsfeld/counterfeiter/v6
go install github.com/jstemmer/go-junit-report
deps:
go mod download
go mod tidy
go mod verify
deps-upgrade:
GOFLAGS="" go get -u ./...
$(MAKE) deps
#######################################
## Tests, codegen, lint and format.
#######################################
fmt:
$(info Running goimports...)
@goimports -w -e $$(find . -type f -name '*.go')
test:
$(info Running unit tests...)
mkdir -p $(RESULTS_DIR)
CGO_ENABLED=1 go test -race -v -cover ./... -coverprofile=$(RESULTS_DIR)/$(PACKAGE)-coverage.out 2>&1 | tee >(go-junit-report > $(RESULTS_DIR)/report.xml)
@echo "Total code coverage:"
@go tool cover -func=$(RESULTS_DIR)/$(PACKAGE)-coverage.out | grep 'total:' | tee $(RESULTS_DIR)/anybadge.out
@go tool cover -html=$(RESULTS_DIR)/$(PACKAGE)-coverage.out -o $(RESULTS_DIR)/coverage.html
test-only-failed:
$(info Running unit tests (showing only failed ones with context)...)
go test -v -race ./... | grep --color -B 45 -A 5 -E '^FAIL.+'
$(LINT_BIN):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.51.2
lint: $(LINT_BIN)
$(LINT_BIN) run
lint-docker:
docker run --rm -v "${PWD}":/app -w /app golangci/golangci-lint:v1.51.2 golangci-lint run
lint-shell:
shellcheck -x $$(find . -name "*.sh" -type f)
gen:
go generate -x ./...
$(MAKE) fmt