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