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.
5 # We currently disable Travis notifications entirely until https://github.com/travis-ci/travis-ci/issues/4976
21 # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
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.2, 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 CI Tests without running PHPUnit.
39 # Run unit tests on Postgres
40 - DB=pgsql TASK=PHPUNIT
42 # Perform an upgrade test too.
43 - DB=pgsql TASK=UPGRADE
47 # This will fail the build if a single job fails (except those in allow_failures).
48 # It will not stop the jobs from running.
52 # Run mysql only on highest - it's just too slow
54 env: DB=mysqli TASK=PHPUNIT
55 # Run grunt/npm install on highest version too ('node' is an alias for the latest node.js version.)
57 env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon'
61 - $HOME/.composer/cache
65 - docker run -d -p 127.0.0.1:8080:80 --name exttests moodlehq/moodle-exttests
66 # Avoid IPv6 default binding as service (causes redis not to start).
67 - sudo service redis-server start --bind 127.0.0.1
71 if [ "$DB" = 'mysqli' ];
73 sudo mkdir /mnt/ramdisk
74 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
75 sudo service mysql stop
76 sudo mv /var/lib/mysql /mnt/ramdisk
77 sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql
78 sudo service mysql restart
81 if [ "$DB" = 'pgsql' ];
83 sudo mkdir /mnt/ramdisk
84 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
85 sudo service postgresql stop
86 sudo mv /var/lib/postgresql /mnt/ramdisk
87 sudo ln -s /mnt/ramdisk/postgresql /var/lib/postgresql
88 sudo service postgresql start 9.6
91 if [ "$TASK" = 'PHPUNIT' ];
93 if [ -n "$GITHUB_APITOKEN" ]; then
94 composer config github-oauth.github.com $GITHUB_APITOKEN;
95 echo 'auth.json' >> .git/info/exclude
98 echo 'extension="redis.so"' > /tmp/redis.ini
99 phpenv config-add /tmp/redis.ini
101 # Install composer dependencies.
102 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
103 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
104 travis_retry composer install --prefer-dist --no-interaction;
108 if [ "$TASK" = 'GRUNT' ];
110 nvm install $NVM_VERSION ;
111 nvm use $NVM_VERSION ;
115 - phpenv config-rm xdebug.ini
117 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
119 # Copy generic configuration in place.
120 cp config-dist.php config.php ;
122 # Create the moodledata directory.
123 mkdir -p "$HOME"/roots/base
125 # The database name and password.
127 -e "s%= 'moodle'%= 'travis_ci_test'%" \
128 -e "s%= 'password'%= ''%" \
131 # The wwwroot and dataroot.
133 -e "s%http://example.com/moodle%https://localhost%" \
134 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
137 if [ "$DB" = 'pgsql' ];
139 # Postgres-specific setup.
141 -e "s%= 'username'%= 'postgres'%" \
144 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
147 if [ "$DB" = 'mysqli' ];
149 # MySQL-specific setup.
151 -e "s%= 'pgsql'%= 'mysqli'%" \
152 -e "s%= 'username'%= 'travis'%" \
153 -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
156 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
157 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
158 mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
159 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
164 if [ "$TASK" = 'PHPUNIT' ];
166 # Create a directory for the phpunit dataroot.
167 mkdir -p "$HOME"/roots/phpunit
169 # The phpunit dataroot and prefix..
171 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
172 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
174 # Enable test external resources
176 -e "/require_once/i \\define('TEST_EXTERNAL_FILES_HTTP_URL', 'http://127.0.0.1:8080');" \
178 # Redis cache store tests
180 -e "/require_once/i \\define('TEST_CACHESTORE_REDIS_TESTSERVERS', '127.0.0.1');" \
182 # Redis session tests, but not for PHP 7.2 and up. See MDL-60978 for more info.
183 redissession="define('TEST_SESSION_REDIS_HOST', '127.0.0.1');"
185 -e "/require_once/i \\${redissession}" \
188 # Initialise PHPUnit for Moodle.
189 php admin/tool/phpunit/cli/init.php
193 if [ "$TASK" = 'GRUNT' ];
195 npm install --no-spin;
196 npm install --no-spin -g grunt ;
199 ########################################################################
201 ########################################################################
203 if [ "$TASK" = 'CITEST' ];
205 # Note - this is deliberately placed in the script section as we
206 # should not add any code until after phpunit has run.
208 # The following repositories are required.
209 # The local_ci repository does the actual checking.
210 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
212 # We need the official upstream for comparison
213 git remote add upstream https://github.com/moodle/moodle.git;
215 git fetch upstream master;
216 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
217 export GIT_COMMIT="$TRAVIS_COMMIT";
218 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
220 # Variables required by our linter.
221 export gitcmd=`which git`;
222 export gitdir="$TRAVIS_BUILD_DIR";
223 export phpcmd=`which php`;
226 ########################################################################
228 ########################################################################
230 if [ "$TASK" = 'UPGRADE' ];
232 # We need the official upstream.
233 git remote add upstream https://github.com/moodle/moodle.git;
235 # Checkout 30 STABLE branch (the first version compatible with PHP 7.x)
236 git fetch upstream MOODLE_30_STABLE;
237 git checkout MOODLE_30_STABLE;
239 # Perform the upgrade
240 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
242 # Return to the previous commit
245 # Perform the upgrade
246 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
248 # The local_ci repository can be used to check upgrade savepoints.
249 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
254 if [ "$TASK" = 'PHPUNIT' ];
256 vendor/bin/phpunit --fail-on-risky --disallow-test-output --verbose;
257 EXTTESTS_HITS=$(docker logs exttests 2>&1 | grep -Fv -e 'AH00558' -e '[pid 1]' | wc -l)
258 echo -e "\nTest local resources number of hits: ${EXTTESTS_HITS}.\n"
262 if [ "$TASK" = 'CITEST' ];
264 bash local/ci/php_lint/php_lint.sh;
268 if [ "$TASK" = 'GRUNT' ];
271 # Add all files to the git index and then run diff --cached to see all changes.
272 # This ensures that we get the status of all files, including new files.
273 # We ignore npm-shrinkwrap.json to make the tasks immune to npm changes.
275 git reset -- npm-shrinkwrap.json ;
276 git diff --cached --exit-code ;
279 ########################################################################
281 ########################################################################
283 if [ "$TASK" = 'UPGRADE' ];
285 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
286 result=`php check_upgrade_savepoints.php`;
287 # Check if there are problems
288 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;