-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
106 lines (81 loc) · 1.98 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Common makefile helpers
include build/make/common.mk
# Common configuration
SHELL := $(SHELL) -o pipefail
# Set default goal
.DEFAULT_GOAL := all
# Some constants
import-path := github.com/pamburus/slogx
# Populate complete module list, including build tools
ifndef all-modules
all-modules := $(shell go list -m -f '{{.Dir}}')
all-modules := $(subst \,/,$(all-modules))
all-modules := $(all-modules:$(abspath .)=.)
all-modules := $(all-modules:$(abspath .)/%=%)
endif
# Auxiliary modules, not to be tested
aux-modules +=
# Populate module list to test
ifndef modules
modules := $(filter-out $(aux-modules),$(all-modules))
endif
# Tools
go-test := go test
go-tool-cover := go tool cover
coverage-filter := go run github.com/pamburus/go-mod/build/tools/cmd/coverage-filter@latest
test-filter := go run github.com/pamburus/go-mod/build/tools/cmd/test-filter@latest
ifeq ($(verbose),yes)
coverage-filter += -v
go-test += -v
endif
## Run all tests
.PHONY: all
all: ci
# ---
## Run continuous integration tests
.PHONY: ci
ci: lint test
# Run continuous integration tests for a module
.PHONY: ci@/%
ci@/%: lint@/% test@/%
# ---
## Run linters
.PHONY: lint
lint: $(modules:%=lint@/%)
# Run linters for a module
.PHONY: lint@/%
lint@/%:
golangci-lint run $*/...
# ---
## Run tests
.PHONY: test
test: $(modules:%=test@/%)
# Run tests for a module
.PHONY: test@/%
test@/%:
$(go-test) -fullpath -coverprofile=$*/.cover.out ./$*/... | $(test-filter)
test@/.:
$(go-test) -fullpath -coverprofile=.cover.out ./... | $(test-filter)
# ---
## Show coverage
.PHONY: coverage
coverage: $(modules:%=coverage@/%)
# Show coverage for a module
.PHONY: coverage@/%
coverage@/%: test@/%
$(go-tool-cover) -func=$*/.cover.out | $(coverage-filter) $(import-path)
# ---
## Tidy up
.PHONY: tidy
tidy: $(all-modules:%=tidy@/%)
# go work sync
# Tidy up a module
.PHONY: tidy@/%
tidy@/%:
cd $* && go mod tidy
# ---
## Clean up
.PHONY: clean
clean:
rm -f $(modules:%=%/.cover.out)
find . -type f -name go.work.sum -delete