Moodle release 3.3rc1
[moodle.git] / .travis.yml
blobff2b674cffb143b0ac34721094027a670b10dd0b
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.
5 sudo: false
7 # We currently disable Travis notifications entirely until https://github.com/travis-ci/travis-ci/issues/4976
8 # is fixed.
9 notifications:
10   email: false
12 language: php
14 php:
15     # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
16     - 7.1
17     - 5.6
19 addons:
20   postgresql: "9.3"
22 services:
23     - redis-server
25 env:
26     # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
27     # start first so that the total run time is not too high.
28     #
29     # We only run MySQL on PHP 7.1, so run that first.
30     # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
31     # Postgres is significantly is pretty reasonable in its run-time.
33     # Run unit tests on MySQL
34     - DB=mysqli   TASK=PHPUNIT
36     # Run CI Tests without running PHPUnit.
37     - DB=none     TASK=CITEST
39     # Run unit tests on Postgres
40     - DB=pgsql    TASK=PHPUNIT
42     # Perform an upgrade test too.
43     - DB=pgsql    TASK=UPGRADE
45 matrix:
46     # Enable fast finish.
47     # This will fail the build if a single job fails (except those in allow_failures).
48     # It will not stop the jobs from running.
49     fast_finish: true
51     include:
52           # Run grunt/npm install on lowest supported npm version
53         - php: 7.1
54           env: DB=none     TASK=GRUNT   NVM_VERSION='4'
55           # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
56         - php: 7.1
57           env: DB=none     TASK=GRUNT   NVM_VERSION='node'
59     exclude:
60         # MySQL - it's just too slow.
61         # Exclude it on all versions except for 7.1
63         - env: DB=mysqli   TASK=PHPUNIT
64           php: 5.6
66         # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
67         - env: DB=pgsql    TASK=UPGRADE
68           php: 7.1
70 cache:
71     directories:
72       - $HOME/.composer/cache
73       - $HOME/.npm
75 install:
76     - >
77         if [ "$TASK" = 'PHPUNIT' ];
78         then
79             if [ -n "$GITHUB_APITOKEN" ]; then
80                 composer config github-oauth.github.com $GITHUB_APITOKEN;
81                 echo 'auth.json' >> .git/info/exclude
82             fi
84             # Enable Redis.
85             echo 'extension="redis.so"' > /tmp/redis.ini
86             phpenv config-add /tmp/redis.ini
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;
92         fi
94     - >
95         if [ "$TASK" = 'GRUNT' ];
96         then
97             nvm install $NVM_VERSION ;
98             nvm use $NVM_VERSION ;
99         fi
101 before_script:
102     - phpenv config-rm xdebug.ini
103     - >
104       if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
105       then
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.
113         sed -i \
114           -e "s%= 'moodle'%= 'travis_ci_test'%" \
115           -e "s%= 'password'%= ''%" \
116           config.php ;
118         # The wwwroot and dataroot.
119         sed -i \
120           -e "s%http://example.com/moodle%https://localhost%" \
121           -e "s%/home/example/moodledata%/home/travis/roots/base%" \
122           config.php ;
124         if [ "$DB" = 'pgsql' ];
125         then
126           # Postgres-specific setup.
127           sed -i \
128             -e "s%= 'username'%= 'postgres'%" \
129             config.php ;
131           psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
132         fi
134         if [ "$DB" = 'mysqli' ];
135         then
136           # MySQL-specific setup.
137           sed -i \
138             -e "s%= 'pgsql'%= 'mysqli'%" \
139             -e "s%= 'username'%= 'travis'%" \
140             -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \
141             config.php;
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;' ;
147         fi
148       fi
150     - >
151       if [ "$TASK" = 'PHPUNIT' ];
152       then
153         # Create a directory for the phpunit dataroot.
154         mkdir -p "$HOME"/roots/phpunit
156         # The phpunit dataroot and prefix..
157         sed -i \
158           -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
159           -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
160           -e "/require_once/i \\define('TEST_SESSION_REDIS_HOST', '127.0.0.1');" \
161           config.php ;
163         # Initialise PHPUnit for Moodle.
164         php admin/tool/phpunit/cli/init.php
165       fi
167     - >
168       if [ "$TASK" = 'GRUNT' ];
169       then
170         npm install --no-spin;
171         npm install --no-spin -g grunt ;
172       fi
174     ########################################################################
175     # CI Tests
176     ########################################################################
177     - >
178       if [ "$TASK" = 'CITEST' ];
179       then
180         # Note - this is deliberately placed in the script section as we
181         # should not add any code until after phpunit has run.
183         # The following repositories are required.
184         # The local_ci repository does the actual checking.
185         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
187         # We need the official upstream for comparison
188         git remote add upstream https://github.com/moodle/moodle.git;
190         git fetch upstream master;
191         export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
192         export GIT_COMMIT="$TRAVIS_COMMIT";
193         export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
195         # Variables required by our linter.
196         export gitcmd=`which git`;
197         export gitdir="$TRAVIS_BUILD_DIR";
198         export phpcmd=`which php`;
199       fi
201     ########################################################################
202     # Upgrade test
203     ########################################################################
204     - >
205       if [ "$TASK" = 'UPGRADE' ];
206       then
207         # We need the official upstream.
208         git remote add upstream https://github.com/moodle/moodle.git;
210         # Checkout 27 STABLE branch.
211         git fetch upstream MOODLE_27_STABLE;
212         git checkout MOODLE_27_STABLE;
214         # Perform the upgrade
215         php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
217         # Return to the previous commit
218         git checkout -;
220         # Perform the upgrade
221         php admin/cli/upgrade.php --non-interactive --allow-unstable ;
223         # The local_ci repository can be used to check upgrade savepoints.
224         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
225       fi
227 script:
228     - >
229       if [ "$TASK" = 'PHPUNIT' ];
230       then
231         vendor/bin/phpunit;
232       fi
234     - >
235       if [ "$TASK" = 'CITEST' ];
236       then
237         bash local/ci/php_lint/php_lint.sh;
238       fi
240     - >
241       if [ "$TASK" = 'GRUNT' ];
242       then
243         grunt ;
244         # Add all files to the git index and then run diff --cached to see all changes.
245         # This ensures that we get the status of all files, including new files.
246         git add . ;
247         git diff --cached --exit-code ;
248       fi
250     ########################################################################
251     # Upgrade test
252     ########################################################################
253     - >
254       if [ "$TASK" = 'UPGRADE' ];
255       then
256         cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
257         result=`php check_upgrade_savepoints.php`;
258         # Check if there are problems
259         count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;
260         if (($count > 0));
261         then
262           echo "$result"
263           exit 1 ;
264         fi
265       fi