forked from kevincobain2000/gobrew
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
107 lines (89 loc) · 3.15 KB
/
Copy pathMakefile
File metadata and controls
107 lines (89 loc) · 3.15 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# 通用目录
WORK_DIR := $(shell pwd)
BUILD_DIR := $(WORK_DIR)/build
TARGET_DIR := $(WORK_DIR)/target
DIST_DIR := $(TARGET_DIR)/dist
LINT_DIR := $(TARGET_DIR)/lint
TEST_DIR := $(TARGET_DIR)/test
# 通用变量
MOD_NAME := $(shell go list -m)
# 默认不开启verbose模式
VERBOSE ?= 0
#################
##@ Help
#################
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m \033[36m[VERBOSE=1]\033[0m\n"} \
/^[a-zA-Z_0-9-]+:.*?##/ \
{ printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ \
{ printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
#################
##@ Development
#################
.PHONY: generate
generate: ## Run generate code
@echo "===> step generate..."
@go generate ./...
.PHONY: fmt
fmt: ## Run go fmt against code.
@echo "===> step fmt..."
@go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
@echo "===> step vet..."
@go vet ./...
.PHONY: lint
lint: ## Run go lint (add VERBOSE=1 for -v)
@echo "===> step lint..."
@mkdir -p $(LINT_DIR)
@$(eval VERBOSE_FLAG = $(if $(filter 1,$(VERBOSE)),-v,))
@golangci-lint run --output.junit-xml.path=$(LINT_DIR)/lint.xml --output.html.path=$(LINT_DIR)/lint.html \
$(VERBOSE_FLAG)
.PHONY: test
test: ## Run go test (add VERBOSE=1 for -v)
@echo "===> step test..."
@mkdir -p $(TEST_DIR)
@$(eval VERBOSE_FLAG = $(if $(filter 1,$(VERBOSE)),-v,))
@go test -gcflags=all=-l $$(go list ./... | grep -v /e2e) -covermode=count -coverprofile=$(TEST_DIR)/cover.out $(VERBOSE_FLAG)
@$(eval MODULE_DIR = $(shell basename $(WORK_DIR)))
@gocover diff --cover-profile=$(TEST_DIR)/cover.out -o=$(TEST_DIR)/diff --baseline=0.0 $(VERBOSE_FLAG)
@gocover full --cover-profile=$(TEST_DIR)/cover.out -o=$(TEST_DIR)/full --baseline=0.0 $(VERBOSE_FLAG)
.PHONY: clean
clean: ## Clean up the project.
@echo "===> step clean..."
@rm -rf $(TARGET_DIR)
#################
##@ Dist
#################
### 编译信息
VERSION ?= V0.0.1
PLATFORMS ?= linux/amd64 windows/386 windows/amd64
COMMIT := $(shell git rev-parse --short HEAD)
LDFLAGS = '-w -X $(MOD_NAME)/internal/cmd.Release=$(VERSION) -X $(MOD_NAME)/internal/cmd.Commit=$(COMMIT)'
.PHONY: build
build: fmt vet generate $(PLATFORMS) ## Build binary
$(PLATFORMS):
@$(eval DISTTYPE = $(subst /, ,$@))
@$(eval BUILD_GOOS = $(word 1, $(DISTTYPE)))
@$(eval BUILD_ARCH = $(word 2, $(DISTTYPE)))
@echo Building for $(BUILD_GOOS) platform, arch is $(BUILD_ARCH)...
@mkdir -p $(DIST_DIR)
@outbin="$(DIST_DIR)/gvm-$(BUILD_GOOS)-$(BUILD_ARCH)"; \
if [ "$(BUILD_GOOS)" = "windows" ]; then outbin="$$outbin.exe"; fi; \
GOOS=$(BUILD_GOOS) GOARCH=$(BUILD_ARCH) GO111MODULE=on CGO_ENABLED=0 go build -trimpath -mod vendor -ldflags $(LDFLAGS) \
-o $$outbin ./cmd/gvm
#################
##@ Dependencies
#################
### 版本信息
GOLANGCI_LINT_VERSION ?= v2.5.0
MOCKGEN_VERSION ?= v0.5.1
.PHONY: depend
depend: golangci-lint mockgen ## Set dependencies
golangci-lint:
@echo "===> install golangci-lint..."
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
mockgen:
@echo "===> install mockgen..."
@go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)