MDL-56354 unittests: Put debug messages in the failure notice.
[moodle.git] / .travis.yml
blob4057ffc75efe843da9d4f2578c6ec28e114753a5
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     # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
16     - 7.0
17     # - 5.6
18     # - 5.5
19     - 5.4
21 env:
22     # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
23     # start first so that the total run time is not too high.
24     #
25     # We only run MySQL on PHP 5.6, so run that first.
26     # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
27     # Postgres is significantly is pretty reasonable in its run-time.
29     # Run unit tests on MySQL
30     - DB=mysqli   TASK=PHPUNIT
32     # Run CI Tests without running PHPUnit.
33     - DB=none     TASK=CITEST
35     # Run unit tests on Postgres
36     - DB=pgsql    TASK=PHPUNIT
38 matrix:
39     # Enable fast finish.
40     # This will fail the build if a single job fails (except those in allow_failures).
41     # It will not stop the jobs from running.
42     fast_finish: true
44     include:
45           # Run grunt/npm install on lowest supported npm version
46         - php: 7
47           env: DB=none     TASK=GRUNT   NVM_VERSION='0.10'
48           # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
49         - php: 7
50           env: DB=none     TASK=GRUNT   NVM_VERSION='node'
52     exclude:
53         # MySQL - it's just too slow.
54         # Exclude it on all versions except for 7.0
55         # - env: DB=mysqli   TASK=PHPUNIT
56         #   php: 5.6
57         #
58         # - env: DB=mysqli   TASK=PHPUNIT
59         #   php: 5.5
61         - env: DB=mysqli   TASK=PHPUNIT
62           php: 5.4
64         - env: DB=none     TASK=GRUNT
65           php: 5.4
67 cache:
68     directories:
69       - $HOME/.composer/cache
70       - $HOME/.npm
72 install:
73     # Disable xdebug. We aren't generating code coverage, and it has a huge impact upon test performance.
74     - rm /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
76     - >
77         if [ "$TASK" = 'PHPUNIT' ];
78         then
79             if [ -n "$GITHUB_APITOKEN" ]; then
80                 composer config github-oauth.github.com $GITHUB_APITOKEN;
81                 echo 'auth.json' >> .git/info/exclude
82             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;
88         fi
90     - >
91         if [ "$TASK" = 'GRUNT' ];
92         then
93             nvm install $NVM_VERSION ;
94             nvm use $NVM_VERSION ;
95         fi
97 before_script:
98     - >
99       if [ "$TASK" = 'PHPUNIT' ];
100       then
101         # Copy generic configuration in place.
102         cp config-dist.php config.php ;
104         # Create the moodledata directory.
105         mkdir -p "$HOME"/roots/base
107         # The database name and password.
108         sed -i \
109           -e "s%= 'moodle'%= 'travis_ci_test'%" \
110           -e "s%= 'password'%= ''%" \
111           config.php ;
113         # The wwwroot and dataroot.
114         sed -i \
115           -e "s%http://example.com/moodle%http://localhost%" \
116           -e "s%/home/example/moodledata%/home/travis/roots/base%" \
117           config.php ;
119         if [ "$DB" = 'pgsql' ];
120         then
121           # Postgres-specific setup.
122           sed -i \
123             -e "s%= 'username'%= 'postgres'%" \
124             config.php ;
126           psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
127         fi
129         if [ "$DB" = 'mysqli' ];
130         then
131           # MySQL-specific setup.
132           sed -i \
133             -e "s%= 'pgsql'%= 'mysqli'%" \
134             -e "s%= 'username'%= 'travis'%" \
135             config.php;
137           mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
138           mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
139           mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
140         fi
141       fi
143     - >
144       if [ "$TASK" = 'PHPUNIT' ];
145       then
146         # Create a directory for the phpunit dataroot.
147         mkdir -p "$HOME"/roots/phpunit
149         # The phpunit dataroot and prefix..
150         sed -i \
151           -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
152           -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
153           config.php ;
155         # Initialise PHPUnit for Moodle.
156         php admin/tool/phpunit/cli/init.php
157       fi
159     - >
160       if [ "$TASK" = 'GRUNT' ];
161       then
162         npm install --no-spin;
163         npm install --no-spin -g grunt ;
164       fi
166     ########################################################################
167     # CI Tests
168     ########################################################################
169     - >
170       if [ "$TASK" = 'CITEST' ];
171       then
172         # Note - this is deliberately placed in the script section as we
173         # should not add any code until after phpunit has run.
175         # The following repositories are required.
176         # The local_ci repository does the actual checking.
177         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
179         # We need the official upstream for comparison
180         git remote add upstream https://github.com/moodle/moodle.git;
182         git fetch upstream MOODLE_30_STABLE;
183         export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
184         export GIT_COMMIT="$TRAVIS_COMMIT";
185         export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
187         # Variables required by our linter.
188         export gitcmd=`which git`;
189         export gitdir="$TRAVIS_BUILD_DIR";
190         export phpcmd=`which php`;
191       fi
193     # Actually run the CI Tests - do this outside of the main test to make output clearer.
194     - >
195       if [ "$TASK" = 'CITEST' ];
196       then
197         bash local/ci/php_lint/php_lint.sh;
198       fi
200 script:
201     - >
202       if [ "$TASK" = 'PHPUNIT' ];
203       then
204         vendor/bin/phpunit;
205       fi
207     - >
208       if [ "$TASK" = 'CITEST' ];
209       then
210         bash local/ci/php_lint/php_lint.sh;
211       fi
213     - >
214       if [ "$TASK" = 'GRUNT' ];
215       then
216         grunt ;
217         # Add all files to the git index and then run diff --cached to see all changes.
218         # This ensures that we get the status of all files, including new files.
219         git add . ;
220         git diff --cached --exit-code ;
221       fi