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
41 # Run a check for unbuilt files with Grunt.
46 # This will fail the build if a single job fails (except those in allow_failures).
47 # It will not stop the jobs from running.
51 # MySQL - it's just too slow.
52 # Exclude it on all versions except for 7.0
53 # - env: DB=mysqli TASK=PHPUNIT
56 # - env: DB=mysqli TASK=PHPUNIT
59 - env: DB=mysqli TASK=PHPUNIT
62 - env: DB=none TASK=GRUNT
65 # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
66 - env: DB=pgsql TASK=UPGRADE
71 - $HOME/.composer/cache
75 # Disable xdebug. We aren't generating code coverage, and it has a huge impact upon test performance.
76 - rm /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
78 # Set the encrypted GITHUB_TOKEN if it's available to raise the API limit.
79 - if [ -n "$GITHUB_APITOKEN" ]; then composer config github-oauth.github.com $GITHUB_APITOKEN; fi
80 - echo 'auth.json' >> .git/info/exclude
82 # Install composer dependencies.
83 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
84 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
85 - travis_retry composer install --prefer-dist --no-interaction
89 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
91 # Copy generic configuration in place.
92 cp config-dist.php config.php ;
94 # Create the moodledata directory.
95 mkdir -p "$HOME"/roots/base
97 # The database name and password.
99 -e "s%= 'moodle'%= 'travis_ci_test'%" \
100 -e "s%= 'password'%= ''%" \
103 # The wwwroot and dataroot.
105 -e "s%http://example.com/moodle%http://localhost%" \
106 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
109 if [ "$DB" = 'pgsql' ];
111 # Postgres-specific setup.
113 -e "s%= 'username'%= 'postgres'%" \
116 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
119 if [ "$DB" = 'mysqli' ];
121 # MySQL-specific setup.
123 -e "s%= 'pgsql'%= 'mysqli'%" \
124 -e "s%= 'username'%= 'travis'%" \
127 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
128 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
129 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
134 if [ "$TASK" = 'PHPUNIT' ];
136 # Create a directory for the phpunit dataroot.
137 mkdir -p "$HOME"/roots/phpunit
139 # The phpunit dataroot and prefix..
141 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
142 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
145 # Initialise PHPUnit for Moodle.
146 php admin/tool/phpunit/cli/init.php
150 if [ "$TASK" = 'GRUNT' ];
153 npm install -g grunt ;
157 ########################################################################
159 ########################################################################
161 if [ "$TASK" = 'CITEST' ];
163 # Note - this is deliberately placed in the script section as we
164 # should not add any code until after phpunit has run.
166 # The following repositories are required.
167 # The local_ci repository does the actual checking.
168 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
170 # We need the official upstream for comparison
171 git remote add upstream https://github.com/moodle/moodle.git;
173 git fetch upstream MOODLE_31_STABLE;
174 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
175 export GIT_COMMIT="$TRAVIS_COMMIT";
176 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
178 # Variables required by our linter.
179 export gitcmd=`which git`;
180 export gitdir="$TRAVIS_BUILD_DIR";
181 export phpcmd=`which php`;
184 ########################################################################
186 ########################################################################
188 if [ "$TASK" = 'UPGRADE' ];
190 # We need the official upstream.
191 git remote add upstream https://github.com/moodle/moodle.git;
193 # Checkout 27 STABLE branch.
194 git fetch upstream MOODLE_27_STABLE;
195 git checkout MOODLE_27_STABLE;
197 # Perform the upgrade
198 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
200 # Return to the previous commit
203 # Perform the upgrade
204 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
206 # The local_ci repository can be used to check upgrade savepoints.
207 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
212 if [ "$TASK" = 'PHPUNIT' ];
218 if [ "$TASK" = 'CITEST' ];
220 bash local/ci/php_lint/php_lint.sh;
224 if [ "$TASK" = 'GRUNT' ];
226 # Add all files to the git index and then run diff --cached to see all changes.
227 # This ensures that we get the status of all files, including new files.
229 git diff --cached --exit-code ;
232 ########################################################################
234 ########################################################################
236 if [ "$TASK" = 'UPGRADE' ];
238 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
239 result=`php check_upgrade_savepoints.php`;
240 # Check if there are problems
241 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;