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