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.
20 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
21 # start first so that the total run time is not too high.
23 # We only run MySQL on PHP 7.0, so run that first.
24 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
25 # Postgres is significantly is pretty reasonable in its run-time.
27 # Run unit tests on MySQL
28 - DB=mysqli TASK=PHPUNIT
30 # Run CI Tests without running PHPUnit.
33 # Run unit tests on Postgres
34 - DB=pgsql TASK=PHPUNIT
36 # Perform an upgrade test too.
37 - DB=pgsql TASK=UPGRADE
41 # This will fail the build if a single job fails (except those in allow_failures).
42 # It will not stop the jobs from running.
46 # Run grunt/npm install on lowest supported npm version
48 env: DB=none TASK=GRUNT NVM_VERSION='4'
49 # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
51 env: DB=none TASK=GRUNT NVM_VERSION='node'
54 # MySQL - it's just too slow.
55 # Exclude it on all versions except for 7.0
57 - env: DB=mysqli TASK=PHPUNIT
60 # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
61 - env: DB=pgsql TASK=UPGRADE
66 - $HOME/.composer/cache
70 # Disable xdebug. We aren't generating code coverage, and it has a huge impact upon test performance.
71 - rm /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
74 if [ "$TASK" = 'PHPUNIT' ];
76 if [ -n "$GITHUB_APITOKEN" ]; then
77 composer config github-oauth.github.com $GITHUB_APITOKEN;
78 echo 'auth.json' >> .git/info/exclude
81 # Install composer dependencies.
82 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
83 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
84 travis_retry composer install --prefer-dist --no-interaction;
88 if [ "$TASK" = 'GRUNT' ];
90 nvm install $NVM_VERSION ;
91 nvm use $NVM_VERSION ;
96 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
98 # Copy generic configuration in place.
99 cp config-dist.php config.php ;
101 # Create the moodledata directory.
102 mkdir -p "$HOME"/roots/base
104 # The database name and password.
106 -e "s%= 'moodle'%= 'travis_ci_test'%" \
107 -e "s%= 'password'%= ''%" \
110 # The wwwroot and dataroot.
112 -e "s%http://example.com/moodle%http://localhost%" \
113 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
116 if [ "$DB" = 'pgsql' ];
118 # Postgres-specific setup.
120 -e "s%= 'username'%= 'postgres'%" \
123 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
126 if [ "$DB" = 'mysqli' ];
128 # MySQL-specific setup.
130 -e "s%= 'pgsql'%= 'mysqli'%" \
131 -e "s%= 'username'%= 'travis'%" \
134 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
135 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
136 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
141 if [ "$TASK" = 'PHPUNIT' ];
143 # Create a directory for the phpunit dataroot.
144 mkdir -p "$HOME"/roots/phpunit
146 # The phpunit dataroot and prefix..
148 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
149 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
152 # Initialise PHPUnit for Moodle.
153 php admin/tool/phpunit/cli/init.php
157 if [ "$TASK" = 'GRUNT' ];
159 npm install --no-spin;
160 npm install --no-spin -g grunt ;
163 ########################################################################
165 ########################################################################
167 if [ "$TASK" = 'CITEST' ];
169 # Note - this is deliberately placed in the script section as we
170 # should not add any code until after phpunit has run.
172 # The following repositories are required.
173 # The local_ci repository does the actual checking.
174 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
176 # We need the official upstream for comparison
177 git remote add upstream https://github.com/moodle/moodle.git;
179 git fetch upstream master;
180 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
181 export GIT_COMMIT="$TRAVIS_COMMIT";
182 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
184 # Variables required by our linter.
185 export gitcmd=`which git`;
186 export gitdir="$TRAVIS_BUILD_DIR";
187 export phpcmd=`which php`;
190 ########################################################################
192 ########################################################################
194 if [ "$TASK" = 'UPGRADE' ];
196 # We need the official upstream.
197 git remote add upstream https://github.com/moodle/moodle.git;
199 # Checkout 27 STABLE branch.
200 git fetch upstream MOODLE_27_STABLE;
201 git checkout MOODLE_27_STABLE;
203 # Perform the upgrade
204 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
206 # Return to the previous commit
209 # Perform the upgrade
210 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
212 # The local_ci repository can be used to check upgrade savepoints.
213 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
218 if [ "$TASK" = 'PHPUNIT' ];
224 if [ "$TASK" = 'CITEST' ];
226 bash local/ci/php_lint/php_lint.sh;
230 if [ "$TASK" = 'GRUNT' ];
233 # Add all files to the git index and then run diff --cached to see all changes.
234 # This ensures that we get the status of all files, including new files.
236 git diff --cached --exit-code ;
239 ########################################################################
241 ########################################################################
243 if [ "$TASK" = 'UPGRADE' ];
245 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
246 result=`php check_upgrade_savepoints.php`;
247 # Check if there are problems
248 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;