Merge branch 'MDL-51495' of https://github.com/NeillM/moodle
[moodle.git] / .travis.yml
blob9deb770e6c69630d3b3e2a1e90954086e91e5940
1 # PLEASE NOTE: Travis is not currently utilised by the Moodle core integration
2 # process (which uses our internal CI system) this file is here for the benefit
3 # of community developers git clones - see MDL-51458.
5 sudo: false
7 # We currently disable Travis notifications entirely until https://github.com/travis-ci/travis-ci/issues/4976
8 # is fixed.
9 notifications:
10   email: false
12 language: php
14 php:
15     # Moodle supports versions 5.4, 5.5, and 5.6 of PHP.
16     # Order by fastest to slowest.
17     # We currently only run the highest and lowest versions to reduce the load on travis-ci.org.
18     - 5.6
19     # - 5.5
20     - 5.4
22     # We hope to offer PHP 7 support in the near future.
23     - nightly
25 services:
26     # Ensure that memcached and mongodb are running for testing of those MUC stores.
27     - memcached
28     - mongodb
30 env:
31     # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
32     # start first so that the total run time is not too high.
33     #
34     # We only run MySQL on PHP 5.6, so run that first.
35     # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
36     # Postgres is significantly is pretty reasonable in its run-time.
38     # Run unit tests on MySQL
39     - DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
41     # Run CI Tests without running PHPUnit.
42     - DB=none     PHPUNIT=false   INSTALL=false   CITEST=true
44     # Run unit tests on Postgres
45     - DB=pgsql    PHPUNIT=true    INSTALL=false   CITEST=false
47 matrix:
48     # Enable fast finish.
49     # This will fail the build if a single job fails (except those in allow_failures).
50     # It will not stop the jobs from running.
51     fast_finish: true
53     # Always allow failure on nightly.
54     # It's a nightly build and failures can happen.
55     allow_failures:
56         - php: nightly
58     exclude:
59         # PHP 7 is not yet supported for actual runs.
60         # Exclude it by default - we include it for CITEST only later.
61         - php: nightly
63         # MySQL - it's just too slow.
64         # Exclude it on all versions except for 5.6.
65         # - env: DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
66         #   php: 5.5
68         - env: DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
69           php: 5.4
71     include:
72         # Attempt to run the CITEST set on PHP 7.
73         - php: nightly
74           env: DB=none     PHPUNIT=false   INSTALL=false   CITEST=true
76 cache:
77     directories:
78       - $HOME/.composer/cache
80 install:
81     # Set the encrypted GITHUB_TOKEN if it's available to raise the API limit.
82     - if [ -n "$GITHUB_APITOKEN" ]; then composer config github-oauth.github.com $GITHUB_APITOKEN; fi
84     # Install composer dependencies.
85     # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
86     # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
87     - travis_retry composer install --prefer-dist --no-interaction
89     - echo "extension = memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
90     - echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
91     - echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
93 before_script:
94     - >
95       if [ "$INSTALL" = 'true' -o "$PHPUNIT" = 'true' ];
96       then
97         # Copy generic configuration in place.
98         cp config-dist.php config.php ;
100         # Create the moodledata directory.
101         mkdir -p "$HOME"/roots/base
103         # The database name and password.
104         sed -i \
105           -e "s%= 'moodle'%= 'travis_ci_test'%" \
106           -e "s%= 'password'%= ''%" \
107           config.php ;
109         # The wwwroot and dataroot.
110         sed -i \
111           -e "s%http://example.com/moodle%http://localhost%" \
112           -e "s%/home/example/moodledata%/home/travis/roots/base%" \
113           config.php ;
115         if [ "$DB" = 'pgsql' ];
116         then
117           # Postgres-specific setup.
118           sed -i \
119             -e "s%= 'username'%= 'postgres'%" \
120             config.php ;
122           psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
123         fi
125         if [ "$DB" = 'mysqli' ];
126         then
127           # MySQL-specific setup.
128           sed -i \
129             -e "s%= 'pgsql'%= 'mysqli'%" \
130             -e "s%= 'username'%= 'travis'%" \
131             config.php;
133           mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
134           mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
135           mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
136         fi
138         if [ "$PHPUNIT" = 'true' ];
139         then
140           # Create a directory for the phpunit dataroot.
141           mkdir -p "$HOME"/roots/phpunit
143           # The phpunit dataroot and prefix..
144           sed -i \
145             -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
146             -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
147             -e "/require_once/i define('TEST_CACHESTORE_MEMCACHE_TESTSERVERS', '127.0.0.1:11211');" \
148             -e "/require_once/i define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11211');" \
149             -e "/require_once/i define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://localhost:27017');" \
150             config.php ;
152           # Initialise PHPUnit for Moodle.
153           php admin/tool/phpunit/cli/init.php
154         fi
155       fi
157 script:
158     ########################################################################
159     # PHPUnit
160     ########################################################################
161     - >
162       if [ "$PHPUNIT" = 'true' ];
163       then
164         vendor/bin/phpunit;
165       fi
167     ########################################################################
168     # CI Tests
169     ########################################################################
170     - >
171       if [ "$CITEST" = 'true' ];
172       then
173         # Note - this is deliberately placed in the script section as we
174         # should not add any code until after phpunit has run.
176         # The following repositories are required.
177         # The local_ci repository does the actual checking.
178         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
180         # We need the official upstream for comparison
181         git remote add upstream https://github.com/moodle/moodle.git;
183         git fetch upstream master;
184         export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
185         export GIT_COMMIT="$TRAVIS_COMMIT";
186         export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
188         # Variables required by our linter.
189         export gitcmd=`which git`;
190         export gitdir="$TRAVIS_BUILD_DIR";
191         export phpcmd=`which php`;
192       fi
194     - >
195       if [ "$CITEST" = "true" -a "$GIT_PREVIOUS_COMMIT" != "$UPSTREAM_FETCH_HEAD" ];
196       then
197         # This is a CI test, but it is based on an older weekly release.
198         # Warn in a way that will fail the test.
199         echo "Current commit is based on an older weekly release" && false;
200       fi
202     # Actually run the CI Tests - do this outside of the main test to make output clearer.
203     - >
204       if [ "$CITEST" = 'true' ];
205       then
206         bash local/ci/php_lint/php_lint.sh;
207       fi