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.
7 # We currently disable Travis notifications entirely until https://github.com/travis-ci/travis-ci/issues/4976
20 # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
22 - 7.1.30 # Make this sticky because current default version (7.1.11) has a bug with redis-extension output (MDL-66062)
28 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
29 # start first so that the total run time is not too high.
31 # We only run MySQL on PHP 7.2, so run that first.
32 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
33 # Postgres is significantly is pretty reasonable in its run-time.
35 # Run CI Tests without running PHPUnit.
38 # Run unit tests on Postgres
39 - DB=pgsql TASK=PHPUNIT
41 # Perform an upgrade test too.
42 - DB=pgsql TASK=UPGRADE
46 # This will fail the build if a single job fails (except those in allow_failures).
47 # It will not stop the jobs from running.
51 # Run mysql only on 7.3 - it's just too slow
53 env: DB=mysqli TASK=PHPUNIT
54 # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
56 env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon'
60 - $HOME/.composer/cache
64 # Avoid IPv6 default binding as service (causes redis not to start).
65 sudo service redis-server start --bind 127.0.0.1
69 if [ "$DB" = 'mysqli' ];
71 sudo mkdir /mnt/ramdisk
72 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
73 sudo service mysql stop
74 sudo mv /var/lib/mysql /mnt/ramdisk
75 sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql
76 sudo service mysql restart
79 if [ "$DB" = 'pgsql' ];
81 sudo mkdir /mnt/ramdisk
82 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
83 sudo service postgresql stop
84 sudo mv /var/lib/postgresql /mnt/ramdisk
85 sudo ln -s /mnt/ramdisk/postgresql /var/lib/postgresql
86 sudo service postgresql start 9.6
89 if [ "$TASK" = 'PHPUNIT' ];
91 if [ -n "$GITHUB_APITOKEN" ]; then
92 composer config github-oauth.github.com $GITHUB_APITOKEN;
93 echo 'auth.json' >> .git/info/exclude
96 echo 'extension="redis.so"' > /tmp/redis.ini
97 phpenv config-add /tmp/redis.ini
99 # Install composer dependencies.
100 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
101 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
102 travis_retry composer install --prefer-dist --no-interaction;
106 if [ "$TASK" = 'GRUNT' ];
108 nvm install $NVM_VERSION ;
109 nvm use $NVM_VERSION ;
113 - phpenv config-rm xdebug.ini
115 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
117 # Copy generic configuration in place.
118 cp config-dist.php config.php ;
120 # Create the moodledata directory.
121 mkdir -p "$HOME"/roots/base
123 # The database name and password.
125 -e "s%= 'moodle'%= 'travis_ci_test'%" \
126 -e "s%= 'password'%= ''%" \
129 # The wwwroot and dataroot.
131 -e "s%http://example.com/moodle%https://localhost%" \
132 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
135 if [ "$DB" = 'pgsql' ];
137 # Postgres-specific setup.
139 -e "s%= 'username'%= 'postgres'%" \
142 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
145 if [ "$DB" = 'mysqli' ];
147 # MySQL-specific setup.
149 -e "s%= 'pgsql'%= 'mysqli'%" \
150 -e "s%= 'username'%= 'travis'%" \
151 -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
154 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
155 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
156 mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
157 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
162 if [ "$TASK" = 'PHPUNIT' ];
164 # Create a directory for the phpunit dataroot.
165 mkdir -p "$HOME"/roots/phpunit
167 # The phpunit dataroot and prefix..
169 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
170 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
172 # Redis cache store tests
174 -e "/require_once/i \\define('TEST_CACHESTORE_REDIS_TESTSERVERS', '127.0.0.1');" \
176 # Redis session tests, but not for PHP 7.2 and up. See MDL-60978 for more info.
177 redissession="define('TEST_SESSION_REDIS_HOST', '127.0.0.1');"
179 -e "/require_once/i \\${redissession}" \
182 # Initialise PHPUnit for Moodle.
183 php admin/tool/phpunit/cli/init.php
187 if [ "$TASK" = 'GRUNT' ];
189 npm install --no-spin;
190 npm install --no-spin -g grunt ;
193 ########################################################################
195 ########################################################################
197 if [ "$TASK" = 'CITEST' ];
199 # Note - this is deliberately placed in the script section as we
200 # should not add any code until after phpunit has run.
202 # The following repositories are required.
203 # The local_ci repository does the actual checking.
204 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
206 # We need the official upstream for comparison
207 git remote add upstream https://github.com/moodle/moodle.git;
209 git fetch upstream master;
210 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
211 export GIT_COMMIT="$TRAVIS_COMMIT";
212 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
214 # Variables required by our linter.
215 export gitcmd=`which git`;
216 export gitdir="$TRAVIS_BUILD_DIR";
217 export phpcmd=`which php`;
220 ########################################################################
222 ########################################################################
224 if [ "$TASK" = 'UPGRADE' ];
226 # We need the official upstream.
227 git remote add upstream https://github.com/moodle/moodle.git;
229 # Checkout 30 STABLE branch (the first version compatible with PHP 7.x)
230 git fetch upstream MOODLE_30_STABLE;
231 git checkout MOODLE_30_STABLE;
233 # Perform the upgrade
234 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
236 # Return to the previous commit
239 # Perform the upgrade
240 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
242 # The local_ci repository can be used to check upgrade savepoints.
243 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
248 if [ "$TASK" = 'PHPUNIT' ];
250 vendor/bin/phpunit --fail-on-risky --disallow-test-output --verbose;
254 if [ "$TASK" = 'CITEST' ];
256 bash local/ci/php_lint/php_lint.sh;
260 if [ "$TASK" = 'GRUNT' ];
263 # Add all files to the git index and then run diff --cached to see all changes.
264 # This ensures that we get the status of all files, including new files.
265 # We ignore npm-shrinkwrap.json to make the tasks immune to npm changes.
267 git reset -- npm-shrinkwrap.json ;
268 git diff --cached --exit-code ;
271 ########################################################################
273 ########################################################################
275 if [ "$TASK" = 'UPGRADE' ];
277 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
278 result=`php check_upgrade_savepoints.php`;
279 # Check if there are problems
280 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;