Throw away suboptimal travis CPANM env-option and tighten plans more
[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     return  # this is like an `exit 0` in sourcing
42   fi
43
44   perlbrew install --as $BREWVER --notest $BREWOPTS -j $NUMTHREADS perl-$BREWVER
45   perlbrew use $BREWVER
46 fi
47
48 export PERL_MM_USE_DEFAULT=1 PERL_MM_NONINTERACTIVE=1 PERL_AUTOINSTALL_PREFER_CPAN=1
49 export PERL_CPANM_OPT="$( echo $PERL_CPANM_OPT | sed 's/--skip-satisfied//' )"
50
51 # configure CPAN.pm - older versions get tickled by M::AI and
52 # go into an endless loop when trying to autoconf themselves
53 perl -e '
54   require CPAN;
55   require CPAN::FirstTime;
56   *CPAN::FirstTime::conf_sites = sub {};
57   CPAN::Config->load;
58   $CPAN::Config->{urllist} = [ "http://cpan.cpantesters.org/" ];
59   CPAN::Config->commit;
60 ' &> /dev/null
61
62 # if this won't be a CLEANTEST (i.e. no deps) - run basic tests using SQLT
63 # and set up whatever databases necessary
64 if [[ "$CLEANTEST" != "true" ]]; then
65   # extra debian stuff
66   sudo apt-get -y install memcached firebird2.5-super
67   echo -e '\v'
68   echo
69
70   export DBICTEST_SQLT_DEPLOY=1
71
72   # memcached
73   export DBICTEST_MEMCACHED=127.0.0.1:11211
74
75   # mysql
76   mysql -e 'create database dbic_test;'
77   export DBICTEST_MYSQL_DSN='dbi:mysql:database=dbic_test;host=127.0.0.1'
78   export DBICTEST_MYSQL_USER=root
79
80   # pg
81   psql -c 'create database dbic_test;' -U postgres
82   export DBICTEST_PG_DSN='dbi:Pg:database=dbic_test;host=127.0.0.1'
83   export DBICTEST_PG_USER=postgres
84
85   # firebird
86   sudo perl -pi -e 's/\=no/=yes/' /etc/default/firebird2.5
87   sudo /etc/init.d/firebird2.5-super start
88   # FIXME: todo
89   #sudo gsec -add dbic_test -pw 123
90   #export DBICTEST_FIREBIRD_DSN=dbi:Firebird:dbname=/var/lib/firebird/2.5/data/dbic_test
91   #export DBICTEST_FIREBIRD_USER=dbic_test
92   #export DBICTEST_FIREBIRD_PASS=123
93   #export DBICTEST_FIREBIRD_INTERBASE_DSN=dbi:InterBase:dbname=/var/lib/firebird/2.5/data/dbic_test
94   #export DBICTEST_FIREBIRD_INTERBASE_USER=dbic_test
95   #export DBICTEST_FIREBIRD_INTERBASE_PASS=123
96
97   # oracle
98   # FIXME: todo
99   #DBICTEST_ORA_DSN=dbi:Oracle:host=localhost;sid=XE
100   #DBICTEST_ORA_USER=dbic_test
101   #DBICTEST_ORA_PASS=123
102   #DBICTEST_ORA_EXTRAUSER_DSN=dbi:Oracle:host=localhost;sid=XE
103   #DBICTEST_ORA_EXTRAUSER_USER=dbic_test_extra
104   #DBICTEST_ORA_EXTRAUSER_PASS=123
105   #ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client
106 fi
107
108 installdeps() {
109   if [[ -z "$@" ]] ; then return; fi
110
111   echo -n "Installing $@... "
112   if ! OUT=$( echo "$@" | xargs -n 1 -P $NUMTHREADS cpanm --verbose --notest 2>&1 ) ; then
113     EX=$?
114     echo "FAILED !!!"
115     echo "$OUT"
116     exit $?
117   else
118     echo "done."
119   fi
120 }
121
122 # Install *hard dep* modules that typically appear in more than one dep
123 #
124 # *NEVER* add optional depenencies here - will make CLEANTEST=true smokes useless
125 #
126 # do it in several passes to minimize amount of cross-deps installing multiple
127 # times, and to avoid module re-architecture breaking another install
128 # (e.g. once Carp is upgraded there's no more Carp::Heavy)
129 #
130 installdeps $(cpanm --notest --quiet --showdeps Module::Build)
131 installdeps Test::Exception Test::Fatal Module::Runtime Carp
132 installdeps Sub::Name multidimensional namespace::clean Class::XSAccessor MRO::Compat
133 installdeps DBI Moo Class::Accessor::Grouped
134
135 if [[ "$CLEANTEST" = "true" ]]; then
136   # get the last inc/ off cpan - we will get rid of MI
137   # soon enough, but till then this will do
138   # the point is to have a *really* clean perl (the ones
139   # we build are guaranteed to be clean, without side
140   # effects from travis preinstalls)
141   #
142   # FIXME - not yet implemented - not sure how to reliably
143   # feed to wget this location: http://cpansearch.perl.org/src/GETTY/DBIx-Class-0.08204/inc/
144   echo TODOOOO - M::I is not supposed to be installed here - this test is useless now
145   installdeps Module::Install
146 else
147   # we will be running all tests, preinstall MOAR stuff
148   installdeps Module::Install DateTime::Format::Strptime MooseX::Types JSON::Any Class::DBI
149 fi
150
151 # install the rest
152 perl Makefile.PL
153 installdeps $(make listalldeps)
154
155 # announce what are we running
156 perl -V
157 echo "Using $NUMTHREADS Travis-CI concurrent processes"
158
159 # make sure we got everything we need
160 perl Makefile.PL &> /dev/null
161 if [[ -n "$(make listdeps)" ]] ; then
162   echo "Not all deps installed - something went wrong :("
163   make listdeps
164   exit 1
165 fi