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 # Moodle supports versions 5.4, 5.5, and 5.6 of PHP.
16 # Order by fastest to slowest.
17 # We currently only run the highest and lowest versions to reduce the load on travis-ci.org.
22 # We hope to offer PHP 7 support in the near future.
26 # Ensure that memcached and mongodb are running for testing of those MUC stores.
31 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
32 # start first so that the total run time is not too high.
34 # We only run MySQL on PHP 5.6, so run that first.
35 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
36 # Postgres is significantly is pretty reasonable in its run-time.
38 # Run unit tests on MySQL
39 - DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
41 # Run CI Tests without running PHPUnit.
42 - DB=none PHPUNIT=false INSTALL=false CITEST=true
44 # Run unit tests on Postgres
45 - DB=pgsql PHPUNIT=true INSTALL=false CITEST=false
49 # This will fail the build if a single job fails (except those in allow_failures).
50 # It will not stop the jobs from running.
53 # Always allow failure on nightly.
54 # It's a nightly build and failures can happen.
59 # PHP 7 is not yet supported for actual runs.
60 # Exclude it by default - we include it for CITEST only later.
63 # MySQL - it's just too slow.
64 # Exclude it on all versions except for 5.6.
65 # - env: DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
68 - env: DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
72 # Attempt to run the CITEST set on PHP 7.
74 env: DB=none PHPUNIT=false INSTALL=false CITEST=true
78 - $HOME/.composer/cache
81 # Set the encrypted GITHUB_TOKEN if it's available to raise the API limit.
82 - if [ -n "$GITHUB_APITOKEN" ]; then composer config github-oauth.github.com $GITHUB_APITOKEN; fi
84 # Install composer dependencies.
85 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
86 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
87 - travis_retry composer install --prefer-dist --no-interaction
89 - echo "extension = memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
90 - echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
91 - echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
95 if [ "$INSTALL" = 'true' -o "$PHPUNIT" = 'true' ];
97 # Copy generic configuration in place.
98 cp config-dist.php config.php ;
100 # Create the moodledata directory.
101 mkdir -p "$HOME"/roots/base
103 # The database name and password.
105 -e "s%= 'moodle'%= 'travis_ci_test'%" \
106 -e "s%= 'password'%= ''%" \
109 # The wwwroot and dataroot.
111 -e "s%http://example.com/moodle%http://localhost%" \
112 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
115 if [ "$DB" = 'pgsql' ];
117 # Postgres-specific setup.
119 -e "s%= 'username'%= 'postgres'%" \
122 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
125 if [ "$DB" = 'mysqli' ];
127 # MySQL-specific setup.
129 -e "s%= 'pgsql'%= 'mysqli'%" \
130 -e "s%= 'username'%= 'travis'%" \
133 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
134 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
135 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
138 if [ "$PHPUNIT" = 'true' ];
140 # Create a directory for the phpunit dataroot.
141 mkdir -p "$HOME"/roots/phpunit
143 # The phpunit dataroot and prefix..
145 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
146 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
147 -e "/require_once/i define('TEST_CACHESTORE_MEMCACHE_TESTSERVERS', '127.0.0.1:11211');" \
148 -e "/require_once/i define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11211');" \
149 -e "/require_once/i define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://localhost:27017');" \
152 # Initialise PHPUnit for Moodle.
153 php admin/tool/phpunit/cli/init.php
158 ########################################################################
160 ########################################################################
162 if [ "$PHPUNIT" = 'true' ];
167 ########################################################################
169 ########################################################################
171 if [ "$CITEST" = 'true' ];
173 # Note - this is deliberately placed in the script section as we
174 # should not add any code until after phpunit has run.
176 # The following repositories are required.
177 # The local_ci repository does the actual checking.
178 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
180 # We need the official upstream for comparison
181 git remote add upstream https://github.com/moodle/moodle.git;
183 git fetch upstream MOODLE_30_STABLE;
184 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
185 export GIT_COMMIT="$TRAVIS_COMMIT";
186 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
188 # Variables required by our linter.
189 export gitcmd=`which git`;
190 export gitdir="$TRAVIS_BUILD_DIR";
191 export phpcmd=`which php`;
195 if [ "$CITEST" = "true" -a "$GIT_PREVIOUS_COMMIT" != "$UPSTREAM_FETCH_HEAD" ];
197 # This is a CI test, but it is based on an older weekly release.
198 # Warn in a way that will fail the test.
199 echo "Current commit is based on an older weekly release" && false;
202 # Actually run the CI Tests - do this outside of the main test to make output clearer.
204 if [ "$CITEST" = 'true' ];
206 bash local/ci/php_lint/php_lint.sh;