-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
203 lines (178 loc) · 6.84 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
.PHONY: test check clean build dist all
#TOP_DIR := $(shell pwd)
# can change by env:ENV_CI_DIST_VERSION use and change by env:ENV_CI_DIST_MARK by CI
ENV_DIST_VERSION=v0.1.2
ENV_DIST_MARK=
ROOT_NAME ?=GoLang-PlayGround
## MakeDocker.mk settings start
ROOT_OWNER ?=sinlov
ROOT_PARENT_SWITCH_TAG=1.20.14
# for image local build
INFO_TEST_BUILD_DOCKER_PARENT_IMAGE=golang
# for image running
INFO_BUILD_DOCKER_FROM_IMAGE=alpine:3.17
INFO_BUILD_DOCKER_FILE=Dockerfile
INFO_TEST_BUILD_DOCKER_FILE=Dockerfile.s6
## MakeDocker.mk settings end
## run info start
ENV_RUN_INFO_HELP_ARGS= -h
ENV_RUN_INFO_ARGS=
## run info end
## build dist env start
# change to other build entrance
ENV_ROOT_BUILD_ENTRANCE=cmd/GoLang-PlayGround/main.go
ENV_ROOT_BUILD_BIN_NAME=${ROOT_NAME}
ENV_ROOT_BUILD_PATH=build
ENV_ROOT_BUILD_BIN_PATH=${ENV_ROOT_BUILD_PATH}/${ENV_ROOT_BUILD_BIN_NAME}
ENV_ROOT_LOG_PATH=logs/
# linux windows darwin list as: go tool dist list
ENV_DIST_GO_OS=linux
# amd64 386
ENV_DIST_GO_ARCH=amd64
# mark for dist and tag helper
ENV_ROOT_MANIFEST_PKG_JSON?=package.json
ENV_ROOT_MAKE_FILE?=Makefile
ENV_ROOT_CHANGELOG_PATH?=CHANGELOG.md
## build dist env end
## go test MakeGoTest.mk start
# ignore used not matching mode
# set ignore of test case like grep -v -E "vendor|go_fatal_error" to ignore vendor and go_fatal_error package
ENV_ROOT_TEST_INVERT_MATCH ?="vendor|go_fatal_error|robotn|shirou|go_robot"
ifeq ($(OS),Windows_NT)
ENV_ROOT_TEST_LIST?=./...
else
ENV_ROOT_TEST_LIST?=$$(go list ./... | grep -v -E ${ENV_ROOT_TEST_INVERT_MATCH})
endif
# test max time
ENV_ROOT_TEST_MAX_TIME:=1m
## go test MakeGoTest.mk end
include z-MakefileUtils/MakeBasicEnv.mk
include z-MakefileUtils/MakeDistTools.mk
include z-MakefileUtils/MakeGoList.mk
include z-MakefileUtils/MakeGoMod.mk
include z-MakefileUtils/MakeGoTest.mk
include z-MakefileUtils/MakeGoTestIntegration.mk
include z-MakefileUtils/MakeGoDist.mk
# include MakeDockerRun.mk for docker run
include z-MakefileUtils/MakeDocker.mk
all: env
env: distEnv
@echo "== project env info start =="
@echo ""
@echo "test info"
@echo "ENV_ROOT_TEST_LIST ${ENV_ROOT_TEST_LIST}"
@echo ""
@echo "ROOT_NAME ${ROOT_NAME}"
@echo "ENV_DIST_VERSION ${ENV_DIST_VERSION}"
@echo "ENV_ROOT_CHANGELOG_PATH ${ENV_ROOT_CHANGELOG_PATH}"
@echo ""
@echo "ENV_ROOT_BUILD_ENTRANCE ${ENV_ROOT_BUILD_ENTRANCE}"
@echo "ENV_ROOT_BUILD_PATH ${ENV_ROOT_BUILD_PATH}"
ifeq ($(OS),Windows_NT)
@echo "ENV_ROOT_BUILD_BIN_PATH $(subst /,\,${ENV_ROOT_BUILD_BIN_PATH}).exe"
else
@echo "ENV_ROOT_BUILD_BIN_PATH ${ENV_ROOT_BUILD_BIN_PATH}"
endif
@echo "ENV_DIST_GO_OS ${ENV_DIST_GO_OS}"
@echo "ENV_DIST_GO_ARCH ${ENV_DIST_GO_ARCH}"
@echo ""
@echo "ENV_DIST_MARK ${ENV_DIST_MARK}"
@echo "== project env info end =="
cleanBuild:
@$(RM) -r ${ENV_ROOT_BUILD_PATH}
@echo "~> finish clean path: ${ENV_ROOT_BUILD_PATH}"
cleanLog:
@$(RM) -r ${ENV_ROOT_LOG_PATH}
@echo "~> finish clean path: ${ENV_ROOT_LOG_PATH}"
cleanTest:
@$(RM) coverage.txt
@$(RM) coverage.out
@$(RM) profile.txt
cleanTestData:
$(info -> notes: remove folder [ testdata ] unable to match subdirectories)
@$(RM) -r **/testdata
@$(RM) -r **/**/testdata
@$(RM) -r **/**/**/testdata
@$(RM) -r **/**/**/**/testdata
@$(RM) -r **/**/**/**/**/testdata
@$(RM) -r **/**/**/**/**/**/testdata
$(info -> finish clean folder [ testdata ])
clean: cleanTest cleanBuild cleanLog
@echo "~> clean finish"
cleanAll: clean
@echo "~> clean all finish"
init:
@echo "~> start init this project"
@echo "-> check version"
go version
@echo "-> check env golang"
go env
@echo "~> you can use [ make help ] see more task"
-go mod verify
dep: modVerify modDownload modTidy
@echo "-> just check depends below"
style: modTidy modVerify modFmt modLintRun
ci: modTidy modVerify modFmt modLintRun test
buildMain:
@echo "-> start build local OS: ${PLATFORM} ${OS_BIT}"
ifeq ($(OS),Windows_NT)
@go build -o $(subst /,\,${ENV_ROOT_BUILD_BIN_PATH}).exe ${ENV_ROOT_BUILD_ENTRANCE}
@echo "-> finish build out path: $(subst /,\,${ENV_ROOT_BUILD_BIN_PATH}).exe"
else
@go build -o ${ENV_ROOT_BUILD_BIN_PATH} ${ENV_ROOT_BUILD_ENTRANCE}
@echo "-> finish build out path: ${ENV_ROOT_BUILD_BIN_PATH}"
endif
devHelp: export CLI_VERBOSE=false
devHelp: cleanBuild buildMain
ifeq ($(OS),Windows_NT)
$(subst /,\,${ENV_ROOT_BUILD_BIN_PATH}).exe ${ENV_RUN_INFO_HELP_ARGS}
else
${ENV_ROOT_BUILD_BIN_PATH} ${ENV_RUN_INFO_HELP_ARGS}
endif
dev: export ENV_WEB_AUTO_HOST=true
dev: cleanBuild buildMain
ifeq ($(OS),Windows_NT)
$(subst /,\,${ENV_ROOT_BUILD_BIN_PATH}).exe ${ENV_RUN_INFO_ARGS}
else
${ENV_ROOT_BUILD_BIN_PATH} ${ENV_RUN_INFO_ARGS}
endif
runHelp: export CLI_VERBOSE=false
runHelp:
go run -v ${ENV_ROOT_BUILD_ENTRANCE} ${ENV_RUN_INFO_HELP_ARGS}
cloc:
@echo "see: https://stackoverflow.com/questions/26152014/cloc-ignore-exclude-list-file-clocignore"
cloc --exclude-list-file=.clocignore .
helpProjectRoot:
@echo "Help: Project root Makefile"
ifeq ($(OS),Windows_NT)
@echo ""
@echo "warning: other install make cli tools has bug, please use: scoop install main/make"
@echo " run will at make tools version 4.+"
@echo "windows use this kit must install tools blow:"
@echo ""
@echo "https://scoop.sh/#/apps?q=busybox&s=0&d=1&o=true"
@echo "-> scoop install main/busybox"
@echo "and"
@echo "https://scoop.sh/#/apps?q=shasum&s=0&d=1&o=true"
@echo "-> scoop install main/shasum"
@echo ""
endif
@echo "-- now build name: ${ROOT_NAME} version: ${ENV_DIST_VERSION}"
@echo "-- distTestOS or distReleaseOS will out abi as: ${ENV_DIST_GO_OS} ${ENV_DIST_GO_ARCH} --"
@echo ""
@echo "~> make env - print env of this project"
@echo "~> make init - check base env of this project"
@echo "~> make dep - check and install by go mod"
@echo "~> make clean - remove build binary file, log files, and testdata"
@echo "~> make test - run test case ignore --invert-match by config"
@echo "~> make testCoverage - run test coverage case ignore --invert-match by config"
@echo "~> make testCoverageBrowser - see coverage at browser --invert-match by config"
@echo "~> make testBenchmark - run go test benchmark case all"
@echo "~> make ci - run CI tools tasks"
@echo "~> make style - run local code fmt and style check"
@echo "~> make devHelp - run as develop mode see help with ${ENV_RUN_INFO_HELP_ARGS}"
@echo "~> make dev - run as develop mode"
@echo "~> make runHelp - run use ${ENV_RUN_INFO_HELP_ARGS}"
help: helpGoMod helpGoTest helpGoDist helpDocker helpProjectRoot
@echo ""
@echo "-- more info see Makefile include: MakeGoMod.mk MakeGoTest.mk MakeGoTestIntegration.mk MakeDocker.mk --"