Expand comments, move core dep install before RDBMS setup (no func. changes)
[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   # extra debian stuff
115   sudo apt-get -y install memcached firebird2.5-super
116   echo -e '\v'
117   echo
118
119   # memcached
120   export DBICTEST_MEMCACHED=127.0.0.1:11211
121
122   # mysql
123   mysql -e 'create database dbic_test;'
124   export DBICTEST_MYSQL_DSN='dbi:mysql:database=dbic_test;host=127.0.0.1'
125   export DBICTEST_MYSQL_USER=root
126
127   # pg
128   psql -c 'create database dbic_test;' -U postgres
129   export DBICTEST_PG_DSN='dbi:Pg:database=dbic_test;host=127.0.0.1'
130   export DBICTEST_PG_USER=postgres
131
132   # firebird
133   sudo perl -pi -e 's/\=no/=yes/' /etc/default/firebird2.5
134   sudo /etc/init.d/firebird2.5-super start
135   # FIXME: todo
136   #sudo gsec -add dbic_test -pw 123
137   #export DBICTEST_FIREBIRD_DSN=dbi:Firebird:dbname=/var/lib/firebird/2.5/data/dbic_test
138   #export DBICTEST_FIREBIRD_USER=dbic_test
139   #export DBICTEST_FIREBIRD_PASS=123
140   #export DBICTEST_FIREBIRD_INTERBASE_DSN=dbi:InterBase:dbname=/var/lib/firebird/2.5/data/dbic_test
141   #export DBICTEST_FIREBIRD_INTERBASE_USER=dbic_test
142   #export DBICTEST_FIREBIRD_INTERBASE_PASS=123
143
144   # oracle
145   # FIXME: todo
146   #DBICTEST_ORA_DSN=dbi:Oracle:host=localhost;sid=XE
147   #DBICTEST_ORA_USER=dbic_test
148   #DBICTEST_ORA_PASS=123
149   #DBICTEST_ORA_EXTRAUSER_DSN=dbi:Oracle:host=localhost;sid=XE
150   #DBICTEST_ORA_EXTRAUSER_USER=dbic_test_extra
151   #DBICTEST_ORA_EXTRAUSER_PASS=123
152   #ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client
153 fi
154
155 # install the rest
156 perl Makefile.PL
157 installdeps $(make listalldeps)
158
159 # announce what are we running
160 perl -V
161 echo "Using $NUMTHREADS Travis-CI concurrent processes"
162
163 # make sure we got everything we need
164 perl Makefile.PL &> /dev/null
165 if [[ -n "$(make listdeps)" ]] ; then
166   echo "Not all deps installed - something went wrong :("
167   make listdeps
168   exit 1
169 fi