-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
105 lines (83 loc) · 2.21 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
100
101
102
103
104
105
BIN := tlc3
ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
endif
GOBIN ?= $(shell go env GOPATH)/bin
VERSION := $$(make -s show-version)
REVISION := $(shell git rev-parse --short HEAD)
LDFLAGS := "-s -w -X main.Version=$(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: build
build: clean
go mod tidy
go build -ldflags $(LDFLAGS) -o $(BIN) .
.PHONY: put
put: build
cp $(BIN) $(GOBIN)/$(BIN)
.PHONY: check
check: test cover bench vet 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 -race -cover -v ./... -coverprofile=cover.out -covermode=atomic
.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: vet
vet:
go vet
.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 push origin main
.PHONY: release
release: check-git
git tag "v$(VERSION)"
git push origin "refs/tags/v$(VERSION)"
.PHONY: clean
clean:
go clean
rm -f $(BIN) cover.out cover.html
rm -f cover.out cover.html cpu.prof mem.prof $(BIN).test