-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
81 lines (64 loc) · 1.81 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
GOBIN ?= $(shell go env GOPATH)/bin
VERSION := $$(make -s show-version)
HAS_LINT := $(shell command -v $(GOBIN)/golangci-lint 2> /dev/null)
HAS_VULNCHECK := $(shell command -v $(GOBIN)/govulncheck 2> /dev/null)
HAS_GOBUMP := $(shell command -v $(GOBIN)/gobump 2> /dev/null)
BIN_LINT := github.com/golangci/golangci-lint/cmd/golangci-lint@latest
BIN_GOVULNCHECK := golang.org/x/vuln/cmd/govulncheck@latest
BIN_GOBUMP := github.com/x-motemen/gobump/cmd/gobump@latest
export GO111MODULE=on
.PHONY: check
check: test cover bench golangci-lint govulncheck
.PHONY: deps
deps: deps-lint deps-govulncheck deps-gobump
.PHONY: deps-lint
deps-lint:
ifndef HAS_LINT
go install $(BIN_LINT)
endif
.PHONY: deps-govulncheck
deps-govulncheck:
ifndef HAS_VULNCHECK
go install $(BIN_GOVULNCHECK)
endif
.PHONY: deps-gobump
deps-gobump:
ifndef HAS_GOBUMP
go install $(BIN_GOBUMP)
endif
.PHONY: test
test:
go test ./... -v -cover -coverprofile=cover.out
.PHONY: cover
cover:
go tool cover -html=cover.out -o cover.html
.PHONY: bench
bench:
go test -run=^$$ -bench=. -benchmem -count 5 -cpuprofile=cpu.prof -memprofile=mem.prof
.PHONY: golangci-lint
golangci-lint: deps-lint
golangci-lint run ./... -v
.PHONY: govulncheck
govulncheck: deps-govulncheck
$(GOBIN)/govulncheck -test ./...
.PHONY: show-version
show-version: deps-gobump
$(GOBIN)/gobump show -r .
.PHONY: check-git
ifneq ($(shell git status --porcelain),)
$(error git workspace is dirty)
endif
ifneq ($(shell git rev-parse --abbrev-ref HEAD),main)
$(error current branch is not main)
endif
.PHONY: publish
publish: deps-gobump check-git
$(GOBIN)/gobump up -w .
git commit -am "bump up version to $(VERSION)"
git tag "v$(VERSION)"
git push origin main
git push origin "refs/tags/v$(VERSION)"
.PHONY: clean
clean:
go clean
rm -f cover.out cover.html cpu.prof mem.prof $(BIN).test