cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.63.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Makefile

99lines · modecode

1PINT_BIN := pint
2PINT_GO_DIRS := cmd internal
3PINT_SRC := $(shell find $(PINT_GO_DIRS) -type f -name '*.go')
4PINT_VERSION ?= $(shell git describe --tags --always --dirty='-dev')
5PINT_COMMIT ?= $(shell git rev-parse HEAD)
6
7GOBIN := $(shell go env GOBIN)
8ifeq ($(GOBIN),)
9GOBIN = $(shell go env GOPATH)/bin
10endif
11
12GOFLAGS := -tags stringlabels
13
14COVER_DIR = .cover
15COVER_PROFILE = $(COVER_DIR)/coverage.out
16
17.PHONY: build
18build: $(PINT_BIN)
19
20$(PINT_BIN): $(PINT_SRC) go.mod go.sum
21 CGO_ENABLED=0 go build \
22 $(GOFLAGS) \
23 -trimpath \
24 -ldflags='-X main.version=$(PINT_VERSION) -X main.commit=$(PINT_COMMIT) -s -w' \
25 ./cmd/pint
26
27$(GOBIN)/golangci-lint: tools/golangci-lint/go.mod tools/golangci-lint/go.sum
28 go install -modfile=tools/golangci-lint/go.mod github.com/golangci/golangci-lint/cmd/golangci-lint
29.PHONY: lint
30lint: $(GOBIN)/golangci-lint
31 $(GOBIN)/golangci-lint run
32
33$(GOBIN)/gofumpt: tools/gofumpt/go.mod tools/gofumpt/go.sum
34 go install -modfile=tools/gofumpt/go.mod mvdan.cc/gofumpt
35$(GOBIN)/goimports: tools/goimports/go.mod tools/goimports/go.sum
36 go install -modfile=tools/goimports/go.mod golang.org/x/tools/cmd/goimports
37$(GOBIN)/betteralign: tools/betteralign/go.mod tools/betteralign/go.sum
38 go install -modfile=tools/betteralign/go.mod github.com/dkorunic/betteralign/cmd/betteralign
39.PHONY: format
40format: $(GOBIN)/betteralign $(GOBIN)/gofumpt $(GOBIN)/goimports
41 $(GOBIN)/betteralign -test_files -apply ./...
42 $(GOBIN)/gofumpt -extra -l -w .
43 $(GOBIN)/goimports -local github.com/cloudflare/pint -w .
44
45tidy:
46 go mod tidy
47 @for f in $(wildcard tools/*/go.mod) ; do echo ">>> $$f" && cd $(CURDIR)/`dirname "$$f"` && go mod tidy && cd $(CURDIR) ; done
48
49
50.PHONY: test
51test:
52 mkdir -p $(COVER_DIR)
53 echo 'mode: atomic' > $(COVER_PROFILE)
54 go test \
55 $(GOFLAGS) \
56 -covermode=atomic \
57 -coverprofile=$(COVER_PROFILE) \
58 -coverpkg=./... \
59 -race \
60 -count=3 \
61 -timeout=15m \
62 ./...
63
64.PHONY: debug-testscript
65debug-testscript:
66 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
67
68.PHONY: update-snapshots
69update-snapshots:
70 UPDATE_SNAPS=true UPDATE_SNAPSHOTS=1 go test -count=1 ./...
71 $(MAKE) test
72
73.PHONY: cover
74cover: test
75 go tool cover -func=$(COVER_PROFILE)
76
77.PHONY: coverhtml
78coverhtml: test
79 go tool cover -html=$(COVER_PROFILE)
80
81.PHONY: benchmark
82benchmark:
83 go test \
84 $(GOFLAGS) \
85 -count=10 \
86 -run=none \
87 -bench=. \
88 -benchmem \
89 ./cmd/pint
90
91$(GOBIN)/benchstat: tools/benchstat/go.mod tools/benchstat/go.sum
92 go install -modfile=tools/benchstat/go.mod golang.org/x/perf/cmd/benchstat
93.PHONY: benchmark-diff
94benchmark-diff: $(GOBIN)/benchstat
95 echo "Benchmark diff:" | tee benchstat.txt
96 echo "" | tee -a benchstat.txt
97 echo '```' | tee -a benchstat.txt
98 $(GOBIN)/benchstat old.txt new.txt | tee -a benchstat.txt
99 echo '```' | tee -a benchstat.txt