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.
26 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
27 # start first so that the total run time is not too high.
29 # We only run MySQL on PHP 7.1, so run that first.
30 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
31 # Postgres is significantly is pretty reasonable in its run-time.
33 # Run unit tests on MySQL
34 - DB=mysqli TASK=PHPUNIT
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 grunt/npm install on lowest supported npm version
54 env: DB=none TASK=GRUNT NVM_VERSION='4'
55 # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
57 env: DB=none TASK=GRUNT NVM_VERSION='node'
60 # MySQL - it's just too slow.
61 # Exclude it on all versions except for 7.1
63 - env: DB=mysqli TASK=PHPUNIT
66 # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
67 - env: DB=pgsql TASK=UPGRADE
72 - $HOME/.composer/cache
77 if [ "$TASK" = 'PHPUNIT' ];
79 if [ -n "$GITHUB_APITOKEN" ]; then
80 composer config github-oauth.github.com $GITHUB_APITOKEN;
81 echo 'auth.json' >> .git/info/exclude
85 echo 'extension="redis.so"' > /tmp/redis.ini
86 phpenv config-add /tmp/redis.ini
88 # Install composer dependencies.
89 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
90 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
91 travis_retry composer install --prefer-dist --no-interaction;
95 if [ "$TASK" = 'GRUNT' ];
97 nvm install $NVM_VERSION ;
98 nvm use $NVM_VERSION ;
102 - phpenv config-rm xdebug.ini
104 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
106 # Copy generic configuration in place.
107 cp config-dist.php config.php ;
109 # Create the moodledata directory.
110 mkdir -p "$HOME"/roots/base
112 # The database name and password.
114 -e "s%= 'moodle'%= 'travis_ci_test'%" \
115 -e "s%= 'password'%= ''%" \
118 # The wwwroot and dataroot.
120 -e "s%http://example.com/moodle%https://localhost%" \
121 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
124 if [ "$DB" = 'pgsql' ];
126 # Postgres-specific setup.
128 -e "s%= 'username'%= 'postgres'%" \
131 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
134 if [ "$DB" = 'mysqli' ];
136 # MySQL-specific setup.
138 -e "s%= 'pgsql'%= 'mysqli'%" \
139 -e "s%= 'username'%= 'travis'%" \
140 -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
143 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
144 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
145 mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ;
146 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ;
151 if [ "$TASK" = 'PHPUNIT' ];
153 # Create a directory for the phpunit dataroot.
154 mkdir -p "$HOME"/roots/phpunit
156 # The phpunit dataroot and prefix..
158 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
159 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
160 -e "/require_once/i \\define('TEST_SESSION_REDIS_HOST', '127.0.0.1');" \
163 # Initialise PHPUnit for Moodle.
164 php admin/tool/phpunit/cli/init.php
168 if [ "$TASK" = 'GRUNT' ];
170 npm install --no-spin;
171 npm install --no-spin -g grunt ;
174 ########################################################################
176 ########################################################################
178 if [ "$TASK" = 'CITEST' ];
180 # Note - this is deliberately placed in the script section as we
181 # should not add any code until after phpunit has run.
183 # The following repositories are required.
184 # The local_ci repository does the actual checking.
185 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
187 # We need the official upstream for comparison
188 git remote add upstream https://github.com/moodle/moodle.git;
190 git fetch upstream master;
191 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
192 export GIT_COMMIT="$TRAVIS_COMMIT";
193 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
195 # Variables required by our linter.
196 export gitcmd=`which git`;
197 export gitdir="$TRAVIS_BUILD_DIR";
198 export phpcmd=`which php`;
201 ########################################################################
203 ########################################################################
205 if [ "$TASK" = 'UPGRADE' ];
207 # We need the official upstream.
208 git remote add upstream https://github.com/moodle/moodle.git;
210 # Checkout 27 STABLE branch.
211 git fetch upstream MOODLE_27_STABLE;
212 git checkout MOODLE_27_STABLE;
214 # Perform the upgrade
215 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
217 # Return to the previous commit
220 # Perform the upgrade
221 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
223 # The local_ci repository can be used to check upgrade savepoints.
224 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
229 if [ "$TASK" = 'PHPUNIT' ];
235 if [ "$TASK" = 'CITEST' ];
237 bash local/ci/php_lint/php_lint.sh;
241 if [ "$TASK" = 'GRUNT' ];
244 # Add all files to the git index and then run diff --cached to see all changes.
245 # This ensures that we get the status of all files, including new files.
247 git diff --cached --exit-code ;
250 ########################################################################
252 ########################################################################
254 if [ "$TASK" = 'UPGRADE' ];
256 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
257 result=`php check_upgrade_savepoints.php`;
258 # Check if there are problems
259 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;