Commit | Line | Data |
b58ecb01 |
1 | #!/bin/bash |
2 | |
afeb40d2 |
3 | # "autodie" |
b58ecb01 |
4 | set -e |
5 | |
b9970637 |
6 | TEST_STDERR_LOG=/tmp/dbictest.stderr |
2a89732d |
7 | TIMEOUT_CMD="/usr/bin/timeout --kill-after=16m --signal=TERM 15m" |
b9970637 |
8 | |
b58ecb01 |
9 | echo_err() { echo "$@" 1>&2 ; } |
10 | |
11 | if [[ "$TRAVIS" != "true" ]] ; then |
12 | echo_err "Running this script makes no sense outside of travis-ci" |
13 | exit 1 |
14 | fi |
15 | |
16 | tstamp() { echo -n "[$(date '+%H:%M:%S')]" ; } |
17 | |
5c0b7a18 |
18 | ci_vm_state_text() { |
19 | echo " |
20 | ========================== CI System information ============================ |
21 | |
22 | = CPUinfo |
23 | $(perl -0777 -p -e 's/.+\n\n(?!\z)//s' < /proc/cpuinfo) |
24 | |
25 | = Meminfo |
26 | $(free -m -t) |
27 | |
28 | = Diskinfo |
36372426 |
29 | $(df -h) |
5c0b7a18 |
30 | |
31 | $(mount | grep '^/') |
32 | |
33 | = Kernel info |
34 | $(uname -a) |
35 | |
36 | = Network Configuration |
37 | $(ip addr) |
38 | |
39 | = Network Sockets Status |
36372426 |
40 | $( (sudo netstat -an46p || netstat -an46p) | grep -Pv '\s(CLOSING|(FIN|TIME|CLOSE)_WAIT.?|LAST_ACK)\s') |
5c0b7a18 |
41 | |
42 | = Processlist |
36372426 |
43 | $(ps fuxa) |
5c0b7a18 |
44 | |
45 | = Environment |
4fb8d74c |
46 | $(env | grep -P 'TEST|HARNESS|MAKE|TRAVIS|PERL|DBIC|PATH|SHELL' | LC_ALL=C sort | cat -v) |
5c0b7a18 |
47 | |
48 | = Perl in use |
49 | $(perl -V) |
50 | =============================================================================" |
51 | } |
52 | |
b58ecb01 |
53 | run_or_err() { |
54 | echo_err -n "$(tstamp) $1 ... " |
55 | |
47749813 |
56 | LASTCMD="$2" |
b58ecb01 |
57 | LASTEXIT=0 |
58 | START_TIME=$SECONDS |
8f1a96a2 |
59 | |
60 | PRMETER_PIDFILE="$(tempfile)_$SECONDS" |
61 | # the double bash is to hide the job control messages |
62 | bash -c "bash -c 'echo \$\$ >> $PRMETER_PIDFILE; while true; do sleep 10; echo -n \"\${SECONDS}s ... \"; done' &" |
63 | |
47749813 |
64 | LASTOUT=$( eval "$2" 2>&1 ) || LASTEXIT=$? |
8f1a96a2 |
65 | |
66 | # stop progress meter |
67 | for p in $(cat "$PRMETER_PIDFILE"); do kill $p ; done |
68 | |
b58ecb01 |
69 | DELTA_TIME=$(( $SECONDS - $START_TIME )) |
70 | |
71 | if [[ "$LASTEXIT" != "0" ]] ; then |
47749813 |
72 | if [[ -z "$3" ]] ; then |
73 | echo_err "FAILED !!! (after ${DELTA_TIME}s)" |
74 | echo_err "Command executed:" |
75 | echo_err "$LASTCMD" |
76 | echo_err "STDOUT+STDERR:" |
77 | echo_err "$LASTOUT" |
8a684aea |
78 | if [[ "$(dmesg)" =~ $( echo "\\bOOM\\b" ) ]] ; then |
79 | echo_err "=== dmesg ringbuffer" |
80 | echo_err "$(dmesg)" |
81 | fi |
47749813 |
82 | fi |
4242985f |
83 | |
b58ecb01 |
84 | return $LASTEXIT |
85 | else |
86 | echo_err "done (took ${DELTA_TIME}s)" |
87 | fi |
88 | } |
89 | |
003e97c5 |
90 | apt_install() { |
91 | # flatten |
92 | pkgs="$@" |
93 | |
003e97c5 |
94 | run_or_err "Installing Debian APT packages: $pkgs" "sudo apt-get install --allow-unauthenticated --no-install-recommends -y $pkgs" |
95 | } |
96 | |
b58ecb01 |
97 | extract_prereqs() { |
71dd2ecc |
98 | # once --verbose is set, --no-verbose can't disable it |
99 | # do this by hand |
b2435630 |
100 | local PERL_CPANM_OPT="$( echo $PERL_CPANM_OPT | sed 's/--verbose\s*//' )" |
71dd2ecc |
101 | |
b58ecb01 |
102 | # hack-hack-hack |
103 | LASTEXIT=0 |
104 | COMBINED_OUT="$( { stdout="$(cpanm --quiet --scandeps --format tree "$@")" ; } 2>&1; echo "!!!STDERRSTDOUTSEPARATOR!!!$stdout")" \ |
105 | || LASTEXIT=$? |
106 | |
107 | OUT=${COMBINED_OUT#*!!!STDERRSTDOUTSEPARATOR!!!} |
777447e9 |
108 | ERR=${COMBINED_OUT%!!!STDERRSTDOUTSEPARATOR!!!*} |
b58ecb01 |
109 | |
50e644e5 |
110 | if [[ "$LASTEXIT" != "0" ]] ; then |
4242985f |
111 | echo_err "Error occured (exit code $LASTEXIT) retrieving dependencies of $@:" |
112 | echo_err "$ERR" |
113 | echo_err "$OUT" |
b58ecb01 |
114 | exit 1 |
115 | fi |
116 | |
777447e9 |
117 | # throw away warnings, up-to-date diag, ascii art, convert to modnames |
118 | PQ=$(perl -p -e ' |
119 | s/^.*?is up to date.*$//; |
120 | s/^\!.*//; |
121 | s/^[^a-z]+//i; |
122 | s/\-[^\-]+$/ /; # strip version part |
123 | s/\-/::/g |
124 | ' <<< "$OUT") |
f207111d |
125 | |
126 | # throw away what was in $@ |
127 | for m in "$@" ; do |
128 | PQ=$( perl -p -e 's/(?:\s|^)\Q'"$m"'\E(?:\s|$)/ /mg' <<< "$PQ") |
129 | done |
130 | |
131 | # RV |
132 | echo "$PQ" |
b58ecb01 |
133 | } |
134 | |
135 | parallel_installdeps_notest() { |
136 | if [[ -z "$@" ]] ; then return; fi |
137 | |
64d48e19 |
138 | is_cperl && echo_err "cpanminus is not yet usable on cperl" && exit 1 |
139 | |
4242985f |
140 | # one module spec per line |
fe92f179 |
141 | MODLIST="$(printf '%s\n' "$@" | sort -R)" |
b58ecb01 |
142 | |
23905f5f |
143 | # We want to trap the output of each process and serially append them to |
144 | # each other as opposed to just dumping a jumbled up mass-log that would |
145 | # need careful unpicking by a human |
146 | # |
147 | # While cpanm does maintain individual buildlogs in more recent versions, |
148 | # we are not terribly interested in trying to figure out which log is which |
149 | # dist. The verbose-output + trap STDIO technique is vastly superior in this |
150 | # particular case |
10e248bf |
151 | # |
152 | # Explanation of inline args: |
153 | # |
154 | # [09:38] <T> you need a $0 |
155 | # [09:38] <G> hence the _ |
156 | # [09:38] <G> bash -c '...' _ |
157 | # [09:39] <T> I like -- because it's the magic that gnu getopts uses for somethign else |
158 | # [09:39] <G> or --, yes |
159 | # [09:39] <T> ribasushi: you could put "giant space monkey penises" instead of "--" and it would work just as well |
160 | # |
4242985f |
161 | run_or_err "Installing (without testing) $(echo $MODLIST)" \ |
162 | "echo \\ |
163 | \"$MODLIST\" \\ |
5ac4a96d |
164 | | xargs -d '\\n' -n 1 -P $VCPU_USE bash -c \\ |
83da25f0 |
165 | 'OUT=\$(maint/getstatus $TIMEOUT_CMD cpanm --notest \"\$@\" 2>&1 ) || (LASTEXIT=\$?; echo \"\$OUT\"; exit \$LASTEXIT)' \\ |
4242985f |
166 | 'giant space monkey penises' |
10e248bf |
167 | " |
b58ecb01 |
168 | } |
169 | |
4fb8d74c |
170 | export -f parallel_installdeps_notest run_or_err echo_err tstamp |
171 | |
579472df |
172 | installdeps() { |
173 | if [[ -z "$@" ]] ; then return; fi |
174 | |
47749813 |
175 | MODLIST=$(printf "%q " "$@" | perl -pe 's/^\s+|\s+$//g') |
579472df |
176 | |
177 | local -x HARNESS_OPTIONS |
178 | |
5ac4a96d |
179 | HARNESS_OPTIONS="j$VCPU_USE" |
579472df |
180 | |
47749813 |
181 | if ! run_or_err "Attempting install of $# modules under parallel ($HARNESS_OPTIONS) testing ($MODLIST)" "_dep_inst_with_test $MODLIST" quiet_fail ; then |
36372426 |
182 | local errlog="failed after ${DELTA_TIME}s Exit:$LASTEXIT Log:$(/usr/bin/perl /usr/bin/nopaste -q -s Shadowcat -d "Parallel testfail" <<< "$LASTOUT")" |
47749813 |
183 | echo "$errlog" |
579472df |
184 | |
a9fc70ee |
185 | POSTMORTEM="$POSTMORTEM$( |
186 | echo |
47749813 |
187 | echo "Depinstall of $MODLIST under $HARNESS_OPTIONS parallel testing $errlog" |
a9fc70ee |
188 | )" |
579472df |
189 | |
190 | HARNESS_OPTIONS="" |
47749813 |
191 | run_or_err "Retrying same $# modules without parallel testing" "_dep_inst_with_test $MODLIST" |
579472df |
192 | fi |
193 | |
194 | INSTALLDEPS_OUT="${INSTALLDEPS_OUT}${LASTOUT}" |
195 | } |
196 | |
e6b373aa |
197 | _dep_inst_with_test() { |
198 | if [[ "$DEVREL_DEPS" == "true" ]] ; then |
64d48e19 |
199 | is_cperl && echo_err "cpanminus is not yet usable on cperl" && exit 1 |
200 | |
e6b373aa |
201 | # --dev is already part of CPANM_OPT |
47749813 |
202 | LASTCMD="$TIMEOUT_CMD cpanm $@" |
6bb14e9b |
203 | $LASTCMD 2>&1 || return 1 |
e6b373aa |
204 | else |
47749813 |
205 | LASTCMD="$TIMEOUT_CMD cpan $@" |
6bb14e9b |
206 | $LASTCMD 2>&1 || return 1 |
579472df |
207 | |
e6b373aa |
208 | # older perls do not have a CPAN which can exit with error on failed install |
209 | for m in "$@"; do |
210 | if ! perl -e ' |
579472df |
211 | |
2c657cb2 |
212 | $ARGV[0] =~ s/-TRIAL\.//; |
213 | |
647da28e |
214 | my $mod = ( |
2c657cb2 |
215 | # abuse backtrack |
216 | $ARGV[0] =~ m{ / .*? ( [^/]+ ) $ }x |
579472df |
217 | ? do { my @p = split (/\-/, $1); pop @p; join "::", @p } |
218 | : $ARGV[0] |
647da28e |
219 | ); |
220 | |
a223f758 |
221 | # map some install-names to a module/version combo |
222 | # serves both as a grandfathered title-less tarball, and |
223 | # as a minimum version check for upgraded core modules |
224 | my $eval_map = { |
647da28e |
225 | |
a223f758 |
226 | # this is temporary, will need something more robust down the road |
227 | # (perhaps by then Module::CoreList will be dep-free) |
228 | "Module::Build" => { ver => "0.4214" }, |
6a0bca69 |
229 | "podlators" => { mod => "Pod::Man", ver => "2.17" }, |
a223f758 |
230 | |
231 | "File::Spec" => { ver => "3.47" }, |
232 | "Cwd" => { ver => "3.47" }, |
233 | |
234 | "List::Util" => { ver => "1.42" }, |
235 | "Scalar::Util" => { ver => "1.42" }, |
236 | "Scalar::List::Utils" => { mod => "List::Util", ver => "1.42" }, |
237 | }; |
238 | |
6a0bca69 |
239 | my $m = $eval_map->{$mod}{mod} || $mod; |
a223f758 |
240 | |
6a0bca69 |
241 | eval( |
242 | "require $m" |
a223f758 |
243 | |
244 | . |
245 | |
246 | ($eval_map->{$mod}{ver} |
6a0bca69 |
247 | ? "; $m->VERSION(\$eval_map->{\$mod}{ver}) " |
a223f758 |
248 | : "" |
249 | ) |
250 | |
251 | . |
252 | |
253 | "; 1" |
254 | ) |
255 | or |
256 | ( print $@ and exit 1) |
579472df |
257 | |
e6b373aa |
258 | ' "$m" 2> /dev/null ; then |
259 | echo -e "$m installation seems to have failed" |
260 | return 1 |
261 | fi |
262 | done |
263 | fi |
579472df |
264 | } |
265 | |
fb954d9d |
266 | # Idea stolen from |
267 | # https://github.com/kentfredric/Dist-Zilla-Plugin-Prereqs-MatchInstalled-All/blob/master/maint-travis-ci/sterilize_env.pl |
268 | # Only works on 5.12+ (where sitelib was finally properly fixed) |
269 | purge_sitelib() { |
3a554b66 |
270 | echo_err "$(tstamp) Sterilizing the Perl installation (cleaning up sitelib)" |
fb954d9d |
271 | |
272 | if perl -M5.012 -e1 &>/dev/null ; then |
273 | |
fb954d9d |
274 | perl -M5.012 -MConfig -MFile::Find -e ' |
275 | my $sitedirs = { |
276 | map { $Config{$_} => 1 } |
277 | grep { $_ =~ /site(lib|arch)exp$/ } |
278 | keys %Config |
279 | }; |
280 | find({ bydepth => 1, no_chdir => 1, follow_fast => 1, wanted => sub { |
281 | ! $sitedirs->{$_} and ( -d _ ? rmdir : unlink ) |
282 | } }, keys %$sitedirs ) |
283 | ' |
3a554b66 |
284 | else |
285 | |
286 | cl_fn="/tmp/${TRAVIS_BUILD_ID}_Module_CoreList.pm"; |
287 | |
288 | [[ -s "$cl_fn" ]] || run_or_err \ |
289 | "Downloading latest Module::CoreList" \ |
290 | "curl -s --compress -o '$cl_fn' https://api.metacpan.org/source/Module::CoreList" |
291 | |
292 | perl -0777 -Ilib -MDBIx::Class::Optional::Dependencies -e ' |
293 | |
294 | # this is horrible, but really all we want is "has this ever been used" |
295 | # so a grep without a load is quite legit (and horrible) |
296 | my $mcl_source = <>; |
297 | |
298 | my @all_possible_never_been_core_modpaths = map |
299 | { (my $mp = $_ . ".pm" ) =~ s|::|/|g; $mp } |
300 | grep |
301 | { $mcl_source !~ / ^ \s+ \x27 $_ \x27 \s* \=\> /mx } |
113087b7 |
302 | ( |
303 | qw( |
304 | Module::Build::Tiny |
305 | ), |
306 | keys %{ DBIx::Class::Optional::Dependencies->modreq_list_for([ |
307 | keys %{ DBIx::Class::Optional::Dependencies->req_group_list } |
308 | ])} |
309 | ) |
3a554b66 |
310 | ; |
311 | |
312 | # now that we have the list we can go ahead and destroy every single one |
313 | # of these modules without being concerned about breaking the base ability |
314 | # to install things |
315 | for my $mp ( sort { lc($a) cmp lc($b) } @all_possible_never_been_core_modpaths ) { |
316 | for my $incdir (@INC) { |
317 | -e "$incdir/$mp" |
318 | and |
319 | unlink "$incdir/$mp" |
320 | and |
321 | print "Nuking $incdir/$mp\n" |
322 | } |
323 | } |
324 | ' "$cl_fn" |
325 | |
fb954d9d |
326 | fi |
327 | } |
328 | |
329 | |
b58ecb01 |
330 | CPAN_is_sane() { perl -MCPAN\ 1.94_56 -e 1 &>/dev/null ; } |
f207111d |
331 | |
332 | CPAN_supports_BUILDPL() { perl -MCPAN\ 1.9205 -e1 &>/dev/null; } |
36372426 |
333 | |
334 | have_sudo() { sudo /bin/true &>/dev/null ; } |
64d48e19 |
335 | |
336 | is_cperl() { [[ "$BREWVER" =~ $( echo -n "^cperl-" ) ]] ; } |