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
15 # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
23 - mysql-client-core-5.6
27 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
28 # start first so that the total run time is not too high.
30 # We only run MySQL on PHP 7.2, so run that first.
31 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
32 # Postgres is significantly is pretty reasonable in its run-time.
34 # Run CI Tests without running PHPUnit.
37 # Run unit tests on Postgres
38 - DB=pgsql TASK=PHPUNIT
40 # Perform an upgrade test too.
41 - DB=pgsql TASK=UPGRADE
45 # This will fail the build if a single job fails (except those in allow_failures).
46 # It will not stop the jobs from running.
50 # Run mysql only on 7.3 - it's just too slow
52 env: DB=mysqli TASK=PHPUNIT
53 # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
55 env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon'
59 - $HOME/.composer/cache
63 # Avoid IPv6 default binding as service (causes redis not to start).
64 sudo service redis-server start --bind 127.0.0.1
68 if [ "$DB" = 'mysqli' ];
70 sudo mkdir /mnt/ramdisk
71 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
73 sudo mv /var/lib/mysql /mnt/ramdisk
74 sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql
78 if [ "$DB" = 'pgsql' ];
80 sudo mkdir /mnt/ramdisk
81 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
82 sudo service postgresql stop
83 sudo mv /var/lib/postgresql /mnt/ramdisk
84 sudo ln -s /mnt/ramdisk/postgresql /var/lib/postgresql
85 sudo service postgresql start 9.6
88 if [ "$TASK" = 'PHPUNIT' ];
90 if [ -n "$GITHUB_APITOKEN" ]; then
91 composer config github-oauth.github.com $GITHUB_APITOKEN;
92 echo 'auth.json' >> .git/info/exclude
95 echo 'extension="redis.so"' > /tmp/redis.ini
96 phpenv config-add /tmp/redis.ini
98 # Install composer dependencies.
99 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
100 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
101 travis_retry composer install --prefer-dist --no-interaction;
105 if [ "$TASK" = 'GRUNT' ];
107 nvm install $NVM_VERSION ;
108 nvm use $NVM_VERSION ;
112 - phpenv config-rm xdebug.ini
114 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
116 # Copy generic configuration in place.
117 cp config-dist.php config.php ;
119 # Create the moodledata directory.
120 mkdir -p "$HOME"/roots/base
122 # The database name and password.
124 -e "s%= 'moodle'%= 'travis_ci_test'%" \
125 -e "s%= 'password'%= ''%" \
128 # The wwwroot and dataroot.
130 -e "s%http://example.com/moodle%https://localhost%" \
131 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
134 if [ "$DB" = 'pgsql' ];
136 # Postgres-specific setup.
138 -e "s%= 'username'%= 'postgres'%" \
141 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
144 if [ "$DB" = 'mysqli' ];
146 # MySQL-specific setup.
148 -e "s%= 'pgsql'%= 'mysqli'%" \
149 -e "s%= 'username'%= 'travis'%" \
150 -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
153 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
154 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
155 mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
156 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
161 if [ "$TASK" = 'PHPUNIT' ];
163 # Create a directory for the phpunit dataroot.
164 mkdir -p "$HOME"/roots/phpunit
166 # The phpunit dataroot and prefix..
168 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
169 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
171 # Redis cache store tests
173 -e "/require_once/i \\define('TEST_CACHESTORE_REDIS_TESTSERVERS', '127.0.0.1');" \
175 # Redis session tests, but not for PHP 7.2 and up. See MDL-60978 for more info.
176 redissession="if (version_compare(PHP_VERSION, '7.2.0', '<')) { define('TEST_SESSION_REDIS_HOST', '127.0.0.1'); }"
178 -e "/require_once/i \\${redissession}" \
181 # Initialise PHPUnit for Moodle.
182 php admin/tool/phpunit/cli/init.php
186 if [ "$TASK" = 'GRUNT' ];
188 npm install --no-spin;
189 npm install --no-spin -g grunt ;
192 ########################################################################
194 ########################################################################
196 if [ "$TASK" = 'CITEST' ];
198 # Note - this is deliberately placed in the script section as we
199 # should not add any code until after phpunit has run.
201 # The following repositories are required.
202 # The local_ci repository does the actual checking.
203 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
205 # We need the official upstream for comparison
206 git remote add upstream https://github.com/moodle/moodle.git;
208 git fetch upstream MOODLE_37_STABLE;
209 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
210 export GIT_COMMIT="$TRAVIS_COMMIT";
211 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
213 # Variables required by our linter.
214 export gitcmd=`which git`;
215 export gitdir="$TRAVIS_BUILD_DIR";
216 export phpcmd=`which php`;
219 ########################################################################
221 ########################################################################
223 if [ "$TASK" = 'UPGRADE' ];
225 # We need the official upstream.
226 git remote add upstream https://github.com/moodle/moodle.git;
228 # Checkout 30 STABLE branch (the first version compatible with PHP 7.x)
229 git fetch upstream MOODLE_30_STABLE;
230 git checkout MOODLE_30_STABLE;
232 # Perform the upgrade
233 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
235 # Return to the previous commit
238 # Perform the upgrade
239 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
241 # The local_ci repository can be used to check upgrade savepoints.
242 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
247 if [ "$TASK" = 'PHPUNIT' ];
249 vendor/bin/phpunit --fail-on-risky --disallow-test-output --verbose;
253 if [ "$TASK" = 'CITEST' ];
255 bash local/ci/php_lint/php_lint.sh;
259 if [ "$TASK" = 'GRUNT' ];
262 # Add all files to the git index and then run diff --cached to see all changes.
263 # This ensures that we get the status of all files, including new files.
264 # We ignore npm-shrinkwrap.json to make the tasks immune to npm changes.
266 git reset -- npm-shrinkwrap.json ;
267 git diff --cached --exit-code ;
270 ########################################################################
272 ########################################################################
274 if [ "$TASK" = 'UPGRADE' ];
276 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
277 result=`php check_upgrade_savepoints.php`;
278 # Check if there are problems
279 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;