cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.57.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

Makefile

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