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
26 # Redis tests are currently failing on php 7.2 due to https://bugs.php.net/bug.php?id=75628
31 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
32 # start first so that the total run time is not too high.
34 # We only run MySQL on PHP 7.2, so run that first.
35 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
36 # Postgres is significantly is pretty reasonable in its run-time.
38 # Run unit tests on MySQL
39 - DB=mysqli TASK=PHPUNIT
41 # Run CI Tests without running PHPUnit.
44 # Run unit tests on Postgres
45 - DB=pgsql TASK=PHPUNIT
47 # Perform an upgrade test too.
48 - DB=pgsql TASK=UPGRADE
52 # This will fail the build if a single job fails (except those in allow_failures).
53 # It will not stop the jobs from running.
57 # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
59 env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon'
62 # MySQL - it's just too slow.
63 # Exclude it on all versions except for 7.2
65 - env: DB=mysqli TASK=PHPUNIT
70 - $HOME/.composer/cache
75 if [ "$DB" = 'mysqli' ];
77 sudo mkdir /mnt/ramdisk
78 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
80 sudo mv /var/lib/mysql /mnt/ramdisk
81 sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql
85 if [ "$DB" = 'pgsql' ];
87 sudo mkdir /mnt/ramdisk
88 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
89 sudo service postgresql stop
90 sudo mv /var/lib/postgresql /mnt/ramdisk
91 sudo ln -s /mnt/ramdisk/postgresql /var/lib/postgresql
92 sudo service postgresql start 9.6
95 if [ "$TASK" = 'PHPUNIT' ];
97 if [ -n "$GITHUB_APITOKEN" ]; then
98 composer config github-oauth.github.com $GITHUB_APITOKEN;
99 echo 'auth.json' >> .git/info/exclude
103 # Redis tests are currently failing on php 7.2 due to https://bugs.php.net/bug.php?id=75628
104 # echo 'extension="redis.so"' > /tmp/redis.ini
105 # phpenv config-add /tmp/redis.ini
107 # Install composer dependencies.
108 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
109 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
110 travis_retry composer install --prefer-dist --no-interaction;
114 if [ "$TASK" = 'GRUNT' ];
116 nvm install $NVM_VERSION ;
117 nvm use $NVM_VERSION ;
121 - phpenv config-rm xdebug.ini
123 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
125 # Copy generic configuration in place.
126 cp config-dist.php config.php ;
128 # Create the moodledata directory.
129 mkdir -p "$HOME"/roots/base
131 # The database name and password.
133 -e "s%= 'moodle'%= 'travis_ci_test'%" \
134 -e "s%= 'password'%= ''%" \
137 # The wwwroot and dataroot.
139 -e "s%http://example.com/moodle%https://localhost%" \
140 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
143 if [ "$DB" = 'pgsql' ];
145 # Postgres-specific setup.
147 -e "s%= 'username'%= 'postgres'%" \
150 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
153 if [ "$DB" = 'mysqli' ];
155 # MySQL-specific setup.
157 -e "s%= 'pgsql'%= 'mysqli'%" \
158 -e "s%= 'username'%= 'travis'%" \
159 -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
162 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
163 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
164 mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
165 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
170 if [ "$TASK" = 'PHPUNIT' ];
172 # Create a directory for the phpunit dataroot.
173 mkdir -p "$HOME"/roots/phpunit
175 # The phpunit dataroot and prefix..
176 # Redis tests are currently failing on php 7.2 due to https://bugs.php.net/bug.php?id=75628
177 # -e "/require_once/i \\define('TEST_SESSION_REDIS_HOST', '127.0.0.1');" \
179 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
180 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
183 # Initialise PHPUnit for Moodle.
184 php admin/tool/phpunit/cli/init.php
188 if [ "$TASK" = 'GRUNT' ];
190 npm install --no-spin;
191 npm install --no-spin -g grunt ;
194 ########################################################################
196 ########################################################################
198 if [ "$TASK" = 'CITEST' ];
200 # Note - this is deliberately placed in the script section as we
201 # should not add any code until after phpunit has run.
203 # The following repositories are required.
204 # The local_ci repository does the actual checking.
205 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
207 # We need the official upstream for comparison
208 git remote add upstream https://github.com/moodle/moodle.git;
210 git fetch upstream master;
211 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
212 export GIT_COMMIT="$TRAVIS_COMMIT";
213 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
215 # Variables required by our linter.
216 export gitcmd=`which git`;
217 export gitdir="$TRAVIS_BUILD_DIR";
218 export phpcmd=`which php`;
221 ########################################################################
223 ########################################################################
225 if [ "$TASK" = 'UPGRADE' ];
227 # We need the official upstream.
228 git remote add upstream https://github.com/moodle/moodle.git;
230 # Checkout 30 STABLE branch (the first version compatible with PHP 7.x)
231 git fetch upstream MOODLE_30_STABLE;
232 git checkout MOODLE_30_STABLE;
234 # Perform the upgrade
235 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
237 # Return to the previous commit
240 # Perform the upgrade
241 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
243 # The local_ci repository can be used to check upgrade savepoints.
244 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
249 if [ "$TASK" = 'PHPUNIT' ];
251 vendor/bin/phpunit --fail-on-risky --disallow-test-output --verbose;
255 if [ "$TASK" = 'CITEST' ];
257 bash local/ci/php_lint/php_lint.sh;
261 if [ "$TASK" = 'GRUNT' ];
264 # Add all files to the git index and then run diff --cached to see all changes.
265 # This ensures that we get the status of all files, including new files.
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` ;