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.
22 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
23 # start first so that the total run time is not too high.
25 # We only run MySQL on PHP 5.6, so run that first.
26 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
27 # Postgres is significantly is pretty reasonable in its run-time.
29 # Run unit tests on MySQL
30 - DB=mysqli TASK=PHPUNIT
32 # Run CI Tests without running PHPUnit.
35 # Run unit tests on Postgres
36 - DB=pgsql TASK=PHPUNIT
38 # Perform an upgrade test too.
39 - DB=pgsql TASK=UPGRADE
43 # This will fail the build if a single job fails (except those in allow_failures).
44 # It will not stop the jobs from running.
48 # Run grunt/npm install on lowest supported npm version
50 env: DB=none TASK=GRUNT NVM_VERSION='0.10'
51 # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
53 env: DB=none TASK=GRUNT NVM_VERSION='node'
56 # MySQL - it's just too slow.
57 # Exclude it on all versions except for 7.0
58 # - env: DB=mysqli TASK=PHPUNIT
61 # - env: DB=mysqli TASK=PHPUNIT
64 - env: DB=mysqli TASK=PHPUNIT
67 - env: DB=none TASK=GRUNT
70 # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
71 - env: DB=pgsql TASK=UPGRADE
76 - $HOME/.composer/cache
81 if [ "$TASK" = 'PHPUNIT' ];
83 if [ -n "$GITHUB_APITOKEN" ]; then
84 composer config github-oauth.github.com $GITHUB_APITOKEN;
85 echo 'auth.json' >> .git/info/exclude
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%http://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_';" \
162 # Initialise PHPUnit for Moodle.
163 php admin/tool/phpunit/cli/init.php
167 if [ "$TASK" = 'GRUNT' ];
169 npm install --no-spin;
170 npm install --no-spin -g grunt ;
173 ########################################################################
175 ########################################################################
177 if [ "$TASK" = 'CITEST' ];
179 # Note - this is deliberately placed in the script section as we
180 # should not add any code until after phpunit has run.
182 # The following repositories are required.
183 # The local_ci repository does the actual checking.
184 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
186 # We need the official upstream for comparison
187 git remote add upstream https://github.com/moodle/moodle.git;
189 git fetch upstream MOODLE_31_STABLE;
190 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
191 export GIT_COMMIT="$TRAVIS_COMMIT";
192 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
194 # Variables required by our linter.
195 export gitcmd=`which git`;
196 export gitdir="$TRAVIS_BUILD_DIR";
197 export phpcmd=`which php`;
200 ########################################################################
202 ########################################################################
204 if [ "$TASK" = 'UPGRADE' ];
206 # We need the official upstream.
207 git remote add upstream https://github.com/moodle/moodle.git;
209 # Checkout 27 STABLE branch.
210 git fetch upstream MOODLE_27_STABLE;
211 git checkout MOODLE_27_STABLE;
213 # Perform the upgrade
214 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
216 # Return to the previous commit
219 # Perform the upgrade
220 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
222 # The local_ci repository can be used to check upgrade savepoints.
223 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
228 if [ "$TASK" = 'PHPUNIT' ];
234 if [ "$TASK" = 'CITEST' ];
236 bash local/ci/php_lint/php_lint.sh;
240 if [ "$TASK" = 'GRUNT' ];
243 # Add all files to the git index and then run diff --cached to see all changes.
244 # This ensures that we get the status of all files, including new files.
246 git diff --cached --exit-code ;
249 ########################################################################
251 ########################################################################
253 if [ "$TASK" = 'UPGRADE' ];
255 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
256 result=`php check_upgrade_savepoints.php`;
257 # Check if there are problems
258 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;