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
25 - /MOODLE_[0-9]+_STABLE/
26 - /^v[0-9]+\.[0-9]+\.[0-9]+.*/
30 # This will fail the build if a single job fails (except those in allow_failures).
31 # It will not stop the jobs from running.
35 # First all the lowest php ones (7.3)
37 env: DB=none TASK=CITEST
39 env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon'
41 - if: env(MOODLE_DATABASE) = "pgsql" OR env(MOODLE_DATABASE) = "all" OR env(MOODLE_DATABASE) IS NOT present
43 env: DB=pgsql TASK=PHPUNIT
45 - if: env(MOODLE_DATABASE) = "mysqli" OR env(MOODLE_DATABASE) = "all"
47 env: DB=mysqli TASK=PHPUNIT
49 # Then, conditionally, all the highest php ones (8.0)
50 - if: env(MOODLE_PHP) = "all"
52 env: DB=none TASK=CITEST
53 - if: env(MOODLE_PHP) = "all"
55 env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon'
57 - if: env(MOODLE_PHP) = "all" AND (env(MOODLE_DATABASE) = "pgsql" OR env(MOODLE_DATABASE) = "all" OR env(MOODLE_DATABASE) IS NOT present)
59 env: DB=pgsql TASK=PHPUNIT
61 - if: env(MOODLE_PHP) = "all" AND (env(MOODLE_DATABASE) = "mysqli" OR env(MOODLE_DATABASE) = "all")
63 env: DB=mysqli TASK=PHPUNIT
67 - $HOME/.composer/cache
71 - docker run -d -p 127.0.0.1:8080:80 --name exttests moodlehq/moodle-exttests
72 # Avoid IPv6 default binding as service (causes redis not to start).
73 - sudo service redis-server start --bind 127.0.0.1
77 if [ "$DB" = 'mysqli' ];
79 sudo mkdir /mnt/ramdisk
80 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
81 sudo service mysql stop
82 sudo mv /var/lib/mysql /mnt/ramdisk
83 sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql
84 sudo service mysql restart
87 if [ "$DB" = 'pgsql' ];
89 sudo mkdir /mnt/ramdisk
90 sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
91 sudo service postgresql stop
92 sudo mv /var/lib/postgresql /mnt/ramdisk
93 sudo ln -s /mnt/ramdisk/postgresql /var/lib/postgresql
94 sudo service postgresql start 9.6
97 if [ "$TASK" = 'PHPUNIT' ];
99 if [ -n "$GITHUB_APITOKEN" ]; then
100 composer config github-oauth.github.com $GITHUB_APITOKEN;
101 echo 'auth.json' >> .git/info/exclude
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 - if [[ ${TRAVIS_PHP_VERSION:0:1} -gt 7 ]]; then pecl install xmlrpc-beta; fi
122 - echo 'max_input_vars=5000' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
123 - phpenv config-rm xdebug.ini
125 if [ "$TASK" = 'PHPUNIT' ];
127 # Copy generic configuration in place.
128 cp config-dist.php config.php ;
130 # Create the moodledata directory.
131 mkdir -p "$HOME"/roots/base
133 # The database name and password.
135 -e "s%= 'moodle'%= 'travis_ci_test'%" \
136 -e "s%= 'password'%= ''%" \
139 # The wwwroot and dataroot.
141 -e "s%http://example.com/moodle%https://localhost%" \
142 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
145 if [ "$DB" = 'pgsql' ];
147 # Postgres-specific setup.
149 -e "s%= 'username'%= 'postgres'%" \
152 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
155 if [ "$DB" = 'mysqli' ];
157 # MySQL-specific setup.
159 -e "s%= 'pgsql'%= 'mysqli'%" \
160 -e "s%= 'username'%= 'travis'%" \
161 -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
164 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
165 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
166 mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
167 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
172 if [ "$TASK" = 'PHPUNIT' ];
174 # Create a directory for the phpunit dataroot.
175 mkdir -p "$HOME"/roots/phpunit
177 # The phpunit dataroot and prefix..
179 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
180 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
182 # Enable test external resources
184 -e "/require_once/i \\define('TEST_EXTERNAL_FILES_HTTP_URL', 'http://127.0.0.1:8080');" \
185 -e "/require_once/i \\define('TEST_EXTERNAL_FILES_HTTPS_URL', 'http://127.0.0.1:8080');" \
188 # Redis cache store tests
190 -e "/require_once/i \\define('TEST_CACHESTORE_REDIS_TESTSERVERS', '127.0.0.1');" \
192 # Redis session tests
194 -e "/require_once/i \\define('TEST_SESSION_REDIS_HOST', '127.0.0.1');" \
197 # Initialise PHPUnit for Moodle.
198 php admin/tool/phpunit/cli/init.php
202 if [ "$TASK" = 'GRUNT' ];
204 npm install --no-spin;
205 npm install --no-spin -g grunt ;
208 ########################################################################
210 ########################################################################
212 if [ "$TASK" = 'CITEST' ];
214 # Note - this is deliberately placed in the script section as we
215 # should not add any code until after phpunit has run.
217 # The following repositories are required.
218 # The local_ci repository does the actual checking.
219 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
221 # We need the official upstream for comparison
222 git remote add upstream https://github.com/moodle/moodle.git;
224 git fetch upstream MOODLE_400_STABLE;
225 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
226 export GIT_COMMIT="$TRAVIS_COMMIT";
227 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
229 # Variables required by our linter.
230 export gitcmd=`which git`;
231 export gitdir="$TRAVIS_BUILD_DIR";
232 export phpcmd=`which php`;
237 if [ "$TASK" = 'PHPUNIT' ];
239 vendor/bin/phpunit --fail-on-risky --disallow-test-output --verbose;
243 if [ "$TASK" = 'CITEST' ];
245 bash local/ci/php_lint/php_lint.sh;
249 if [ "$TASK" = 'GRUNT' ];
252 # Add all files to the git index and then run diff --cached to see all changes.
253 # This ensures that we get the status of all files, including new files.
254 # We ignore npm-shrinkwrap.json to make the tasks immune to npm changes.
256 git reset -- npm-shrinkwrap.json ;
257 git diff --cached --exit-code ;
262 if [ "$TASK" = 'PHPUNIT' ];
264 EXTTESTS_HITS=$(docker logs exttests 2>&1 | grep -Fv -e 'AH00558' -e '[pid 1]' | wc -l)
265 echo -e "\nTest local resources number of hits: ${EXTTESTS_HITS}.\n"