-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
87 lines (74 loc) · 2.82 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
export GO111MODULE=on
APP:=protolinter
OS:=$(shell go env GOOS)
ARCH:=$(shell go env GOARCH)
LOCAL_BIN:=$(CURDIR)/bin
GOLANGCI_BIN:=$(LOCAL_BIN)/golangci-lint
GOLANGCI_TAG:=1.53.3
GOLANGCI_CONFIG:=.golangci.yaml
GOLANGCI_STRICT_CONFIG:=.golangci-strict.yaml
ifneq ($(wildcard $(GOLANGCI_BIN)),)
GOLANGCI_BIN_VERSION:=$(shell $(GOLANGCI_BIN) --version)
ifneq ($(GOLANGCI_BIN_VERSION),)
GOLANGCI_BIN_VERSION_SHORT:=$(shell echo "$(GOLANGCI_BIN_VERSION)" | sed -E 's/.* version (.*) built .* from .*/\1/g')
else
GOLANGCI_BIN_VERSION_SHORT:=0
endif
ifneq "$(GOLANGCI_TAG)" "$(word 1, $(sort $(GOLANGCI_TAG) $(GOLANGCI_BIN_VERSION_SHORT)))"
GOLANGCI_BIN:=
endif
endif
default: help
.PHONY: install-lint
install-lint:
ifeq ($(wildcard $(GOLANGCI_BIN)),)
$(info Downloading golangci-lint v$(GOLANGCI_TAG))
@mkdir -p $(LOCAL_BIN)
GOBIN=$(LOCAL_BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(GOLANGCI_TAG)
GOLANGCI_BIN:=$(LOCAL_BIN)/golangci-lint
endif
.PHONY: lint
lint: install-lint
$(info Running lint in normal mode...)
$(GOLANGCI_BIN) run --new-from-rev=origin/master --config=$(GOLANGCI_CONFIG) ./...
.PHONY: lint-strict
lint-strict: install-lint
$(info Running lint in strict mode...)
$(GOLANGCI_BIN) run --new-from-rev=origin/master --config=$(GOLANGCI_STRICT_CONFIG) ./...
.PHONY: lint-full
lint-full: install-lint
$(info Running lint in normal mode...)
$(GOLANGCI_BIN) run --config=$(GOLANGCI_CONFIG) ./...
.PHONY: lint-strict-full
lint-strict-full: install-lint
$(info Running lint in strict mode...)
$(GOLANGCI_BIN) run --config=$(GOLANGCI_STRICT_CONFIG) ./...
.PHONY: test
test:
@go test -v ./...
.PHONY: build
build:
$(info Building $(APP) for $(OS)/$(ARCH))
@mkdir -p $(LOCAL_BIN)
@GOOS=$(OS) GOARCH=$(ARCH) go build -o $(LOCAL_BIN)/$(APP) main.go
.PHONY: run
run:
@mkdir -p $(LOCAL_BIN)
@$(LOCAL_BIN)/$(APP)
.PHONY: clean
clean:
@mkdir -p $(LOCAL_BIN)
@rm -rf $(LOCAL_BIN)/$(APP)
.PHONY: help
help:
@echo "Available targets:"
@echo " help Show this help message"
@echo " install-lint Download and install golangci-lint to $(LOCAL_BIN) directory if it's not already installed"
@echo " lint Run golangci-lint with normal checks and compare changes against master branch."
@echo " lint-strict Same as 'lint', but with more strict checks."
@echo " lint-full Run golangci-lint with normal checks for all files in the repository."
@echo " lint-strict-full Same as 'lint-full', but with more strict checks."
@echo " test Run unit tests"
@echo " build Build the $(APP) binary for $(OS)/$(ARCH)"
@echo " run Run the $(APP) binary"
@echo " clean Remove the $(APP) binary"