forked from dipperin/dipperin-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cs.sh
executable file
·229 lines (162 loc) · 5.06 KB
/
cs.sh
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
#!/usr/bin/env bash
#####################################################################################
# #
# #
# #
# Dipperin Shell Script #
# #
# #
# #
#####################################################################################
root=`pwd`
GoPath=$HOME/go/src/
cover () {
target_dir=${root}/test-summary
# mkdir
if [[ ! -d ${target_dir} ]];then
echo "mkdir test-summary"
mkdir -p ${target_dir}
else
rm -rf test-summary
mkdir -p ${target_dir}
fi
# run go test
echo "summary test coverage for dipperin core & cmd & common"
run_c
# summary
cd ${root}/test-summary
go tool cover -func=test_cover.out -o test_summary.text
LASTLINE=$(tail -1 test_summary.text)
echo "core & cmd & common test coverage : " ${LASTLINE}
if [[ $1 == true ]];then
go tool cover -html=test_cover.out
fi
}
run_c () {
#go test -failfast -v -coverprofile=./test-summary/test_cover.out -p 1 ./core/... ./common/... ./cmd/...
go test -failfast -coverprofile=./test-summary/test_cover.out -p 1 ./core/... ./cmd/... ./common/...
#go test -failfast -coverprofile=./test-summary/test_cover.out -p 1 ./cmd/...
FAIL=$?
if [[ ${FAIL} != 0 ]];then
echo "go test failed, please fix test"
exit ${FAIL}
fi
}
run_test () {
# is_jenkins="yes" go test -p 1 -cover ./... -coverprofile=size_coverage.out
is_jenkins="yes" go test -p 1 -cover ./core/... ./common/... ./cmd/...
return $?
}
jks_test () {
if [ ! -d ${GoPath} ];then
echo "mkdir go path:$GoPath"
mkdir -p ${GoPath}
fi
# 获取当前项目的信息
curProName=`basename $PWD`
# 获取该项目应该在的位置(go path下)
gpCurPro="$GoPath$curProName"
if [ ! -d ${gpCurPro} ];then
echo "ln cur pro to go path"
curProPath=`pwd`
ln -s ${curProPath} ${gpCurPro}
fi
cd ${gpCurPro}
run_test
return $?
}
build_ci() {
echo 'build dipperin'
monitor_path="${GoPath}/chainstack-monitor/core"
#rm ~/go/bin/dipperin;
cd ${monitor_path}/cmd/dipperin; go install
#rm ~/go/bin/dipperincli;
echo 'build dipperincli'
cd ${monitor_path}/cmd/dipperincli; go install
#rm ~/go/bin/bootnode;
echo 'build bootnode'
cd ${root}/cmd/bootnode; go install
#rm ~/go/bin/miner;
echo 'build miner'
cd ${root}/cmd/miner; go install
cd ${root}
return $?
}
build_install() {
echo 'build dipperin'
cd ${root}/cmd/dipperin; go install
echo 'build dipperincli'
cd ${root}/cmd/dipperincli; go install
echo 'build bootnode'
cd ${root}/cmd/bootnode; go install
echo 'build miner'
cd ${root}/cmd/miner; go install
# echo 'build chain_checker'
# cd ${root}/cmd/chain_checker; go install
cd ${root}
return $?
}
update_vendor () {
# enable go1.11 mod in go path
export GO111MODULE=on
if [[ -n "$1" ]];then
############################################
#
#
# need use http proxy
#
#
############################################
# go mod tidy download pkg which we are using
export http_proxy=http://127.0.0.1:$1;export https_proxy=http://127.0.0.1:$1;go mod tidy
go mod vendor
exit $?
fi
go mod tidy
go mod vendor
return $?
}
main () {
if [[ ! $1 ]];then
run_test
exit $?
fi
case $1 in
[Jj][Kk][Ss] )
{
jks_test
};;
ci )
{
build_ci
};;
install )
{
build_install
};;
tidy )
{
update_vendor $2
};;
cover )
{
cover $2
};;
esac
exit $?
}
echo "
#####################################################################################
# #
# #
# #
# Dipperin Shell Script #
# #
# #
# #
#####################################################################################
"
# setup git hooks
find .git/hooks -type l -exec rm {} \;
find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \;
main $1 $2