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 if: env(MOODLE_EMAIL) != no
24 # This will fail the build if a single job fails (except those in allow_failures).
25 # It will not stop the jobs from running.
29 # First all the lowest php ones (7.1.30)
30 # Make this sticky because current default version (7.1.11) has a bug with redis-extension output (MDL-66062)
32 env: DB=none TASK=CITEST
34 env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon'
36 - if: env(MOODLE_DATABASE) = "pgsql" OR env(MOODLE_DATABASE) = "all" OR env(MOODLE_DATABASE) IS NOT present
38 env: DB=pgsql TASK=PHPUNIT
40 - if: env(MOODLE_DATABASE) = "mysqli" OR env(MOODLE_DATABASE) = "all"
42 env: DB=mysqli TASK=PHPUNIT
44 # Then, conditionally, all the highest php ones (7.4)
45 - if: env(MOODLE_PHP) = "all"
47 env: DB=none TASK=CITEST
48 - if: env(MOODLE_PHP) = "all"
50 env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon'
52 - if: env(MOODLE_PHP) = "all" AND (env(MOODLE_DATABASE) = "pgsql" OR env(MOODLE_DATABASE) = "all" OR env(MOODLE_DATABASE) IS NOT present)
54 env: DB=pgsql TASK=PHPUNIT
56 - if: env(MOODLE_PHP) = "all" AND (env(MOODLE_DATABASE) = "mysqli" OR env(MOODLE_DATABASE) = "all")
58 env: DB=mysqli TASK=PHPUNIT
62 - $HOME/.composer/cache
66 - docker run -d -p 127.0.0.1:8080:80 --name exttests moodlehq/moodle-exttests
67 # Avoid IPv6 default binding as service (causes redis not to start).
68 - sudo service redis-server start --bind 127.0.0.1
72 if [ "$DB" = 'mysqli' ];
74 sudo mkdir /mnt/ramdisk
75 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
76 sudo service mysql stop
77 sudo mv /var/lib/mysql /mnt/ramdisk
78 sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql
79 sudo service mysql restart
82 if [ "$DB" = 'pgsql' ];
84 sudo mkdir /mnt/ramdisk
85 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
86 sudo service postgresql stop
87 sudo mv /var/lib/postgresql /mnt/ramdisk
88 sudo ln -s /mnt/ramdisk/postgresql /var/lib/postgresql
89 sudo service postgresql start 9.6
92 if [ "$TASK" = 'PHPUNIT' ];
94 if [ -n "$GITHUB_APITOKEN" ]; then
95 composer config github-oauth.github.com $GITHUB_APITOKEN;
96 echo 'auth.json' >> .git/info/exclude
99 echo 'extension="redis.so"' > /tmp/redis.ini
100 phpenv config-add /tmp/redis.ini
102 # Install composer dependencies.
103 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
104 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
105 travis_retry composer install --prefer-dist --no-interaction;
109 if [ "$TASK" = 'GRUNT' ];
111 nvm install $NVM_VERSION ;
112 nvm use $NVM_VERSION ;
116 - phpenv config-rm xdebug.ini
118 if [ "$TASK" = 'PHPUNIT' ];
120 # Copy generic configuration in place.
121 cp config-dist.php config.php ;
123 # Create the moodledata directory.
124 mkdir -p "$HOME"/roots/base
126 # The database name and password.
128 -e "s%= 'moodle'%= 'travis_ci_test'%" \
129 -e "s%= 'password'%= ''%" \
132 # The wwwroot and dataroot.
134 -e "s%http://example.com/moodle%https://localhost%" \
135 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
138 if [ "$DB" = 'pgsql' ];
140 # Postgres-specific setup.
142 -e "s%= 'username'%= 'postgres'%" \
145 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
148 if [ "$DB" = 'mysqli' ];
150 # MySQL-specific setup.
152 -e "s%= 'pgsql'%= 'mysqli'%" \
153 -e "s%= 'username'%= 'travis'%" \
154 -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
157 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
158 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
159 mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
160 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
165 if [ "$TASK" = 'PHPUNIT' ];
167 # Create a directory for the phpunit dataroot.
168 mkdir -p "$HOME"/roots/phpunit
170 # The phpunit dataroot and prefix..
172 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
173 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
175 # Enable test external resources
177 -e "/require_once/i \\define('TEST_EXTERNAL_FILES_HTTP_URL', 'http://127.0.0.1:8080');" \
178 -e "/require_once/i \\define('TEST_EXTERNAL_FILES_HTTPS_URL', 'http://127.0.0.1:8080');" \
181 # Redis cache store tests
183 -e "/require_once/i \\define('TEST_CACHESTORE_REDIS_TESTSERVERS', '127.0.0.1');" \
185 # Redis session tests, but not for PHP 7.2 and up. See MDL-60978 for more info.
186 redissession="define('TEST_SESSION_REDIS_HOST', '127.0.0.1');"
188 -e "/require_once/i \\${redissession}" \
191 # Initialise PHPUnit for Moodle.
192 php admin/tool/phpunit/cli/init.php
196 if [ "$TASK" = 'GRUNT' ];
198 npm install --no-spin;
199 npm install --no-spin -g grunt ;
202 ########################################################################
204 ########################################################################
206 if [ "$TASK" = 'CITEST' ];
208 # Note - this is deliberately placed in the script section as we
209 # should not add any code until after phpunit has run.
211 # The following repositories are required.
212 # The local_ci repository does the actual checking.
213 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
215 # We need the official upstream for comparison
216 git remote add upstream https://github.com/moodle/moodle.git;
218 git fetch upstream MOODLE_38_STABLE;
219 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
220 export GIT_COMMIT="$TRAVIS_COMMIT";
221 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
223 # Variables required by our linter.
224 export gitcmd=`which git`;
225 export gitdir="$TRAVIS_BUILD_DIR";
226 export phpcmd=`which php`;
231 if [ "$TASK" = 'PHPUNIT' ];
233 vendor/bin/phpunit --fail-on-risky --disallow-test-output --verbose;
237 if [ "$TASK" = 'CITEST' ];
239 bash local/ci/php_lint/php_lint.sh;
243 if [ "$TASK" = 'GRUNT' ];
246 # Add all files to the git index and then run diff --cached to see all changes.
247 # This ensures that we get the status of all files, including new files.
248 # We ignore npm-shrinkwrap.json to make the tasks immune to npm changes.
250 git reset -- npm-shrinkwrap.json ;
251 git diff --cached --exit-code ;
256 if [ "$TASK" = 'PHPUNIT' ];
258 EXTTESTS_HITS=$(docker logs exttests 2>&1 | grep -Fv -e 'AH00558' -e '[pid 1]' | wc -l)
259 echo -e "\nTest local resources number of hits: ${EXTTESTS_HITS}.\n"