-
Notifications
You must be signed in to change notification settings - Fork 53
/
Makefile
99 lines (83 loc) · 2.87 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
PINT_BIN := pint
PINT_GO_DIRS := cmd internal
PINT_SRC := $(shell find $(PINT_GO_DIRS) -type f -name '*.go')
PINT_VERSION ?= $(shell git describe --tags --always --dirty='-dev')
PINT_COMMIT ?= $(shell git rev-parse HEAD)
GOBIN := $(shell go env GOBIN)
ifeq ($(GOBIN),)
GOBIN = $(shell go env GOPATH)/bin
endif
GOFLAGS := -tags stringlabels
COVER_DIR = .cover
COVER_PROFILE = $(COVER_DIR)/coverage.out
.PHONY: build
build: $(PINT_BIN)
$(PINT_BIN): $(PINT_SRC) go.mod go.sum
CGO_ENABLED=0 go build \
$(GOFLAGS) \
-trimpath \
-ldflags='-X main.version=$(PINT_VERSION) -X main.commit=$(PINT_COMMIT) -s -w' \
./cmd/pint
$(GOBIN)/golangci-lint: tools/golangci-lint/go.mod tools/golangci-lint/go.sum
go install -modfile=tools/golangci-lint/go.mod github.com/golangci/golangci-lint/cmd/golangci-lint
.PHONY: lint
lint: $(GOBIN)/golangci-lint
$(GOBIN)/golangci-lint run
$(GOBIN)/gofumpt: tools/gofumpt/go.mod tools/gofumpt/go.sum
go install -modfile=tools/gofumpt/go.mod mvdan.cc/gofumpt
$(GOBIN)/goimports: tools/goimports/go.mod tools/goimports/go.sum
go install -modfile=tools/goimports/go.mod golang.org/x/tools/cmd/goimports
$(GOBIN)/betteralign: tools/betteralign/go.mod tools/betteralign/go.sum
go install -modfile=tools/betteralign/go.mod github.com/dkorunic/betteralign/cmd/betteralign
.PHONY: format
format: $(GOBIN)/betteralign $(GOBIN)/gofumpt $(GOBIN)/goimports
$(GOBIN)/betteralign -test_files -apply ./...
$(GOBIN)/gofumpt -extra -l -w .
$(GOBIN)/goimports -local github.com/cloudflare/pint -w .
tidy:
go mod tidy
@for f in $(wildcard tools/*/go.mod) ; do echo ">>> $$f" && cd $(CURDIR)/`dirname "$$f"` && go mod tidy && cd $(CURDIR) ; done
.PHONY: test
test:
mkdir -p $(COVER_DIR)
echo 'mode: atomic' > $(COVER_PROFILE)
go test \
$(GOFLAGS) \
-covermode=atomic \
-coverprofile=$(COVER_PROFILE) \
-coverpkg=./... \
-race \
-count=3 \
-timeout=15m \
./...
.PHONY: debug-testscript
debug-testscript:
for I in ./cmd/pint/tests/*.txt ; do T=`basename "$${I}" | cut -d. -f1`; echo ">>> $${T}" ; go test -count=1 -timeout=30s -v -run=TestScript/$${T} ./cmd/pint || exit 1 ; done
.PHONY: update-snapshots
update-snapshots:
UPDATE_SNAPS=true UPDATE_SNAPSHOTS=1 go test -count=1 ./...
$(MAKE) test
.PHONY: cover
cover: test
go tool cover -func=$(COVER_PROFILE)
.PHONY: coverhtml
coverhtml: test
go tool cover -html=$(COVER_PROFILE)
.PHONY: benchmark
benchmark:
go test \
$(GOFLAGS) \
-count=10 \
-run=none \
-bench=. \
-benchmem \
./cmd/pint
$(GOBIN)/benchstat: tools/benchstat/go.mod tools/benchstat/go.sum
go install -modfile=tools/benchstat/go.mod golang.org/x/perf/cmd/benchstat
.PHONY: benchmark-diff
benchmark-diff: $(GOBIN)/benchstat
echo "Benchmark diff:" | tee benchstat.txt
echo "" | tee -a benchstat.txt
echo '```' | tee -a benchstat.txt
$(GOBIN)/benchstat old.txt new.txt | tee -a benchstat.txt
echo '```' | tee -a benchstat.txt