-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
112 lines (88 loc) · 2.89 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
107
108
109
110
111
112
SHELL = /bin/bash
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
GO_MODULES ?= $(shell find . \
-path '*/.*' -prune -o \
-type f -a -name 'go.mod' -exec dirname '{}' ';')
# ./docs doesn't have any meaningful Go code.
GO_MODULES := $(filter-out ./docs, $(GO_MODULES))
# 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)
ERRTRACE = $(GOBIN)/errtrace
PAGEFIND = $(PROJECT_ROOT)/integration/node_modules/.bin/pagefind
TEST_FLAGS ?= -race
# Non-test Go files.
GO_SRC_FILES = $(shell find . \
-path '*/.*' -prune -o \
'(' -type f -a -name '*.go' -a -not -name '*_test.go' ')' -print)
DOC2GO = bin/doc2go
.PHONY: all
all: build lint test
.PHONY: build
build: $(DOC2GO)
$(DOC2GO): $(GO_SRC_FILES) $(wildcard ./internal/html/tmpl/*)
go install go.abhg.dev/doc2go
.PHONY: lint
lint: golangci-lint tidy-lint errtrace-lint
.PHONY: test
test:
go test $(TEST_FLAGS) ./...
.PHONY: test-integration
test-integration: $(DOC2GO) $(PAGEFIND)
go test -C integration $(TEST_FLAGS) \
-doc2go $(shell pwd)/$(DOC2GO) \
-pagefind $(PAGEFIND) \
-rundir $(PROJECT_ROOT)
.PHONY: cover
cover:
go test $(TEST_FLAGS) -coverprofile=cover.out -coverpkg=./... ./...
go tool cover -html=cover.out -o cover.html
.PHONY: cover-integration
cover-integration: export GOEXPERIMENT = coverageredesign
cover-integration: $(PAGEFIND)
$(eval BIN := $(shell mktemp -d))
$(eval COVERDIR := $(shell mktemp -d))
GOBIN=$(BIN) \
go install -race -cover -coverpkg=./... go.abhg.dev/doc2go
GOCOVERDIR=$(COVERDIR) PATH=$(BIN):$$PATH \
go test -C integration $(TEST_FLAGS) \
-doc2go $(BIN)/doc2go \
-pagefind $(PAGEFIND) \
-rundir $(PROJECT_ROOT)
go tool covdata textfmt -i=$(COVERDIR) -o=cover.integration.out
go tool cover -html=cover.integration.out -o cover.integration.html
.PHONY: tidy
tidy:
$(foreach mod,$(GO_MODULES),(cd $(mod) && go mod tidy) &&) true
.PHONY: errtrace
errtrace: $(ERRTRACE)
$(ERRTRACE) -w ./...
.PHONY: golangci-lint
golangci-lint:
$(foreach mod,$(GO_MODULES), \
(cd $(mod) && golangci-lint run --path-prefix $(mod)) &&) true
.PHONY: tidy-lint
tidy-lint:
$(foreach mod,$(GO_MODULES), \
(cd $(mod) && go mod tidy && \
git diff --exit-code -- go.mod go.sum || \
(echo "[$(mod)] go mod tidy changed files" && false)) &&) true
.PHONY: errtrace-lint
errtrace-lint: $(ERRTRACE)
$(eval LOG := $(shell mktemp))
@$(foreach mod,$(GO_MODULES), \
(cd $(mod) && \
$(ERRTRACE) -l ./... | sed -e 's|^|$(mod)/|' >> "$(LOG)") &&) true
@if [ -s $(LOG) ]; then \
echo "errtrace found errors:"; \
cat $(LOG); \
false; \
fi
$(ERRTRACE): go.mod
go install braces.dev/errtrace/cmd/errtrace
$(PAGEFIND): integration/package-lock.json integration/package.json
cd integration && npm install