-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
83 lines (61 loc) · 2.59 KB
/
Copy pathMakefile
File metadata and controls
83 lines (61 loc) · 2.59 KB
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
# Test targets:
# make test - Run all unit tests (excludes integration tests)
# make test-int - Run integration tests only (requires explicit build tag)
# make cover - Unit test coverage report
# make cover-int - Integration test coverage report
.PHONY: build lint vet test bench bench-int tidy fmt fmt-check goimports goimports-check cover cover-int cover-check install-lint setup ci clean
VERSION ?= $(shell git describe --tags --always --dirty)
build:
go install -trimpath -ldflags "-s -w -X main.version=$(VERSION)" ./cmd/...
lint:
golangci-lint config verify
golangci-lint run ./...
vet:
go vet ./...
test:
go test ./... -race -shuffle=on -count=1 -v
bench:
go test -bench=. -benchmem ./...
test-int:
go test -tags=integration ./test/integration -v
bench-int:
go test -tags=integration -bench=. -benchmem ./test/integration
tidy:
go mod tidy
fmt:
gofumpt -w .
fmt-check:
@diffs=$$(gofumpt -l .); if [ -n "$$diffs" ]; then echo "Run 'make fmt' to format the following files:"; echo "$$diffs"; exit 1; fi
# Format imports using goimports (enforces import grouping)
goimports:
goimports -w -local github.com/jingle2008/toolkit .
goimports-check:
@diffs=$$(goimports -l -local github.com/jingle2008/toolkit .); if [ -n "$$diffs" ]; then echo "Run 'make goimports' to fix imports in:"; echo "$$diffs"; exit 1; fi
cover:
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
@echo "Open coverage.html in your browser to view the report."
cover-int:
go test -tags=integration ./test/integration -coverprofile=coverage-int.out
go tool cover -html=coverage-int.out -o coverage-int.html
@echo "Open coverage-int.html in your browser to view the integration test report."
cover-check:
go test ./... -race -shuffle=on -count=1 -covermode=atomic -coverprofile=coverage.out
go tool cover -func=coverage.out | awk '/total:/ {if ($$3+0 < 80) {print "Coverage below 80%"; exit 1}}'
# Keep these in sync with the module pins in go.mod (single source of truth):
# golangci-lint -> github.com/golangci/golangci-lint/v2
# gofumpt -> mvdan.cc/gofumpt
# goimports -> golang.org/x/tools
LINT_VERSION ?= v2.12.2
GOFUMPT_VERSION ?= v0.10.0
GOIMPORTS_VERSION ?= v0.46.0
install-lint:
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(LINT_VERSION)
setup:
$(MAKE) install-lint
go install mvdan.cc/gofumpt@$(GOFUMPT_VERSION)
go install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)
ci: fmt-check goimports-check lint vet cover-check
clean:
rm -f coverage.out coverage.html coverage-int.out coverage-int.html toolkit.log
rm -rf bin/