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
39 # Run a check for unbuilt files with Grunt.
44 # This will fail the build if a single job fails (except those in allow_failures).
45 # It will not stop the jobs from running.
49 # MySQL - it's just too slow.
50 # Exclude it on all versions except for 7.0
52 - env: DB=mysqli TASK=PHPUNIT
55 # One grunt execution is enough.
56 - env: DB=none TASK=GRUNT
59 # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
60 - env: DB=pgsql TASK=UPGRADE
65 - $HOME/.composer/cache
69 # Disable xdebug. We aren't generating code coverage, and it has a huge impact upon test performance.
70 - rm /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
72 # Set the encrypted GITHUB_TOKEN if it's available to raise the API limit.
73 - if [ -n "$GITHUB_APITOKEN" ]; then composer config github-oauth.github.com $GITHUB_APITOKEN; fi
74 - echo 'auth.json' >> .git/info/exclude
76 # Install composer dependencies.
77 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
78 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
79 - travis_retry composer install --prefer-dist --no-interaction
83 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
85 # Copy generic configuration in place.
86 cp config-dist.php config.php ;
88 # Create the moodledata directory.
89 mkdir -p "$HOME"/roots/base
91 # The database name and password.
93 -e "s%= 'moodle'%= 'travis_ci_test'%" \
94 -e "s%= 'password'%= ''%" \
97 # The wwwroot and dataroot.
99 -e "s%http://example.com/moodle%http://localhost%" \
100 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
103 if [ "$DB" = 'pgsql' ];
105 # Postgres-specific setup.
107 -e "s%= 'username'%= 'postgres'%" \
110 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
113 if [ "$DB" = 'mysqli' ];
115 # MySQL-specific setup.
117 -e "s%= 'pgsql'%= 'mysqli'%" \
118 -e "s%= 'username'%= 'travis'%" \
121 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
122 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
123 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
128 if [ "$TASK" = 'PHPUNIT' ];
130 # Create a directory for the phpunit dataroot.
131 mkdir -p "$HOME"/roots/phpunit
133 # The phpunit dataroot and prefix..
135 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
136 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
139 # Initialise PHPUnit for Moodle.
140 php admin/tool/phpunit/cli/init.php
144 if [ "$TASK" = 'GRUNT' ];
147 npm install -g grunt ;
151 ########################################################################
153 ########################################################################
155 if [ "$TASK" = 'CITEST' ];
157 # Note - this is deliberately placed in the script section as we
158 # should not add any code until after phpunit has run.
160 # The following repositories are required.
161 # The local_ci repository does the actual checking.
162 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
164 # We need the official upstream for comparison
165 git remote add upstream https://github.com/moodle/moodle.git;
167 git fetch upstream master;
168 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
169 export GIT_COMMIT="$TRAVIS_COMMIT";
170 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
172 # Variables required by our linter.
173 export gitcmd=`which git`;
174 export gitdir="$TRAVIS_BUILD_DIR";
175 export phpcmd=`which php`;
178 ########################################################################
180 ########################################################################
182 if [ "$TASK" = 'UPGRADE' ];
184 # We need the official upstream.
185 git remote add upstream https://github.com/moodle/moodle.git;
187 # Checkout 27 STABLE branch.
188 git fetch upstream MOODLE_27_STABLE;
189 git checkout MOODLE_27_STABLE;
191 # Perform the upgrade
192 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
194 # Return to the previous commit
197 # Perform the upgrade
198 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
200 # The local_ci repository can be used to check upgrade savepoints.
201 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
206 if [ "$TASK" = 'PHPUNIT' ];
212 if [ "$TASK" = 'CITEST' ];
214 bash local/ci/php_lint/php_lint.sh;
218 if [ "$TASK" = 'GRUNT' ];
220 # Add all files to the git index and then run diff --cached to see all changes.
221 # This ensures that we get the status of all files, including new files.
223 git diff --cached --exit-code ;
226 ########################################################################
228 ########################################################################
230 if [ "$TASK" = 'UPGRADE' ];
232 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
233 result=`php check_upgrade_savepoints.php`;
234 # Check if there are problems
235 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;