forked from BanzaiMan/travis_production_test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
335 lines (275 loc) · 8.7 KB
/
build.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
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/bin/bash
source /etc/profile
if [[ -s ~/.bash_profile ]] ; then
source ~/.bash_profile
fi
ANSI_RED="\033[31;1m"
ANSI_GREEN="\033[32;1m"
ANSI_RESET="\033[0m"
ANSI_CLEAR="\033[0K"
TRAVIS_TEST_RESULT=
TRAVIS_CMD=
function travis_cmd() {
local assert output display retry timing cmd result
cmd=$1
TRAVIS_CMD=$cmd
shift
while true; do
case "$1" in
--assert) assert=true; shift ;;
--echo) output=true; shift ;;
--display) display=$2; shift 2;;
--retry) retry=true; shift ;;
--timing) timing=true; shift ;;
*) break ;;
esac
done
if [[ -n "$timing" ]]; then
travis_time_start
fi
if [[ -n "$output" ]]; then
echo "\$ ${display:-$cmd}"
fi
if [[ -n "$retry" ]]; then
travis_retry eval "$cmd"
else
eval "$cmd"
fi
result=$?
if [[ -n "$timing" ]]; then
travis_time_finish
fi
if [[ -n "$assert" ]]; then
travis_assert $result
fi
return $result
}
travis_time_start() {
travis_timer_id=$(printf %08x $(( RANDOM * RANDOM )))
travis_start_time=$(travis_nanoseconds)
echo -en "travis_time:start:$travis_timer_id\r${ANSI_CLEAR}"
}
travis_time_finish() {
local result=$?
travis_end_time=$(travis_nanoseconds)
local duration=$(($travis_end_time-$travis_start_time))
echo -en "travis_time:end:$travis_timer_id:start=$travis_start_time,finish=$travis_end_time,duration=$duration\r${ANSI_CLEAR}"
return $result
}
function travis_nanoseconds() {
local cmd="date"
local format="+%s%N"
local os=$(uname)
if hash gdate > /dev/null 2>&1; then
cmd="gdate" # use gdate if available
elif [[ "$os" = Darwin ]]; then
format="+%s000000000" # fallback to second precision on darwin (does not support %N)
fi
$cmd -u $format
}
travis_assert() {
local result=${1:-$?}
if [ $result -ne 0 ]; then
echo -e "\n${ANSI_RED}The command \"$TRAVIS_CMD\" failed and exited with $result during $TRAVIS_STAGE.${ANSI_RESET}\n\nYour build has been stopped."
travis_terminate 2
fi
}
travis_result() {
local result=$1
export TRAVIS_TEST_RESULT=$(( ${TRAVIS_TEST_RESULT:-0} | $(($result != 0)) ))
if [ $result -eq 0 ]; then
echo -e "\n${ANSI_GREEN}The command \"$TRAVIS_CMD\" exited with $result.${ANSI_RESET}"
else
echo -e "\n${ANSI_RED}The command \"$TRAVIS_CMD\" exited with $result.${ANSI_RESET}"
fi
}
travis_terminate() {
pkill -9 -P $$ &> /dev/null || true
exit $1
}
travis_wait() {
local timeout=$1
if [[ $timeout =~ ^[0-9]+$ ]]; then
# looks like an integer, so we assume it's a timeout
shift
else
# default value
timeout=20
fi
local cmd="$@"
local log_file=travis_wait_$$.log
$cmd &>$log_file &
local cmd_pid=$!
travis_jigger $! $timeout $cmd &
local jigger_pid=$!
local result
{
wait $cmd_pid 2>/dev/null
result=$?
ps -p$jigger_pid &>/dev/null && kill $jigger_pid
}
if [ $result -eq 0 ]; then
echo -e "\n${ANSI_GREEN}The command $cmd exited with $result.${ANSI_RESET}"
else
echo -e "\n${ANSI_RED}The command $cmd exited with $result.${ANSI_RESET}"
fi
echo -e "\n${ANSI_GREEN}Log:${ANSI_RESET}\n"
cat $log_file
return $result
}
travis_jigger() {
# helper method for travis_wait()
local cmd_pid=$1
shift
local timeout=$1 # in minutes
shift
local count=0
# clear the line
echo -e "\n"
while [ $count -lt $timeout ]; do
count=$(($count + 1))
echo -ne "Still running ($count of $timeout): $@\r"
sleep 60
done
echo -e "\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"$@\"${ANSI_RESET}\n"
kill -9 $cmd_pid
}
travis_retry() {
local result=0
local count=1
while [ $count -le 3 ]; do
[ $result -ne 0 ] && {
echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2
}
"$@"
result=$?
[ $result -eq 0 ] && break
count=$(($count + 1))
sleep 1
done
[ $count -gt 3 ] && {
echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2
}
return $result
}
travis_fold() {
local action=$1
local name=$2
echo -en "travis_fold:${action}:${name}\r${ANSI_CLEAR}"
}
decrypt() {
echo $1 | base64 -d | openssl rsautl -decrypt -inkey ~/.ssh/id_rsa.repo
}
# XXX Forcefully removing rabbitmq source until next build env update
# See http://www.traviscistatus.com/incidents/6xtkpm1zglg3
if [[ -f /etc/apt/sources.list.d/rabbitmq-source.list ]] ; then
sudo rm -f /etc/apt/sources.list.d/rabbitmq-source.list
fi
mkdir -p $HOME/build
cd $HOME/build
travis_fold start system_info
echo -e "\033[33;1mBuild system information\033[0m"
echo -e "Build language: go"
echo -e "Build group: edge"
echo -e "Build dist: trusty"
if [[ -f /usr/share/travis/system_info ]]; then
cat /usr/share/travis/system_info
fi
travis_fold end system_info
echo
echo "options rotate
options timeout:1
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 208.67.222.222
nameserver 208.67.220.220
" | sudo tee /etc/resolv.conf &> /dev/null
sudo sed -e 's/^\(127\.0\.0\.1.*\)$/\1 '`hostname`'/' -i'.bak' /etc/hosts
test -f /etc/mavenrc && sudo sed -e 's/M2_HOME=\(.\+\)$/M2_HOME=${M2_HOME:-\1}/' -i'.bak' /etc/mavenrc
sudo sed -e 's/^127\.0\.0\.1\(.*\) localhost \(.*\)$/127.0.0.1 localhost \1 \2/' -i'.bak' /etc/hosts 2>/dev/null
# apply :home_paths
for path_entry in $HOME/.local/bin $HOME/bin ; do
if [[ ${PATH%%:*} != $path_entry ]] ; then
export PATH="$path_entry:$PATH"
fi
done
export GIT_ASKPASS=echo
travis_fold start git.checkout
if [[ ! -d BanzaiMan/travis_production_test/.git ]]; then
travis_cmd git\ clone\ --depth\=50\ --branch\=\'\'\ [email protected]:BanzaiMan/travis_production_test.git\ BanzaiMan/travis_production_test --assert --echo --retry --timing
else
travis_cmd git\ -C\ BanzaiMan/travis_production_test\ fetch\ origin --assert --echo --retry --timing
travis_cmd git\ -C\ BanzaiMan/travis_production_test\ reset\ --hard --assert --echo
fi
travis_cmd cd\ BanzaiMan/travis_production_test --echo
travis_cmd git\ checkout\ -qf\ --assert --echo
travis_fold end git.checkout
if [[ -f .gitmodules ]]; then
travis_fold start git.submodule
echo Host\ github.com'
'\ StrictHostKeyChecking\ no'
' >> ~/.ssh/config
travis_cmd git\ submodule\ init --assert --echo --timing
travis_cmd git\ submodule\ update --assert --echo --retry --timing
travis_fold end git.submodule
fi
rm -f ~/.ssh/source_rsa
travis_fold start apt
echo -e "\033[33;1mInstalling APT Packages (BETA)\033[0m"
echo -e "\033[31;1mDisallowing packages: g\+\+-4.8\033[0m"
echo -e "If you require these packages, please review the package approval process at: https://github.com/travis-ci/apt-package-whitelist#package-approval-process"
travis_fold end apt
export PS4=+
unset gvm
if [[ -d $HOME/.gvm ]]; then
travis_cmd mv\ \$HOME/.gvm\ \$HOME/.gvm.disabled --assert
fi
if [[ ! -x '$HOME/bin/gimme' && ! -x '/usr/local/bin/gimme' ]]; then
echo -e "\033[33;1mInstalling gimme from "https://raw.githubusercontent.com/travis-ci/gimme/v0.2.4/gimme"\033[0m"
mkdir -p $HOME/bin
curl -sL -o $HOME/bin/gimme 'https://raw.githubusercontent.com/travis-ci/gimme/v0.2.4/gimme'
chmod +x $HOME/bin/gimme
export PATH=$HOME/bin:$PATH
gimme 1.4.1 >/dev/null 2>&1
fi
export TRAVIS=true
export CI=true
export CONTINUOUS_INTEGRATION=true
export HAS_JOSH_K_SEAL_OF_APPROVAL=true
export TRAVIS_PULL_REQUEST=false
export TRAVIS_SECURE_ENV_VARS=false
export TRAVIS_BUILD_ID=''
export TRAVIS_BUILD_NUMBER=''
export TRAVIS_BUILD_DIR=$HOME/build/BanzaiMan/travis_production_test
export TRAVIS_JOB_ID=''
export TRAVIS_JOB_NUMBER=''
export TRAVIS_BRANCH=''
export TRAVIS_COMMIT=''
export TRAVIS_COMMIT_RANGE=''
export TRAVIS_REPO_SLUG=BanzaiMan/travis_production_test
export TRAVIS_OS_NAME=linux
export TRAVIS_LANGUAGE=go
export TRAVIS_TAG=''
export TRAVIS_GO_VERSION=1.4.1
if [[ -z $GOMAXPROCS ]]; then
export GOMAXPROCS=2
fi
travis_cmd eval\ \"\$\(gimme\ 1.4.1\)\" --assert --echo --timing
travis_cmd export\ GOPATH\=\$HOME/gopath --echo
travis_cmd export\ PATH\=\$HOME/gopath/bin:\$PATH --echo
travis_cmd mkdir\ -p\ \$HOME/gopath/src/github.com/BanzaiMan/travis_production_test --echo
travis_cmd rsync\ -az\ \$\{TRAVIS_BUILD_DIR\}/\ \$HOME/gopath/src/github.com/BanzaiMan/travis_production_test/ --echo
travis_cmd export\ TRAVIS_BUILD_DIR\=\$HOME/gopath/src/github.com/BanzaiMan/travis_production_test --echo
travis_cmd cd\ \$HOME/gopath/src/github.com/BanzaiMan/travis_production_test --assert --echo
travis_cmd gimme\ version --echo
travis_cmd go\ version --echo
travis_fold start go.env
travis_cmd go\ env --echo
travis_fold end go.env
travis_fold start install
travis_cmd true --assert --echo --timing
travis_fold end install
travis_cmd true --echo --timing
travis_result $?
echo -e "\nDone. Your build exited with $TRAVIS_TEST_RESULT."
travis_terminate $TRAVIS_TEST_RESULT