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