This repository has been archived by the owner on Feb 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtravis-run-run.sh
190 lines (147 loc) · 4.21 KB
/
travis-run-run.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
# Copyright (C) 2014 Daniel Gröber <dxld ÄT darkboxed DOT org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This script will be sourced by travis-run
if [ ! -e .travis.yml ]; then
echo "Error: .travis.yml does not exist.">&2
exit 1
fi
if [ "$1" ]; then
BUILD_ID="$1"; shift
else
unset BUILD_ID
fi
if [ "$1" ]; then
error "Error: Unexpected arguments: \`$@'"
exit 1
fi
CANCELLED=false
if [ ! "$OPT_KEEP" ]; then
trap '$INITIALIZED && CANCELLED=true && trap - INT && echo && backend_end '"$OPT_VM_NAME"'' INT
trap '$INITIALIZED && ! "$CANCELLED" && backend_end '"$OPT_VM_NAME" EXIT
trap '$INITIALIZED && backend_end '"$OPT_VM_NAME" TERM
backend_end "$OPT_VM_NAME"
fi
INITIALIZED=false
init () {
"$INITIALIZED" && return
INITIALIZED=true
backend_init "$OPT_VM_NAME"
if [ $? -ne 0 ]; then
echo "Starting VM failed">&2
exit 1
fi
}
run_tests () {
label="$1"
cfg="$2"
local script
script=$(printf '%s\n' "$cfg" \
| err2null backend_run_script "$OPT_VM_NAME" --build)
RV=$?
if $CANCELLED; then
debug "Generating build script cancelled." >&2
return 1
else
if [ $RV != 0 ]; then
info "Error: Generating build script failed." >&2
return 1
fi
fi
# Save environment just before exiting so we can restore it when launching
# the debugging shell
travis_terminate=$(cat <<EOF
#!/bin/bash
travis_terminate() {
env | sed -e '/PWD\|OLDPWD/d' -e 's/\(.*\)=\(.*\)/export \1="\2"/' >> ~/.profile;
pkill -9 -P \$$ &> /dev/null || true;
exit \$1;
};
EOF
)
#remove definition of travis_terminate
local script
script=$(printf '%s\n' "$script" \
| sed '/travis_terminate() {/,/}/d' \
| sed '/^#!/d' \
| sed '/resolv.conf/d')
script="${travis_terminate} ${script}"
mkdir -p ".travis-run"
fifo .travis-run/.run-fifo
printf '%s' "$script" | backend_run "$OPT_VM_NAME" copy -- bash \
> .travis-run/.run-fifo 2>&1 &
BUILD_PID=$!
# 1) the build script doesn't terminate it's ANSI colors
# 2) remove lone CR's (they use them for folding metadata)
perl -pe '$|=1; s/(\x1b\[[^m]+.*)/\1\x1b[0m/g; s/\r/\n/g' \
< .travis-run/.run-fifo 1>&2 &
wait $!
wait $BUILD_PID
RV=$?
unset BUILD_PID
if ! $CANCELLED; then
if [ $RV -ne 0 ]; then
error "Build failed, please investigate." >&2
info "Current build: \"$label\""
backend_run "$OPT_VM_NAME" nocopy
rm -f ".travis-run/.run-fifo"
return 1
fi
info "Build Succeeded :)\n\n\n" >&2
else
debug "Build cancelled :(\n\n\n"
rm -f ".travis-run/.run-fifo"
return 1
fi
}
##################################################
if ! backend_vm_exists "$OPT_VM_NAME"; then
error "travis-run: Build VM \`$OPT_VM_NAME' doesn't exists."
error
error "Please run \`travis-run create' to create one."
exit 1
fi
if [ $OPT_SHELL ]; then
init
backend_run "$OPT_VM_NAME" copy
exit
fi
cfgs=$(backend_run_script "$OPT_VM_NAME" < .travis.yml)
id=0
while true; do
line="$(printf '%s' "$cfgs" | sed '1q')"
cfgs="$(printf '%s' "$cfgs" | sed '1d')"
[ ! "$line" ] && break
unset label; unset cfg
eval $(printf '%s' "$line")
[ ! "$cfg" ] && continue
if [ "$BUILD_ID" = "$(printf "$BUILD_ID" | tr -dc '[0-9]')" ]; then
num=1
else
num=0
fi
if [ ! "$BUILD_ID" ] \
|| [ x"$BUILD_ID" = x"$label" ] \
|| [ x"$num" = x"1" -a x"$BUILD_ID" = x"$id" ]
then
init
info "Running build: \"$label\""
run_tests "$label" "$cfg"
if [ $? -ne 0 ]; then
exit $?
fi
fi
id=$(($id + 1))
done
exit 0