Merge branch 'MDL-64598-36' of https://github.com/lucaboesch/moodle into MOODLE_36_STABLE
[moodle.git] / .travis.yml
blob217b2820144d8ca4956e2b2a520e57b5e07ee281
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: required
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 dist: xenial
16 services:
17     - mysql
19 php:
20     # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
21     - 7.2
22     - 7.0
24 addons:
25   postgresql: "9.6"
27 # Redis tests are currently failing on php 7.2 due to https://bugs.php.net/bug.php?id=75628
28 # services:
29 #     - redis-server
31 env:
32     # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
33     # start first so that the total run time is not too high.
34     #
35     # We only run MySQL on PHP 7.2, so run that first.
36     # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
37     # Postgres is significantly is pretty reasonable in its run-time.
39     # Run unit tests on MySQL
40     - DB=mysqli   TASK=PHPUNIT
42     # Run CI Tests without running PHPUnit.
43     - DB=none     TASK=CITEST
45     # Run unit tests on Postgres
46     - DB=pgsql    TASK=PHPUNIT
48     # Perform an upgrade test too.
49     - DB=pgsql    TASK=UPGRADE
51 matrix:
52     # Enable fast finish.
53     # This will fail the build if a single job fails (except those in allow_failures).
54     # It will not stop the jobs from running.
55     fast_finish: true
57     include:
58           # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
59         - php: 7.2
60           env: DB=none     TASK=GRUNT   NVM_VERSION='lts/carbon'
62     exclude:
63         # MySQL - it's just too slow.
64         # Exclude it on all versions except for 7.2
66         - env: DB=mysqli   TASK=PHPUNIT
67           php: 7.0
69 cache:
70     directories:
71       - $HOME/.composer/cache
72       - $HOME/.npm
74 install:
75     - >
76         if [ "$DB" = 'mysqli' ];
77         then
78             sudo mkdir /mnt/ramdisk
79             sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
80             sudo service mysql stop
81             sudo mv /var/lib/mysql /mnt/ramdisk
82             sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql
83             sudo service mysql restart
84         fi
85     - >
86         if [ "$DB" = 'pgsql' ];
87         then
88             sudo mkdir /mnt/ramdisk
89             sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
90             sudo service postgresql stop
91             sudo mv /var/lib/postgresql /mnt/ramdisk
92             sudo ln -s /mnt/ramdisk/postgresql /var/lib/postgresql
93             sudo service postgresql start 9.6
94         fi
95     - >
96         if [ "$TASK" = 'PHPUNIT' ];
97         then
98             if [ -n "$GITHUB_APITOKEN" ]; then
99                 composer config github-oauth.github.com $GITHUB_APITOKEN;
100                 echo 'auth.json' >> .git/info/exclude
101             fi
103             # Enable Redis.
104             # Redis tests are currently failing on php 7.2 due to https://bugs.php.net/bug.php?id=75628
105             # echo 'extension="redis.so"' > /tmp/redis.ini
106             # phpenv config-add /tmp/redis.ini
108             # Install composer dependencies.
109             # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
110             # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
111             travis_retry composer install --prefer-dist --no-interaction;
112         fi
114     - >
115         if [ "$TASK" = 'GRUNT' ];
116         then
117             nvm install $NVM_VERSION ;
118             nvm use $NVM_VERSION ;
119         fi
121 before_script:
122     - phpenv config-rm xdebug.ini
123     - >
124       if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
125       then
126         # Copy generic configuration in place.
127         cp config-dist.php config.php ;
129         # Create the moodledata directory.
130         mkdir -p "$HOME"/roots/base
132         # The database name and password.
133         sed -i \
134           -e "s%= 'moodle'%= 'travis_ci_test'%" \
135           -e "s%= 'password'%= ''%" \
136           config.php ;
138         # The wwwroot and dataroot.
139         sed -i \
140           -e "s%http://example.com/moodle%https://localhost%" \
141           -e "s%/home/example/moodledata%/home/travis/roots/base%" \
142           config.php ;
144         if [ "$DB" = 'pgsql' ];
145         then
146           # Postgres-specific setup.
147           sed -i \
148             -e "s%= 'username'%= 'postgres'%" \
149             config.php ;
151           psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
152         fi
154         if [ "$DB" = 'mysqli' ];
155         then
156           # MySQL-specific setup.
157           sed -i \
158             -e "s%= 'pgsql'%= 'mysqli'%" \
159             -e "s%= 'username'%= 'travis'%" \
160             -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
161             config.php;
163           mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
164           mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
165           mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
166           mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
167         fi
168       fi
170     - >
171       if [ "$TASK" = 'PHPUNIT' ];
172       then
173         # Create a directory for the phpunit dataroot.
174         mkdir -p "$HOME"/roots/phpunit
176         # The phpunit dataroot and prefix..
177         # Redis tests are currently failing on php 7.2 due to https://bugs.php.net/bug.php?id=75628
178         # -e "/require_once/i \\define('TEST_SESSION_REDIS_HOST', '127.0.0.1');" \
179         sed -i \
180           -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
181           -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
182           config.php ;
184         # Initialise PHPUnit for Moodle.
185         php admin/tool/phpunit/cli/init.php
186       fi
188     - >
189       if [ "$TASK" = 'GRUNT' ];
190       then
191         npm install --no-spin;
192         npm install --no-spin -g grunt ;
193       fi
195     ########################################################################
196     # CI Tests
197     ########################################################################
198     - >
199       if [ "$TASK" = 'CITEST' ];
200       then
201         # Note - this is deliberately placed in the script section as we
202         # should not add any code until after phpunit has run.
204         # The following repositories are required.
205         # The local_ci repository does the actual checking.
206         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
208         # We need the official upstream for comparison
209         git remote add upstream https://github.com/moodle/moodle.git;
211         git fetch upstream MOODLE_36_STABLE;
212         export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
213         export GIT_COMMIT="$TRAVIS_COMMIT";
214         export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
216         # Variables required by our linter.
217         export gitcmd=`which git`;
218         export gitdir="$TRAVIS_BUILD_DIR";
219         export phpcmd=`which php`;
220       fi
222     ########################################################################
223     # Upgrade test
224     ########################################################################
225     - >
226       if [ "$TASK" = 'UPGRADE' ];
227       then
228         # We need the official upstream.
229         git remote add upstream https://github.com/moodle/moodle.git;
231         # Checkout 30 STABLE branch (the first version compatible with PHP 7.x)
232         git fetch upstream MOODLE_30_STABLE;
233         git checkout MOODLE_30_STABLE;
235         # Perform the upgrade
236         php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
238         # Return to the previous commit
239         git checkout -;
241         # Perform the upgrade
242         php admin/cli/upgrade.php --non-interactive --allow-unstable ;
244         # The local_ci repository can be used to check upgrade savepoints.
245         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
246       fi
248 script:
249     - >
250       if [ "$TASK" = 'PHPUNIT' ];
251       then
252         vendor/bin/phpunit --fail-on-risky --disallow-test-output --verbose;
253       fi
255     - >
256       if [ "$TASK" = 'CITEST' ];
257       then
258         bash local/ci/php_lint/php_lint.sh;
259       fi
261     - >
262       if [ "$TASK" = 'GRUNT' ];
263       then
264         grunt ;
265         # Add all files to the git index and then run diff --cached to see all changes.
266         # This ensures that we get the status of all files, including new files.
267         # We ignore npm-shrinkwrap.json to make the tasks immune to npm changes.
268         git add . ;
269         git reset -- npm-shrinkwrap.json ;
270         git diff --cached --exit-code ;
271       fi
273     ########################################################################
274     # Upgrade test
275     ########################################################################
276     - >
277       if [ "$TASK" = 'UPGRADE' ];
278       then
279         cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
280         result=`php check_upgrade_savepoints.php`;
281         # Check if there are problems
282         count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;
283         if (($count > 0));
284         then
285           echo "$result"
286           exit 1 ;
287         fi
288       fi