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 |
29 | $(sudo df -h) |
30 | |
31 | $(mount | grep '^/') |
32 | |
33 | = Kernel info |
34 | $(uname -a) |
35 | |
36 | = Network Configuration |
37 | $(ip addr) |
38 | |
39 | = Network Sockets Status |
40 | $(sudo netstat -an46p | grep -Pv '\s(CLOSING|(FIN|TIME|CLOSE)_WAIT.?|LAST_ACK)\s') |
41 | |
42 | = Processlist |
43 | $(sudo ps fuxa) |
44 | |
45 | = Environment |
46 | $(env | grep -P 'TEST|HARNESS|MAKE|TRAVIS|PERL|DBIC' | LC_ALL=C sort | cat -v) |
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" |
78 | fi |
4242985f |
79 | |
b58ecb01 |
80 | return $LASTEXIT |
81 | else |
82 | echo_err "done (took ${DELTA_TIME}s)" |
83 | fi |
84 | } |
85 | |
003e97c5 |
86 | apt_install() { |
87 | # flatten |
88 | pkgs="$@" |
89 | |
003e97c5 |
90 | run_or_err "Installing Debian APT packages: $pkgs" "sudo apt-get install --allow-unauthenticated --no-install-recommends -y $pkgs" |
91 | } |
92 | |
b58ecb01 |
93 | extract_prereqs() { |
71dd2ecc |
94 | # once --verbose is set, --no-verbose can't disable it |
95 | # do this by hand |
b2435630 |
96 | local PERL_CPANM_OPT="$( echo $PERL_CPANM_OPT | sed 's/--verbose\s*//' )" |
71dd2ecc |
97 | |
b58ecb01 |
98 | # hack-hack-hack |
99 | LASTEXIT=0 |
100 | COMBINED_OUT="$( { stdout="$(cpanm --quiet --scandeps --format tree "$@")" ; } 2>&1; echo "!!!STDERRSTDOUTSEPARATOR!!!$stdout")" \ |
101 | || LASTEXIT=$? |
102 | |
103 | OUT=${COMBINED_OUT#*!!!STDERRSTDOUTSEPARATOR!!!} |
777447e9 |
104 | ERR=${COMBINED_OUT%!!!STDERRSTDOUTSEPARATOR!!!*} |
b58ecb01 |
105 | |
50e644e5 |
106 | if [[ "$LASTEXIT" != "0" ]] ; then |
4242985f |
107 | echo_err "Error occured (exit code $LASTEXIT) retrieving dependencies of $@:" |
108 | echo_err "$ERR" |
109 | echo_err "$OUT" |
b58ecb01 |
110 | exit 1 |
111 | fi |
112 | |
777447e9 |
113 | # throw away warnings, up-to-date diag, ascii art, convert to modnames |
114 | PQ=$(perl -p -e ' |
115 | s/^.*?is up to date.*$//; |
116 | s/^\!.*//; |
117 | s/^[^a-z]+//i; |
118 | s/\-[^\-]+$/ /; # strip version part |
119 | s/\-/::/g |
120 | ' <<< "$OUT") |
f207111d |
121 | |
122 | # throw away what was in $@ |
123 | for m in "$@" ; do |
124 | PQ=$( perl -p -e 's/(?:\s|^)\Q'"$m"'\E(?:\s|$)/ /mg' <<< "$PQ") |
125 | done |
126 | |
127 | # RV |
128 | echo "$PQ" |
b58ecb01 |
129 | } |
130 | |
131 | parallel_installdeps_notest() { |
132 | if [[ -z "$@" ]] ; then return; fi |
133 | |
4242985f |
134 | # one module spec per line |
fe92f179 |
135 | MODLIST="$(printf '%s\n' "$@" | sort -R)" |
b58ecb01 |
136 | |
23905f5f |
137 | # We want to trap the output of each process and serially append them to |
138 | # each other as opposed to just dumping a jumbled up mass-log that would |
139 | # need careful unpicking by a human |
140 | # |
141 | # While cpanm does maintain individual buildlogs in more recent versions, |
142 | # we are not terribly interested in trying to figure out which log is which |
143 | # dist. The verbose-output + trap STDIO technique is vastly superior in this |
144 | # particular case |
10e248bf |
145 | # |
146 | # Explanation of inline args: |
147 | # |
148 | # [09:38] <T> you need a $0 |
149 | # [09:38] <G> hence the _ |
150 | # [09:38] <G> bash -c '...' _ |
151 | # [09:39] <T> I like -- because it's the magic that gnu getopts uses for somethign else |
152 | # [09:39] <G> or --, yes |
153 | # [09:39] <T> ribasushi: you could put "giant space monkey penises" instead of "--" and it would work just as well |
154 | # |
4242985f |
155 | run_or_err "Installing (without testing) $(echo $MODLIST)" \ |
156 | "echo \\ |
157 | \"$MODLIST\" \\ |
5ac4a96d |
158 | | xargs -d '\\n' -n 1 -P $VCPU_USE bash -c \\ |
83da25f0 |
159 | 'OUT=\$(maint/getstatus $TIMEOUT_CMD cpanm --notest \"\$@\" 2>&1 ) || (LASTEXIT=\$?; echo \"\$OUT\"; exit \$LASTEXIT)' \\ |
4242985f |
160 | 'giant space monkey penises' |
10e248bf |
161 | " |
b58ecb01 |
162 | } |
163 | |
579472df |
164 | installdeps() { |
165 | if [[ -z "$@" ]] ; then return; fi |
166 | |
47749813 |
167 | MODLIST=$(printf "%q " "$@" | perl -pe 's/^\s+|\s+$//g') |
579472df |
168 | |
169 | local -x HARNESS_OPTIONS |
170 | |
5ac4a96d |
171 | HARNESS_OPTIONS="j$VCPU_USE" |
579472df |
172 | |
47749813 |
173 | if ! run_or_err "Attempting install of $# modules under parallel ($HARNESS_OPTIONS) testing ($MODLIST)" "_dep_inst_with_test $MODLIST" quiet_fail ; then |
174 | local errlog="failed after ${DELTA_TIME}s Exit:$LASTEXIT Log:$(/usr/bin/nopaste -q -s Shadowcat -d "Parallel testfail" <<< "$LASTOUT")" |
175 | echo "$errlog" |
579472df |
176 | |
a9fc70ee |
177 | POSTMORTEM="$POSTMORTEM$( |
178 | echo |
47749813 |
179 | echo "Depinstall of $MODLIST under $HARNESS_OPTIONS parallel testing $errlog" |
a9fc70ee |
180 | )" |
579472df |
181 | |
182 | HARNESS_OPTIONS="" |
47749813 |
183 | run_or_err "Retrying same $# modules without parallel testing" "_dep_inst_with_test $MODLIST" |
579472df |
184 | fi |
185 | |
186 | INSTALLDEPS_OUT="${INSTALLDEPS_OUT}${LASTOUT}" |
187 | } |
188 | |
e6b373aa |
189 | _dep_inst_with_test() { |
190 | if [[ "$DEVREL_DEPS" == "true" ]] ; then |
191 | # --dev is already part of CPANM_OPT |
47749813 |
192 | LASTCMD="$TIMEOUT_CMD cpanm $@" |
6bb14e9b |
193 | $LASTCMD 2>&1 || return 1 |
e6b373aa |
194 | else |
47749813 |
195 | LASTCMD="$TIMEOUT_CMD cpan $@" |
6bb14e9b |
196 | $LASTCMD 2>&1 || return 1 |
579472df |
197 | |
e6b373aa |
198 | # older perls do not have a CPAN which can exit with error on failed install |
199 | for m in "$@"; do |
200 | if ! perl -e ' |
579472df |
201 | |
2c657cb2 |
202 | $ARGV[0] =~ s/-TRIAL\.//; |
203 | |
647da28e |
204 | my $mod = ( |
2c657cb2 |
205 | # abuse backtrack |
206 | $ARGV[0] =~ m{ / .*? ( [^/]+ ) $ }x |
579472df |
207 | ? do { my @p = split (/\-/, $1); pop @p; join "::", @p } |
208 | : $ARGV[0] |
647da28e |
209 | ); |
210 | |
211 | $mod = q{List::Util} if $mod eq q{Scalar::List::Utils}; |
212 | |
213 | eval qq{require($mod)} or ( print $@ and exit 1) |
579472df |
214 | |
e6b373aa |
215 | ' "$m" 2> /dev/null ; then |
216 | echo -e "$m installation seems to have failed" |
217 | return 1 |
218 | fi |
219 | done |
220 | fi |
579472df |
221 | } |
222 | |
fb954d9d |
223 | # Idea stolen from |
224 | # https://github.com/kentfredric/Dist-Zilla-Plugin-Prereqs-MatchInstalled-All/blob/master/maint-travis-ci/sterilize_env.pl |
225 | # Only works on 5.12+ (where sitelib was finally properly fixed) |
226 | purge_sitelib() { |
3a554b66 |
227 | echo_err "$(tstamp) Sterilizing the Perl installation (cleaning up sitelib)" |
fb954d9d |
228 | |
229 | if perl -M5.012 -e1 &>/dev/null ; then |
230 | |
fb954d9d |
231 | perl -M5.012 -MConfig -MFile::Find -e ' |
232 | my $sitedirs = { |
233 | map { $Config{$_} => 1 } |
234 | grep { $_ =~ /site(lib|arch)exp$/ } |
235 | keys %Config |
236 | }; |
237 | find({ bydepth => 1, no_chdir => 1, follow_fast => 1, wanted => sub { |
238 | ! $sitedirs->{$_} and ( -d _ ? rmdir : unlink ) |
239 | } }, keys %$sitedirs ) |
240 | ' |
3a554b66 |
241 | else |
242 | |
243 | cl_fn="/tmp/${TRAVIS_BUILD_ID}_Module_CoreList.pm"; |
244 | |
245 | [[ -s "$cl_fn" ]] || run_or_err \ |
246 | "Downloading latest Module::CoreList" \ |
247 | "curl -s --compress -o '$cl_fn' https://api.metacpan.org/source/Module::CoreList" |
248 | |
249 | perl -0777 -Ilib -MDBIx::Class::Optional::Dependencies -e ' |
250 | |
251 | # this is horrible, but really all we want is "has this ever been used" |
252 | # so a grep without a load is quite legit (and horrible) |
253 | my $mcl_source = <>; |
254 | |
255 | my @all_possible_never_been_core_modpaths = map |
256 | { (my $mp = $_ . ".pm" ) =~ s|::|/|g; $mp } |
257 | grep |
258 | { $mcl_source !~ / ^ \s+ \x27 $_ \x27 \s* \=\> /mx } |
113087b7 |
259 | ( |
260 | qw( |
261 | Module::Build::Tiny |
262 | ), |
263 | keys %{ DBIx::Class::Optional::Dependencies->modreq_list_for([ |
264 | keys %{ DBIx::Class::Optional::Dependencies->req_group_list } |
265 | ])} |
266 | ) |
3a554b66 |
267 | ; |
268 | |
269 | # now that we have the list we can go ahead and destroy every single one |
270 | # of these modules without being concerned about breaking the base ability |
271 | # to install things |
272 | for my $mp ( sort { lc($a) cmp lc($b) } @all_possible_never_been_core_modpaths ) { |
273 | for my $incdir (@INC) { |
274 | -e "$incdir/$mp" |
275 | and |
276 | unlink "$incdir/$mp" |
277 | and |
278 | print "Nuking $incdir/$mp\n" |
279 | } |
280 | } |
281 | ' "$cl_fn" |
282 | |
fb954d9d |
283 | fi |
284 | } |
285 | |
286 | |
b58ecb01 |
287 | CPAN_is_sane() { perl -MCPAN\ 1.94_56 -e 1 &>/dev/null ; } |
f207111d |
288 | |
289 | CPAN_supports_BUILDPL() { perl -MCPAN\ 1.9205 -e1 &>/dev/null; } |