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
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.
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.
43 # Run unit tests on Postgres
44 - DB=pgsql TASK=PHPUNIT
46 # Perform an upgrade test too.
47 - DB=pgsql TASK=UPGRADE
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.
56 # Run grunt/npm install on lowest supported npm version
58 env: DB=none TASK=GRUNT NVM_VERSION='4'
59 # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
61 env: DB=none TASK=GRUNT NVM_VERSION='node'
64 # MySQL - it's just too slow.
65 # Exclude it on all versions except for 7.1
67 - env: DB=mysqli TASK=PHPUNIT
70 # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
71 - env: DB=pgsql TASK=UPGRADE
76 - $HOME/.composer/cache
80 - sudo apt-get -y install haveged
81 - sudo service haveged start
83 if [ "$DB" = 'mysqli' ];
85 sudo mkdir /mnt/ramdisk
86 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
88 sudo mv /var/lib/mysql /mnt/ramdisk
89 sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql
93 if [ "$DB" = 'pgsql' ];
95 sudo mkdir /mnt/ramdisk
96 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
97 sudo service postgresql stop
98 sudo mv /var/lib/postgresql /mnt/ramdisk
99 sudo ln -s /mnt/ramdisk/postgresql /var/lib/postgresql
100 sudo service postgresql start 9.3
103 if [ "$TASK" = 'PHPUNIT' ];
105 if [ -n "$GITHUB_APITOKEN" ]; then
106 composer config github-oauth.github.com $GITHUB_APITOKEN;
107 echo 'auth.json' >> .git/info/exclude
111 echo 'extension="redis.so"' > /tmp/redis.ini
112 phpenv config-add /tmp/redis.ini
114 # Install composer dependencies.
115 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
116 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
117 travis_retry composer install --prefer-dist --no-interaction;
121 if [ "$TASK" = 'GRUNT' ];
123 nvm install $NVM_VERSION ;
124 nvm use $NVM_VERSION ;
128 - phpenv config-rm xdebug.ini
130 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
132 # Copy generic configuration in place.
133 cp config-dist.php config.php ;
135 # Create the moodledata directory.
136 mkdir -p "$HOME"/roots/base
138 # The database name and password.
140 -e "s%= 'moodle'%= 'travis_ci_test'%" \
141 -e "s%= 'password'%= ''%" \
144 # The wwwroot and dataroot.
146 -e "s%http://example.com/moodle%https://localhost%" \
147 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
150 if [ "$DB" = 'pgsql' ];
152 # Postgres-specific setup.
154 -e "s%= 'username'%= 'postgres'%" \
157 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
160 if [ "$DB" = 'mysqli' ];
162 # MySQL-specific setup.
164 -e "s%= 'pgsql'%= 'mysqli'%" \
165 -e "s%= 'username'%= 'travis'%" \
166 -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
169 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
170 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
171 mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
172 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
177 if [ "$TASK" = 'PHPUNIT' ];
179 # Create a directory for the phpunit dataroot.
180 mkdir -p "$HOME"/roots/phpunit
182 # The phpunit dataroot and prefix..
184 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
185 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
186 -e "/require_once/i \\define('TEST_SESSION_REDIS_HOST', '127.0.0.1');" \
189 # Initialise PHPUnit for Moodle.
190 php admin/tool/phpunit/cli/init.php
194 if [ "$TASK" = 'GRUNT' ];
196 npm install --no-spin;
197 npm install --no-spin -g grunt ;
200 ########################################################################
202 ########################################################################
204 if [ "$TASK" = 'CITEST' ];
206 # Note - this is deliberately placed in the script section as we
207 # should not add any code until after phpunit has run.
209 # The following repositories are required.
210 # The local_ci repository does the actual checking.
211 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
213 # We need the official upstream for comparison
214 git remote add upstream https://github.com/moodle/moodle.git;
216 git fetch upstream master;
217 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
218 export GIT_COMMIT="$TRAVIS_COMMIT";
219 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
221 # Variables required by our linter.
222 export gitcmd=`which git`;
223 export gitdir="$TRAVIS_BUILD_DIR";
224 export phpcmd=`which php`;
227 ########################################################################
229 ########################################################################
231 if [ "$TASK" = 'UPGRADE' ];
233 # We need the official upstream.
234 git remote add upstream https://github.com/moodle/moodle.git;
236 # Checkout 27 STABLE branch.
237 git fetch upstream MOODLE_27_STABLE;
238 git checkout MOODLE_27_STABLE;
240 # Perform the upgrade
241 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
243 # Return to the previous commit
246 # Perform the upgrade
247 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
249 # The local_ci repository can be used to check upgrade savepoints.
250 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
255 if [ "$TASK" = 'PHPUNIT' ];
261 if [ "$TASK" = 'CITEST' ];
263 bash local/ci/php_lint/php_lint.sh;
267 if [ "$TASK" = 'GRUNT' ];
270 # Add all files to the git index and then run diff --cached to see all changes.
271 # This ensures that we get the status of all files, including new files.
273 git diff --cached --exit-code ;
276 ########################################################################
278 ########################################################################
280 if [ "$TASK" = 'UPGRADE' ];
282 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
283 result=`php check_upgrade_savepoints.php`;
284 # Check if there are problems
285 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;