-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
86 lines (65 loc) · 1.83 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
SHELL = /bin/bash
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# Setting GOBIN and PATH ensures two things:
# - All 'go install' commands we run
# only affect the current directory.
# - All installed tools are available on PATH
# for commands like go generate.
export GOBIN = $(PROJECT_ROOT)/bin
export PATH := $(GOBIN):$(PATH)
TEST_FLAGS ?=
GS = bin/gs
MOCKGEN = bin/mockgen
REQUIREDFIELD = bin/requiredfield
GOTESTSUM = bin/gotestsum
TOOLS = $(MOCKGEN) $(GS) $(GOTESTSUM)
GOTESTSUM_FORMAT ?= pkgname
.PHONY: all
all: build lint test
.PHONY: build
build: $(GS)
.PHONY: lint
lint: golangci-lint requiredfield-lint tidy-lint generate-lint
.PHONY: generate
generate: $(TOOLS)
go generate -x ./...
make -C doc generate
.PHONY: test
test: $(GOTESTSUM)
$(GOTESTSUM) --format=$(GOTESTSUM_FORMAT) -- $(TEST_FLAGS) ./...
.PHONY: cover
cover: $(GOTESTSUM)
$(GOTESTSUM) --format=$(GOTESTSUM_FORMAT) -- $(TEST_FLAGS) -coverprofile=cover.out -coverpkg=./... ./...
go tool cover -html=cover.out -o cover.html
.PHONY: tidy
tidy:
go mod tidy
.PHONY: golangci-lint
golangci-lint:
golangci-lint run
.PHONY: requiredfield-lint
requiredfield-lint: $(REQUIREDFIELD)
@echo "[lint] requiredfield"
@go vet -vettool=$(REQUIREDFIELD) ./...
.PHONY: tidy-lint
tidy-lint:
@echo "[lint] go mod tidy"
@go mod tidy && \
git diff --exit-code -- go.mod go.sum || \
(echo "'go mod tidy' changed files" && false)
.PHONY: generate-lint
generate-lint: $(TOOLS)
@echo "[lint] go generate"
@go generate ./... && \
git diff --exit-code || \
(echo "'go generate' changed files" && false)
$(GS): _always
go install go.abhg.dev/gs
.PHONY: _always
_always:
$(MOCKGEN): go.mod
go install go.uber.org/mock/mockgen
$(REQUIREDFIELD): go.mod
go install go.abhg.dev/requiredfield/cmd/requiredfield
$(GOTESTSUM): go.mod
go install gotest.tools/gotestsum