-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
85 lines (72 loc) · 1.72 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
# Define os name
OS_NAME=$(OS)
# Define go build
OUTPUT_BIN=data-pipeline-go
BUILD_DIR=cmd
CGO=1
ifeq ($(OS_NAME), Windows_NT)
CHCP_CMD := chcp 65001 > nul
TARGET_OS = windows
TARGET_ARCH = amd64
CMD_PREFIX = powershell -Command
CMD_SUFFIX = .exe
CMD_AND = ;
BUILD_ARGS := set CGO_ENABLED=${CGO}; set GOOS=${TARGET_OS}; set GOARCH=${TARGET_ARCH}
CLEAN_CMD := Remove-Item -Path ${BUILD_DIR}/${OUTPUT_BIN}${CMD_SUFFIX}
else
OS_NAME=$(shell uname)
CHCP_CMD :=
TARGET_OS = linux
TARGET_ARCH = amd64
CMD_PREFIX =
CMD_SUFFIX =
CMD_AND = &&
BUILD_ARGS := export CGO_ENABLED=${CGO} GOOS=${TARGET_OS} GOARCH=${TARGET_ARCH}
CLEAN_CMD := rm -f ${BUILD_DIR}/${OUTPUT_BIN}${CMD_SUFFIX}
endif
# Define golangci-lint
GOLANGCI_LINT=golangci-lint
GOLANGCI_LINT_VERBOSE=--verbose
# Define nilaway
NILAWAY=nilaway
# 默认目标, 显示帮助信息
.PHONY: help
help:
@$(CHCP_CMD)
@echo "Available targets:"
@echo - help [显示帮助信息]
@echo - lint [代码静态检查]
@echo - nilaway [代码 nil 检查]
@echo - test [单元测试]
@echo - build [构建二进制包]
@echo - clean [清理构建文件]
.PHONY: all
all: lint-all build
.PHONY: lint-all
lint-all: lint nilaway
.IGNORE: lint
.PHONY: lint
lint:
@$(CHCP_CMD)
-${GOLANGCI_LINT} run ${GOLANGCI_LINT_VERBOSE}
.IGNORE: nilaway
.PHONY: nilaway
nilaway:
@${CHCP_CMD}
${NILAWAY} ./...
.PHONY: test
test:
@${CHCP_CMD}
go test -v -cover -race ./...
.PHONY: pre-ci-build
pre-ci-build:
@$(CHCP_CMD)
export GOFLAGS="-buildvcs=false"
.PHONY: build
build:
@$(CHCP_CMD)
${CMD_PREFIX} cd ${BUILD_DIR} ${CMD_AND} ${BUILD_ARGS} ${CMD_AND} go build -o ${OUTPUT_BIN}${CMD_SUFFIX} .
.PHONY: clean
clean:
@$(CHCP_CMD)
${CMD_PREFIX} ${CLEAN_CMD}