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.
22 - mysql-client-core-5.6
29 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
30 # start first so that the total run time is not too high.
32 # We only run MySQL on PHP 7.1, so run that first.
33 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
34 # Postgres is significantly is pretty reasonable in its run-time.
36 # Run unit tests on MySQL
37 - DB=mysqli TASK=PHPUNIT
39 # Run CI Tests without running PHPUnit.
42 # Run unit tests on Postgres
43 - DB=pgsql TASK=PHPUNIT
45 # Perform an upgrade test too.
46 - DB=pgsql TASK=UPGRADE
50 # This will fail the build if a single job fails (except those in allow_failures).
51 # It will not stop the jobs from running.
55 # Run grunt/npm install on lowest supported npm version
57 env: DB=none TASK=GRUNT NVM_VERSION='4'
58 # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
60 env: DB=none TASK=GRUNT NVM_VERSION='node'
63 # MySQL - it's just too slow.
64 # Exclude it on all versions except for 7.1
66 - env: DB=mysqli TASK=PHPUNIT
69 # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
70 - env: DB=pgsql TASK=UPGRADE
75 - $HOME/.composer/cache
80 if [ "$DB" = 'mysqli' ];
82 sudo mkdir /mnt/ramdisk
83 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
85 sudo mv /var/lib/mysql /mnt/ramdisk
86 sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql
90 if [ "$DB" = 'pgsql' ];
92 sudo mkdir /mnt/ramdisk
93 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
94 sudo service postgresql stop
95 sudo mv /var/lib/postgresql /mnt/ramdisk
96 sudo ln -s /mnt/ramdisk/postgresql /var/lib/postgresql
97 sudo service postgresql start 9.6
100 if [ "$TASK" = 'PHPUNIT' ];
102 if [ -n "$GITHUB_APITOKEN" ]; then
103 composer config github-oauth.github.com $GITHUB_APITOKEN;
104 echo 'auth.json' >> .git/info/exclude
108 echo 'extension="redis.so"' > /tmp/redis.ini
109 phpenv config-add /tmp/redis.ini
111 # Install composer dependencies.
112 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
113 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
114 travis_retry composer install --prefer-dist --no-interaction;
118 if [ "$TASK" = 'GRUNT' ];
120 nvm install $NVM_VERSION ;
121 nvm use $NVM_VERSION ;
125 - phpenv config-rm xdebug.ini
127 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
129 # Copy generic configuration in place.
130 cp config-dist.php config.php ;
132 # Create the moodledata directory.
133 mkdir -p "$HOME"/roots/base
135 # The database name and password.
137 -e "s%= 'moodle'%= 'travis_ci_test'%" \
138 -e "s%= 'password'%= ''%" \
141 # The wwwroot and dataroot.
143 -e "s%http://example.com/moodle%http://localhost%" \
144 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
147 if [ "$DB" = 'pgsql' ];
149 # Postgres-specific setup.
151 -e "s%= 'username'%= 'postgres'%" \
154 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
157 if [ "$DB" = 'mysqli' ];
159 # MySQL-specific setup.
161 -e "s%= 'pgsql'%= 'mysqli'%" \
162 -e "s%= 'username'%= 'travis'%" \
163 -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
166 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
167 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
168 mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
169 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
174 if [ "$TASK" = 'PHPUNIT' ];
176 # Create a directory for the phpunit dataroot.
177 mkdir -p "$HOME"/roots/phpunit
179 # The phpunit dataroot and prefix..
181 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
182 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
183 -e "/require_once/i \\define('TEST_SESSION_REDIS_HOST', '127.0.0.1');" \
186 # Initialise PHPUnit for Moodle.
187 php admin/tool/phpunit/cli/init.php
191 if [ "$TASK" = 'GRUNT' ];
193 npm install --no-spin;
194 npm install --no-spin -g grunt ;
197 ########################################################################
199 ########################################################################
201 if [ "$TASK" = 'CITEST' ];
203 # Note - this is deliberately placed in the script section as we
204 # should not add any code until after phpunit has run.
206 # The following repositories are required.
207 # The local_ci repository does the actual checking.
208 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
210 # We need the official upstream for comparison
211 git remote add upstream https://github.com/moodle/moodle.git;
213 git fetch upstream MOODLE_32_STABLE;
214 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
215 export GIT_COMMIT="$TRAVIS_COMMIT";
216 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
218 # Variables required by our linter.
219 export gitcmd=`which git`;
220 export gitdir="$TRAVIS_BUILD_DIR";
221 export phpcmd=`which php`;
224 ########################################################################
226 ########################################################################
228 if [ "$TASK" = 'UPGRADE' ];
230 # We need the official upstream.
231 git remote add upstream https://github.com/moodle/moodle.git;
233 # Checkout 27 STABLE branch.
234 git fetch upstream MOODLE_27_STABLE;
235 git checkout MOODLE_27_STABLE;
237 # Perform the upgrade
238 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
240 # Return to the previous commit
243 # Perform the upgrade
244 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
246 # The local_ci repository can be used to check upgrade savepoints.
247 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
252 if [ "$TASK" = 'PHPUNIT' ];
258 if [ "$TASK" = 'CITEST' ];
260 bash local/ci/php_lint/php_lint.sh;
264 if [ "$TASK" = 'GRUNT' ];
267 # Add all files to the git index and then run diff --cached to see all changes.
268 # This ensures that we get the status of all files, including new files.
270 git diff --cached --exit-code ;
273 ########################################################################
275 ########################################################################
277 if [ "$TASK" = 'UPGRADE' ];
279 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
280 result=`php check_upgrade_savepoints.php`;
281 # Check if there are problems
282 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;