More information about the test env we are about to use
[dbsrgits/DBIx-Class.git] / maint / travis-ci_prepare_env
CommitLineData
d70070c9 1#!/bin/bash
2
3# * The way .travis.yml is fed to the command controller is idiotic - it
4# makes using multiline `bash -c` statements impossible. Therefore to
5# aid readability (our travis logic is rather complex), the bulk of
6# functionality is moved to a script. More about the problem here:
7# https://github.com/travis-ci/travis-ci/issues/497
8
9set -e
10
44020f08 11echo_err() { echo "$@" 1>&2 ; }
12
13tstamp() { echo -n "[$(date '+%H:%M:%S')]" ; }
14
15run_or_err() {
16 echo_err -n "$(tstamp) $1 ... "
17
18 LASTOUT=$( bash -c "$2" 2>&1)
19 LASTEXIT=$?
20 if [[ "$LASTEXIT" != "0" ]] ; then
21 echo_err -e "FAILED !!!\nCommand executed:\n$2\nSTDOUT+STDERR:\n$LASTOUT"
22 return $LASTEXIT
23 else
24 echo_err "done."
25 fi
26}
27
d70070c9 28if [[ "$TRAVIS" != "true" ]] ; then
44020f08 29 echo_err "Running this script makes no sense outside of travis-ci"
d70070c9 30 exit 1
31fi
32
33#
34# Current dir is the root of the DBIC checkout (make sure to
35# come back there if moving around before end of this script)
36#
37# envvars available for us:
38#
39# NUMTHREADS = { number}
40# dynamically determined amount of threads we want to run on this
41# smoker concurrently
42#
43# CLEANTEST = [ true | false ]
44# controls whether we simulate a "user-side" install experience
45# that is - no author deps and no M::I installation
46#
47# BREWVER = { tripple dotted perl version, e.g. 5.8.3 }
48# brew a custom perl version such and such
49#
50# BREWOPTS = { string to be fed unquoted to perlbrew, e.g. -Duseithreads }
51# build options for perlbrew
52#
53
44020f08 54echo_err "$(tstamp) Smoke preconfiguration starting $(date)"
55
56TRAVIS_CPAN_MIRROR=$(echo "$PERL_CPANM_OPT" | grep -oP -- '--mirror\s+\S+' | head -n 1 | cut -d ' ' -f 2)
57if ! [[ "$TRAVIS_CPAN_MIRROR" =~ "http://" ]] ; then
58 echo_err "Unable to extract primary cpan mirror from PERL_CPANM_OPT - something is wrong"
59 echo_err "PERL_CPANM_OPT: $PERL_CPANM_OPT"
60 exit 1
61fi
62
63export PERL_MM_USE_DEFAULT=1 PERL_MM_NONINTERACTIVE=1 PERL_AUTOINSTALL_PREFER_CPAN=1 PERLBREW_CPAN_MIRROR="$TRAVIS_CPAN_MIRROR"
64
65# Fixup CPANM_OPT to behave more like a traditional cpan client
66export PERL_CPANM_OPT="$( echo $PERL_CPANM_OPT | sed 's/--skip-satisfied//' )"
67
d70070c9 68if [[ -n "$BREWVER" ]] ; then
c299fd65 69 # if this is not master and not a smoke/ branch - cancel all testing
70 if [[ "$TRAVIS_BRANCH" =~ "topic/" ]]; then
71 export SHORT_CIRCUIT_SMOKE=1
44020f08 72 echo_err "$(tstamp) non-smoke branch and custom perl compilation requested - bailing out"
e8e2b3bf 73 sleep 20 # give the console time to attach, otherwise it hangs
c299fd65 74 return # this is like an `exit 0` in sourcing
75 fi
76
44020f08 77 run_or_err "Compiling/installing Perl $BREWVER (without testing, may take up to 5 minutes)" \
78 "perlbrew install --as $BREWVER --notest $BREWOPTS -j $NUMTHREADS perl-$BREWVER"
79
d70070c9 80 perlbrew use $BREWVER
81fi
82
44020f08 83# configure CPAN.pm - older versions go into an endless loop
84# when trying to autoconf themselves
85CPAN_CFG_SCRIPT="
86 require CPAN;
87 require CPAN::FirstTime;
88 *CPAN::FirstTime::conf_sites = sub {};
89 CPAN::Config->load;
90 \$CPAN::Config->{urllist} = [qw{ $TRAVIS_CPAN_MIRROR }];
91 \$CPAN::Config->{halt_on_failure} = 1;
92 CPAN::Config->commit;
93"
94run_or_err "Configuring CPAN.pm" "perl -e '$CPAN_CFG_SCRIPT'"
95
96extract_prereqs() {
97 # hack-hack-hack
98 COMBINED_OUT="$( { stdout="$(cpanm --quiet --scandeps --format tree "$@")" ; } 2>&1; echo "!!!STDERRSTDOUTSEPARATOR!!!$stdout")" \
99 || LASTEXIT=$?
100
101 OUT=${COMBINED_OUT#*!!!STDERRSTDOUTSEPARATOR!!!}
102 ERR=$(grep -v " is up to date." <<< "${COMBINED_OUT%!!!STDERRSTDOUTSEPARATOR!!!*}")
103
104 [[ -n "$LASTEXIT" ]] || LASTEXIT=0
105 if [[ "$LASTEXIT" != "0" ]] || [[ -n "$ERR" ]] ; then
106 echo_err "$(echo -e "Error occured (exit code $LASTEXIT) retrieving dependencies of $@:\n$ERR\n$OUT")"
107 exit 1
108 fi
109
110 # throw away non-children (what was in $@), throw away ascii art, convert to modnames
111 perl -p -e 's/^\s*[^\\].+//; s/^[^A-Za-z]+//; s/\-[^\-]+$/ /; s/\-/::/g' <<< "$OUT"
112}
d70070c9 113
44020f08 114parallel_installdeps_notest() {
e8e2b3bf 115 if [[ -z "$@" ]] ; then return; fi
116
44020f08 117 # flatten list into one string
118 MODLIST=$(echo "$@")
119
e8e2b3bf 120 # The reason we do things so "non-interactively" is that xargs -P will have the
121 # latest cpanm instance overwrite the buildlog. There seems to be no way to
122 # specify a custom buildlog, hence we just collect the verbose output
123 # and display it in case of failure
44020f08 124 run_or_err "Installing (without testing) $MODLIST" \
125 "echo $MODLIST | xargs -n 1 -P $NUMTHREADS cpanm --verbose --no-interactive --notest --no-man-pages"
e8e2b3bf 126}
127
128# Install *hard dep* modules that typically appear in more than one dep
129#
130# *NEVER* add optional depenencies here - will make CLEANTEST=true smokes useless
131#
132# do it in several passes to minimize amount of cross-deps installing multiple
133# times, and to avoid module re-architecture breaking another install
134# (e.g. once Carp is upgraded there's no more Carp::Heavy)
135#
44020f08 136parallel_installdeps_notest $(extract_prereqs Module::Build)
137parallel_installdeps_notest Test::Exception Test::Fatal Module::Runtime Carp
138parallel_installdeps_notest Sub::Name multidimensional namespace::clean Class::XSAccessor MRO::Compat
139parallel_installdeps_notest DBI Moo Class::Accessor::Grouped
d70070c9 140
e8e2b3bf 141if [[ "$CLEANTEST" = "true" ]]; then
142 # get the last inc/ off cpan - we will get rid of MI
143 # soon enough, but till then this will do
144 # the point is to have a *really* clean perl (the ones
145 # we build are guaranteed to be clean, without side
146 # effects from travis preinstalls)
e352dd9a 147
148 # trick cpanm into executing true as shell - we just need the find+unpack
44020f08 149 run_or_err "Downloading DBIC inc/ from CPAN" \
150 "SHELL=/bin/true cpanm --look DBIx::Class"
151
152 mv ~/.cpanm/latest-build/DBIx-Class-*/inc .
e8e2b3bf 153else
154 # we will be running all tests - preinstall MOAR stuff, run basic tests using SQLT
155 # and set up whatever databases necessary
44020f08 156 parallel_installdeps_notest Module::Install DateTime::Format::Strptime MooseX::Types JSON::Any Class::DBI
e8e2b3bf 157
158 export DBICTEST_SQLT_DEPLOY=1
159
2b28f530 160### apt-get invocation - faster to grab everything at once
161 #
162 # FIXME these debconf lines should automate the firebird config but do not :(((
163 sudo bash -c 'echo -e "firebird2.5-super\tshared/firebird/enabled\tboolean\ttrue" | debconf-set-selections'
164 sudo bash -c 'echo -e "firebird2.5-super\tshared/firebird/sysdba_password/new_password\tpassword\t123" | debconf-set-selections'
165
44020f08 166 APT_PACKAGES="memcached firebird2.5-super firebird2.5-dev expect"
167 run_or_err "Installing packages ($APT_PACKAGES)" "sudo apt-get install -y $APT_PACKAGES"
d70070c9 168
2b28f530 169### memcached
d70070c9 170 export DBICTEST_MEMCACHED=127.0.0.1:11211
171
2b28f530 172### mysql
44020f08 173 run_or_err "Creating MySQL TestDB" "mysql -e 'create database dbic_test;'"
d70070c9 174 export DBICTEST_MYSQL_DSN='dbi:mysql:database=dbic_test;host=127.0.0.1'
175 export DBICTEST_MYSQL_USER=root
176
2b28f530 177### pg
44020f08 178 run_or_err "Creating PostgreSQL TestDB" "psql -c 'create database dbic_test;' -U postgres"
d70070c9 179 export DBICTEST_PG_DSN='dbi:Pg:database=dbic_test;host=127.0.0.1'
180 export DBICTEST_PG_USER=postgres
181
2b28f530 182### firebird
183 # poor man's deb config
44020f08 184 EXPECT_FB_SCRIPT='
185 spawn dpkg-reconfigure --frontend=text firebird2.5-super
186 expect "Enable Firebird server?"
187 send "\177\177\177\177yes\r"
188 expect "Password for SYSDBA"
189 send "123\r"
190 sleep 1
191 wait
192 sleep 1
193 '
194 run_or_err "Re-configuring Firebird" "
2b28f530 195 sync
44020f08 196 DEBIAN_FRONTEND=text sudo expect -c '$EXPECT_FB_SCRIPT'
197 sleep 1
47d391d5 198 sync
2b28f530 199 # restart the server for good measure
200 sudo /etc/init.d/firebird2.5-super stop || true
44020f08 201 sleep 1
202 sync
2b28f530 203 sudo /etc/init.d/firebird2.5-super start
44020f08 204 sleep 1
205 sync
206 "
2b28f530 207
208 # creating testdb
d1d19682 209 # FIXME - this step still fails from time to time >:(((
210 # has to do with the FB reconfiguration I suppose
211 # for now if it fails - simply skip FB testing
212 if run_or_err "Creating Firebird TestDB" \
44020f08 213 "echo \"CREATE DATABASE '/var/lib/firebird/2.5/data/dbic_test.fdb';\" | sudo isql-fb -u sysdba -p 123"
d1d19682 214 then
215 # the official version is full of 5.10-isms, but works perfectly fine on 5.8
216 # pull in our patched copy
217 run_or_err "Fetching patched DBD::Firebird" \
218 "git clone https://github.com/dbsrgits/perl-dbd-firebird-5.8.git ~/dbd-firebird"
219
220 # the official version is very much outdated and does not compile on 5.14+
221 # use this rather updated source tree (needs to go to PAUSE):
222 # https://github.com/pilcrow/perl-dbd-interbase
223 run_or_err "Fetching patched DBD::InterBase" \
224 "git clone https://github.com/dbsrgits/perl-dbd-interbase ~/dbd-interbase"
225
226 parallel_installdeps_notest ~/dbd-interbase/ ~/dbd-firebird/
227
228 export DBICTEST_FIREBIRD_DSN=dbi:Firebird:dbname=/var/lib/firebird/2.5/data/dbic_test.fdb
229 export DBICTEST_FIREBIRD_USER=SYSDBA
230 export DBICTEST_FIREBIRD_PASS=123
231
232 export DBICTEST_FIREBIRD_INTERBASE_DSN=dbi:InterBase:dbname=/var/lib/firebird/2.5/data/dbic_test.fdb
233 export DBICTEST_FIREBIRD_INTERBASE_USER=SYSDBA
234 export DBICTEST_FIREBIRD_INTERBASE_PASS=123
235 fi
2b28f530 236
237### oracle
d70070c9 238 # FIXME: todo
239 #DBICTEST_ORA_DSN=dbi:Oracle:host=localhost;sid=XE
240 #DBICTEST_ORA_USER=dbic_test
241 #DBICTEST_ORA_PASS=123
242 #DBICTEST_ORA_EXTRAUSER_DSN=dbi:Oracle:host=localhost;sid=XE
243 #DBICTEST_ORA_EXTRAUSER_USER=dbic_test_extra
244 #DBICTEST_ORA_EXTRAUSER_PASS=123
245 #ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client
246fi
247
44020f08 248# generate the makefile which will have different deps depending on
249# the runmode and envvars set above
250run_or_err "Configure on current branch" "perl Makefile.PL"
d70070c9 251
44020f08 252# install the remaining dependencies
253parallel_installdeps_notest $(make listalldeps)
d70070c9 254
255# make sure we got everything we need
256perl Makefile.PL &> /dev/null
257if [[ -n "$(make listdeps)" ]] ; then
44020f08 258 echo_err "$(tstamp) Not all deps installed - something went wrong :("
d70070c9 259 make listdeps
260 exit 1
261fi
44020f08 262
263run_or_err "Prepare blib" "make pure_all"
264
265# announce what are we running
a7291faa 266echo_err "
267========================= CONFIGURATION COMPLETE ===========================
268Configuration phase seems to have taken $(date -ud "@$SECONDS" '+%H:%M:%S') (@$SECONDS)
269
270= CPUinfo
271$(perl -0777 -p -e 's/.+\n\n(?!\z)//s' < /proc/cpuinfo)
272
273= Meminfo
274$(free -m -t)
275
276= Environment
277$(env | grep -P 'TEST|TRAVIS|PERL|DBIC' | LC_ALL=C sort | cat -v)
278
279= Perl in use
280$(perl -V)
281============================================================================
282
283$(tstamp) Starting tests using $NUMTHREADS concurrent processes"