forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
296 lines (253 loc) · 8.86 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
GO ?= go
GOFMT ?= gofmt "-s"
PACKAGES ?= $(shell $(GO) list ./...)
VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /examples/)
GOFILES := $(shell find . -name "*.go")
VERSION := $(shell grep 'const VERSION =' share/const.go |awk '{print $$4}' |sed 's/\"//g')
# ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
TESTFOLDER := $(shell $(GO) list ./... | grep -vE 'examples|tests*|config')
TESTTAGS ?= ""
# 运行单元测试
.PHONY: test
test:
echo "mode: count" > coverage.out
for d in $(TESTFOLDER); do \
$(GO) test -tags $(TESTTAGS) -v -covermode=count -coverprofile=profile.out -coverpkg=$$(echo $$d | sed "s/\/test$$//g") $$d > tmp.out; \
cat tmp.out; \
if grep -q "^--- FAIL" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "build failed" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "setup failed" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "runtime error" tmp.out; then \
rm tmp.out; \
exit 1; \
fi; \
if [ -f profile.out ]; then \
cat profile.out | grep -v "mode:" >> coverage.out; \
rm profile.out; \
fi; \
done
.PHONY: fmt
fmt:
$(GOFMT) -w $(GOFILES)
.PHONY: fmt-check
fmt-check:
@diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
vet:
$(GO) env -w GONOPROXY=github.com/yaoapp/gou
$(GO) env -w GOPRIVATE=github.com/yaoapp/gou
$(GO) vet $(VETPACKAGES)
.PHONY: lint
lint:
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u golang.org/x/lint/golint; \
fi
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
.PHONY: misspell-check
misspell-check:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -error $(GOFILES)
.PHONY: misspell
misspell:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -w $(GOFILES)
.PHONY: tools
tools:
go install golang.org/x/lint/golint; \
go install github.com/client9/misspell/cmd/misspell;
# 编译测试用插件
.PHONY: plugin
plugin:
rm -rf $(HOME)/data/gou-unit/plugins
rm -rf $(HOME)/data/gou-unit/logs
mkdir -p $(HOME)/data/gou-unit/plugins
mkdir -p $(HOME)/data/gou-unit/logs
GOOS=linux GOARCH=amd64 go build -o $(HOME)/data/gou-unit/plugins/user.so ./tests/plugins/user
chmod +x $(HOME)/data/gou-unit/plugins/user.so
ls -l $(HOME)/data/gou-unit/plugins
ls -l $(HOME)/data/gou-unit/logs
$(HOME)/data/gou-unit/plugins/user.so 2>&1 || true
plugin-mac:
rm -rf ./tests/plugins/user/dist
rm -rf ./tests/plugins/user.so
go build -o ./tests/plugins/user.so ./tests/plugins/user
chmod +x ./tests/plugins/user.so
# 编译静态文件
.PHONY: static
static:
git clone [email protected]:YaoApp/xiang-saas-ui-kxy .tmp/ui
cd .tmp/ui && yarn install && yarn build
rm -rf ui
mv .tmp/ui/dist ui
rm -rf .tmp/ui
# 将静态文件打包到命令工具
.PHONY: bindata
bindata: gen-bindata fmt
# 将静态文件打包到命令工具
.PHONY: gen-bindata
gen-bindata:
mkdir -p .tmp/data
cp -r ui .tmp/data/
cp -r xiang .tmp/data/
go-bindata -fs -pkg data -o data/bindata.go -prefix ".tmp/data/" .tmp/data/...
rm -rf .tmp/data
# 编译可执行文件
.PHONY: xiang
xiang: bindata
if [ ! -z "${XIANG_DOMAIN}" ]; then \
mv share/const.go share/const.go.bak; \
sed "s/*.iqka.com/$(XIANG_DOMAIN)/g" share/const.go.bak > share/const.go; \
fi;
# GOOS=linux GOARCH=amd64 go build -v -o .tmp/xiang-linux-amd64
# GOOS=linux GOARCH=arm GOARM=7 go build -v -o .tmp/xiang-linux-arm
# GOOS=linux GOARCH=arm64 GOARM=7 go build -v -o .tmp/xiang-linux-arm64
GOOS=darwin GOARCH=amd64 go build -v -o .tmp/xiang-darwin-amd64
mkdir -p dist/bin
mv .tmp/xiang-*-* dist/bin/
chmod +x dist/bin/xiang-*-*
if [ ! -z "${XIANG_DOMAIN}" ]; then \
rm share/const.go; \
mv share/const.go.bak share/const.go; \
fi;
.PHONY: release
release: clean
mkdir -p dist/release
git clone [email protected]:YaoApp/yao.git dist/release
git clone [email protected]:YaoApp/kun.git dist/kun
git clone [email protected]:YaoApp/xun.git dist/xun
git clone [email protected]:YaoApp/gou.git dist/gou
# UI制品
git clone [email protected]:YaoApp/xiang-ui .tmp/ui
sed -ie "s/url('\/icon/url('\/xiang\/icon/g" .tmp/ui/public/icon/md_icon.css
cd .tmp/ui && cnpm install && npm run build
rm -rf dist/release/ui
mv .tmp/ui/dist dist/release/ui
# 静态文件打包
mkdir -p .tmp/data
cp -r dist/release/ui .tmp/data/
cp -r dist/release/xiang .tmp/data/
go-bindata -fs -pkg data -o dist/release/data/bindata.go -prefix ".tmp/data/" .tmp/data/...
rm -rf .tmp/data
rm -rf .tmp/ui
# 制品
if [ ! -z "${XIANG_DOMAIN}" ]; then \
mv dist/release/share/const.go dist/release/share/const.go.bak; \
sed "s/*.iqka.com/$(XIANG_DOMAIN)/g" dist/release/share/const.go.bak > dist/release/share/const.go; \
fi;
# cd dist/release && CGO_ENABLED=1 CC=x86_64-linux-musl-gcc CGO_LDFLAGS="-static" GOOS=linux GOARCH=amd64 go build -v -o ../../.tmp/xiang-${VERSION}-linux-amd64
# cd dist/release && GOOS=linux GOARCH=arm GOARM=7 go build -v -o ../../.tmp/xiang-${VERSION}-linux-arm
# cd dist/release && GOOS=linux GOARCH=arm64 GOARM=7 go build -v -o ../../.tmp/xiang-${VERSION}-linux-arm64
cd dist/release && CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -v -o ../../.tmp/xiang-${VERSION}-darwin-amd64
# cd dist/release && GOOS=windows GOARCH=386 go build -v -o ../../.tmp/xiang-${VERSION}-windows-386
rm -rf dist/release
mkdir -p dist/release
mv .tmp/xiang-*-* dist/release/
chmod +x dist/release/xiang-*-*
.PHONY: hi
hi:
echo ${VERSION}
.PHONY: arm
arm: clean
mkdir -p dist/release
git clone [email protected]:YaoApp/yao.git dist/release
git clone [email protected]:YaoApp/kun.git dist/kun
git clone [email protected]:YaoApp/xun.git dist/xun
git clone [email protected]:YaoApp/gou.git dist/gou
# UI制品
git clone [email protected]:YaoApp/xiang-ui.git .tmp/ui
sed -ie "s/url('\/icon/url('\/xiang\/icon/g" .tmp/ui/public/icon/md_icon.css
cd .tmp/ui && cnpm install && npm run build
rm -rf dist/release/ui
mv .tmp/ui/dist dist/release/ui
# 静态文件打包
mkdir -p .tmp/data
cp -r dist/release/ui .tmp/data/
cp -r dist/release/xiang .tmp/data/
go-bindata -fs -pkg data -o dist/release/data/bindata.go -prefix ".tmp/data/" .tmp/data/...
rm -rf .tmp/data
rm -rf .tmp/ui
# 制品
mkdir -p dist
cd dist/release && CC=arm-linux-gnueabi-gcc CXX=arm-linux-gnueabi-g++ CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build -v -o ../../.tmp/xiang-${VERSION}-linux-arm
rm -rf dist/release
mkdir -p dist/release
mv .tmp/xiang-*-* dist/release/
chmod +x dist/release/xiang-*-*
.PHONY: linux
linux: clean
mkdir -p dist/release
git clone [email protected]:YaoApp/yao.git dist/release
git clone [email protected]:YaoApp/kun.git dist/kun
git clone [email protected]:YaoApp/xun.git dist/xun
git clone [email protected]:YaoApp/gou.git dist/gou
# UI制品
git clone [email protected]:YaoApp/xiang-ui.git .tmp/ui
sed -ie "s/url('\/icon/url('\/xiang\/icon/g" .tmp/ui/public/icon/md_icon.css
cd .tmp/ui && cnpm install && npm run build
rm -rf dist/release/ui
mv .tmp/ui/dist dist/release/ui
# 静态文件打包
mkdir -p .tmp/data
cp -r dist/release/ui .tmp/data/
cp -r dist/release/xiang .tmp/data/
go-bindata -fs -pkg data -o dist/release/data/bindata.go -prefix ".tmp/data/" .tmp/data/...
rm -rf .tmp/data
rm -rf .tmp/ui
# 制品
mkdir -p dist
cd dist/release && CGO_ENABLED=1 CGO_LDFLAGS="-static" GOOS=linux GOARCH=amd64 go build -v -o ../../.tmp/xiang-${VERSION}-linux-amd64
rm -rf dist/release
mkdir -p dist/release
mv .tmp/xiang-*-* dist/release/
chmod +x dist/release/xiang-*-*
.PHONY: artifacts
artifacts: clean
mkdir -p dist/release
# UI制品
sed -ie "s/url('\/icon/url('\/xiang\/icon/g" ../ui/public/icon/md_icon.css
cd ../ui && npm install && npm run build
# 静态文件打包
mkdir -p .tmp/data
cp -r ../ui/dist .tmp/data/ui
cp -r xiang .tmp/data/
go-bindata -fs -pkg data -o data/bindata.go -prefix ".tmp/data/" .tmp/data/...
rm -rf .tmp/data
rm -rf .tmp/ui
# 制品
mkdir -p dist
CGO_ENABLED=1 CGO_LDFLAGS="-static" GOOS=linux GOARCH=amd64 go build -v -o dist/yao-${VERSION}-linux-amd64
# CGO_ENABLED=1 CGO_LDFLAGS="-static" GOOS=linux GOARCH=arm GOARM=7 CC=arm-linux-gnueabi-gcc CXX=arm-linux-gnueabi-g++ go build -v -o dist/yao-${VERSION}-linux-arm
# CGO_ENABLED=1 CGO_LDFLAGS="-static" GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ go build -v -o dist/yao-${VERSION}-linux-arm64
mkdir -p dist/release
mv dist/yao-*-* dist/release/
chmod +x dist/release/yao-*-*
ls -l dist/release/
dist/release/yao-${VERSION}-linux-amd64 version
.PHONY: win32
win32: bindata
GOOS=windows GOARCH=386 go build -v -o .tmp/xiang-windows-386
mkdir -p dist/bin
mv .tmp/xiang-*-* dist/bin/
chmod +x dist/bin/xiang-*-*
.PHONY: clean
clean:
rm -rf ./tmp
rm -rf .tmp
rm -rf dist
.PHONY: migrate
migrate:
$(GO) test -tags $(TESTTAGS) -run TestCommandMigrate$