Add comprehensive Firebird smoking to travis
[dbsrgits/DBIx-Class.git] / maint / travis-ci_prepare_env
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
9 set -e
10
11 if [[ "$TRAVIS" != "true" ]] ; then
12   echo "Running this script makes no sense outside of travis-ci"
13   exit 1
14 fi
15
16 #
17 # Current dir is the root of the DBIC checkout (make sure to
18 # come back there if moving around before end of this script)
19 #
20 # envvars available for us:
21 #
22 # NUMTHREADS = { number}
23 #   dynamically determined amount of threads we want to run on this
24 #   smoker concurrently
25 #
26 # CLEANTEST = [ true | false ]
27 #   controls whether we simulate a "user-side" install experience
28 #   that is - no author deps and no M::I installation
29 #
30 # BREWVER = { tripple dotted perl version, e.g. 5.8.3 }
31 #   brew a custom perl version such and such
32 #
33 # BREWOPTS = { string to be fed unquoted to perlbrew, e.g. -Duseithreads }
34 #   build options for perlbrew
35 #
36
37 if [[ -n "$BREWVER" ]] ; then
38   # if this is not master and not a smoke/ branch - cancel all testing
39   if [[ "$TRAVIS_BRANCH" =~ "topic/" ]]; then
40     export SHORT_CIRCUIT_SMOKE=1
41     sleep 20  # give the console time to attach, otherwise it hangs
42     return  # this is like an `exit 0` in sourcing
43   fi
44
45   perlbrew install --as $BREWVER --notest $BREWOPTS -j $NUMTHREADS perl-$BREWVER
46   perlbrew use $BREWVER
47 fi
48
49 export PERL_MM_USE_DEFAULT=1 PERL_MM_NONINTERACTIVE=1 PERL_AUTOINSTALL_PREFER_CPAN=1
50 export PERL_CPANM_OPT="$( echo $PERL_CPANM_OPT | sed 's/--skip-satisfied//' )"
51
52 installdeps() {
53   if [[ -z "$@" ]] ; then return; fi
54
55   # The reason we do things so "non-interactively" is that xargs -P will have the
56   # latest cpanm instance overwrite the buildlog. There seems to be no way to
57   # specify a custom buildlog, hence we just collect the verbose output
58   # and display it in case of failure
59   echo -n "Installing $@... "
60   if ! OUT=$( echo "$@" | xargs -n 1 -P $NUMTHREADS cpanm --verbose --no-interactive --notest --no-man-pages 2>&1 ) ; then
61     EX=$?
62     echo "FAILED !!!"
63     echo "$OUT"
64     exit $?
65   else
66     echo "done."
67   fi
68 }
69
70 # Install *hard dep* modules that typically appear in more than one dep
71 #
72 # *NEVER* add optional depenencies here - will make CLEANTEST=true smokes useless
73 #
74 # do it in several passes to minimize amount of cross-deps installing multiple
75 # times, and to avoid module re-architecture breaking another install
76 # (e.g. once Carp is upgraded there's no more Carp::Heavy)
77 #
78 installdeps $(cpanm --notest --quiet --showdeps Module::Build)
79 installdeps Test::Exception Test::Fatal Module::Runtime Carp
80 installdeps Sub::Name multidimensional namespace::clean Class::XSAccessor MRO::Compat
81 installdeps DBI Moo Class::Accessor::Grouped
82
83 # configure CPAN.pm - older versions get tickled by M::AI and
84 # go into an endless loop when trying to autoconf themselves
85 # we are not *supposed* to actually use it, this is just a
86 # precaution
87 perl -e '
88   require CPAN;
89   require CPAN::FirstTime;
90   *CPAN::FirstTime::conf_sites = sub {};
91   CPAN::Config->load;
92   $CPAN::Config->{urllist} = [ "http://cpan.cpantesters.org/" ];
93   CPAN::Config->commit;
94 ' &> /dev/null
95
96 if [[ "$CLEANTEST" = "true" ]]; then
97   # get the last inc/ off cpan - we will get rid of MI
98   # soon enough, but till then this will do
99   # the point is to have a *really* clean perl (the ones
100   # we build are guaranteed to be clean, without side
101   # effects from travis preinstalls)
102   #
103   # FIXME - not yet implemented - not sure how to reliably
104   # feed to wget this location: http://cpansearch.perl.org/src/GETTY/DBIx-Class-0.08204/inc/
105   echo TODOOOO - M::I is not supposed to be installed here - this test is useless now
106   installdeps Module::Install
107 else
108   # we will be running all tests - preinstall MOAR stuff, run basic tests using SQLT
109   # and set up whatever databases necessary
110   installdeps Module::Install DateTime::Format::Strptime MooseX::Types JSON::Any Class::DBI
111
112   export DBICTEST_SQLT_DEPLOY=1
113
114 ### apt-get invocation - faster to grab everything at once
115   #
116   # FIXME these debconf lines should automate the firebird config but do not :(((
117   sudo bash -c 'echo -e "firebird2.5-super\tshared/firebird/enabled\tboolean\ttrue" | debconf-set-selections'
118   sudo bash -c 'echo -e "firebird2.5-super\tshared/firebird/sysdba_password/new_password\tpassword\t123" | debconf-set-selections'
119
120   sudo apt-get install -y memcached firebird2.5-super firebird2.5-dev expect
121
122 ### memcached
123   export DBICTEST_MEMCACHED=127.0.0.1:11211
124
125 ### mysql
126   mysql -e 'create database dbic_test;'
127   export DBICTEST_MYSQL_DSN='dbi:mysql:database=dbic_test;host=127.0.0.1'
128   export DBICTEST_MYSQL_USER=root
129
130 ### pg
131   psql -c 'create database dbic_test;' -U postgres
132   export DBICTEST_PG_DSN='dbi:Pg:database=dbic_test;host=127.0.0.1'
133   export DBICTEST_PG_USER=postgres
134
135 ### firebird
136   # poor man's deb config
137   echo -n "Re-configuring firebird... "
138   if ! OUT=$(
139     sync
140     DEBIAN_FRONTEND=text sudo expect -c '
141       spawn dpkg-reconfigure --frontend=text firebird2.5-super
142       expect "Enable Firebird server?"
143       send "\177\177\177\177yes\r"
144       expect "Password for SYSDBA"
145       send "123\r"
146       sleep 1
147       wait
148       sleep 1
149     '
150     # restart the server for good measure
151     sudo /etc/init.d/firebird2.5-super stop || true
152     sudo /etc/init.d/firebird2.5-super start
153   ) ; then
154     EX=$?
155     echo "FAILED !!!"
156     echo "$OUT"
157     exit $?
158   else
159     echo "done."
160   fi
161
162   # creating testdb
163   sudo isql-fb -u sysdba -p 123 <<< "CREATE DATABASE '/var/lib/firebird/2.5/data/dbic_test.fdb';"
164
165   # the official version is full of 5.10-isms, but works perfectly fine on 5.8
166   # pull in our patched copy
167   git clone https://github.com/dbsrgits/perl-dbd-firebird-5.8.git ~/dbd-firebird
168
169   # the official version is very much outdated and does not compile on 5.14+
170   # use this rather updated source tree (needs to go to PAUSE):
171   # https://github.com/pilcrow/perl-dbd-interbase
172   git clone https://github.com/dbsrgits/perl-dbd-interbase ~/dbd-interbase
173
174   installdeps ~/dbd-interbase/ ~/dbd-firebird/
175
176   export DBICTEST_FIREBIRD_DSN=dbi:Firebird:dbname=/var/lib/firebird/2.5/data/dbic_test.fdb
177   export DBICTEST_FIREBIRD_USER=SYSDBA
178   export DBICTEST_FIREBIRD_PASS=123
179
180   export DBICTEST_FIREBIRD_INTERBASE_DSN=dbi:InterBase:dbname=/var/lib/firebird/2.5/data/dbic_test.fdb
181   export DBICTEST_FIREBIRD_INTERBASE_USER=SYSDBA
182   export DBICTEST_FIREBIRD_INTERBASE_PASS=123
183
184 ### oracle
185   # FIXME: todo
186   #DBICTEST_ORA_DSN=dbi:Oracle:host=localhost;sid=XE
187   #DBICTEST_ORA_USER=dbic_test
188   #DBICTEST_ORA_PASS=123
189   #DBICTEST_ORA_EXTRAUSER_DSN=dbi:Oracle:host=localhost;sid=XE
190   #DBICTEST_ORA_EXTRAUSER_USER=dbic_test_extra
191   #DBICTEST_ORA_EXTRAUSER_PASS=123
192   #ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client
193 fi
194
195 # install the rest
196 perl Makefile.PL
197 installdeps $(make listalldeps)
198
199 # announce what are we running
200 perl -V
201 echo "Using $NUMTHREADS Travis-CI concurrent processes"
202
203 # make sure we got everything we need
204 perl Makefile.PL &> /dev/null
205 if [[ -n "$(make listdeps)" ]] ; then
206   echo "Not all deps installed - something went wrong :("
207   make listdeps
208   exit 1
209 fi