Merge branch 'MDL-57592-31' of https://github.com/mwehr/moodle into MOODLE_31_STABLE
[moodle.git] / .travis.yml
blobbb92dcfc0fe11cb7cd59f58fe0c8626993b285a7
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.0
17     # - 5.6
18     # - 5.5
19     - 5.4
21 env:
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.
24     #
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.
33     - DB=none     TASK=CITEST
35     # Run unit tests on Postgres
36     - DB=pgsql    TASK=PHPUNIT
38     # Perform an upgrade test too.
39     - DB=pgsql    TASK=UPGRADE
41 matrix:
42     # Enable fast finish.
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.
45     fast_finish: true
47     include:
48           # Run grunt/npm install on lowest supported npm version
49         - php: 7
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.)
52         - php: 7
53           env: DB=none     TASK=GRUNT   NVM_VERSION='node'
55     exclude:
56         # MySQL - it's just too slow.
57         # Exclude it on all versions except for 7.0
58         # - env: DB=mysqli   TASK=PHPUNIT
59         #   php: 5.6
60         #
61         # - env: DB=mysqli   TASK=PHPUNIT
62         #   php: 5.5
64         - env: DB=mysqli   TASK=PHPUNIT
65           php: 5.4
67         - env: DB=none     TASK=GRUNT
68           php: 5.4
70         # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
71         - env: DB=pgsql    TASK=UPGRADE
72           php: 7.0
74 cache:
75     directories:
76       - $HOME/.composer/cache
77       - $HOME/.npm
79 install:
80     - >
81         if [ "$TASK" = 'PHPUNIT' ];
82         then
83             if [ -n "$GITHUB_APITOKEN" ]; then
84                 composer config github-oauth.github.com $GITHUB_APITOKEN;
85                 echo 'auth.json' >> .git/info/exclude
86             fi
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%http://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             config.php;
142           mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
143           mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
144           mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
145         fi
146       fi
148     - >
149       if [ "$TASK" = 'PHPUNIT' ];
150       then
151         # Create a directory for the phpunit dataroot.
152         mkdir -p "$HOME"/roots/phpunit
154         # The phpunit dataroot and prefix..
155         sed -i \
156           -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
157           -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
158           config.php ;
160         # Initialise PHPUnit for Moodle.
161         php admin/tool/phpunit/cli/init.php
162       fi
164     - >
165       if [ "$TASK" = 'GRUNT' ];
166       then
167         npm install --no-spin;
168         npm install --no-spin -g grunt ;
169       fi
171     ########################################################################
172     # CI Tests
173     ########################################################################
174     - >
175       if [ "$TASK" = 'CITEST' ];
176       then
177         # Note - this is deliberately placed in the script section as we
178         # should not add any code until after phpunit has run.
180         # The following repositories are required.
181         # The local_ci repository does the actual checking.
182         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
184         # We need the official upstream for comparison
185         git remote add upstream https://github.com/moodle/moodle.git;
187         git fetch upstream MOODLE_31_STABLE;
188         export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
189         export GIT_COMMIT="$TRAVIS_COMMIT";
190         export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
192         # Variables required by our linter.
193         export gitcmd=`which git`;
194         export gitdir="$TRAVIS_BUILD_DIR";
195         export phpcmd=`which php`;
196       fi
198     ########################################################################
199     # Upgrade test
200     ########################################################################
201     - >
202       if [ "$TASK" = 'UPGRADE' ];
203       then
204         # We need the official upstream.
205         git remote add upstream https://github.com/moodle/moodle.git;
207         # Checkout 27 STABLE branch.
208         git fetch upstream MOODLE_27_STABLE;
209         git checkout MOODLE_27_STABLE;
211         # Perform the upgrade
212         php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
214         # Return to the previous commit
215         git checkout -;
217         # Perform the upgrade
218         php admin/cli/upgrade.php --non-interactive --allow-unstable ;
220         # The local_ci repository can be used to check upgrade savepoints.
221         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
222       fi
224 script:
225     - >
226       if [ "$TASK" = 'PHPUNIT' ];
227       then
228         vendor/bin/phpunit;
229       fi
231     - >
232       if [ "$TASK" = 'CITEST' ];
233       then
234         bash local/ci/php_lint/php_lint.sh;
235       fi
237     - >
238       if [ "$TASK" = 'GRUNT' ];
239       then
240         grunt ;
241         # Add all files to the git index and then run diff --cached to see all changes.
242         # This ensures that we get the status of all files, including new files.
243         git add . ;
244         git diff --cached --exit-code ;
245       fi
247     ########################################################################
248     # Upgrade test
249     ########################################################################
250     - >
251       if [ "$TASK" = 'UPGRADE' ];
252       then
253         cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
254         result=`php check_upgrade_savepoints.php`;
255         # Check if there are problems
256         count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;
257         if (($count > 0));
258         then
259           echo "$result"
260           exit 1 ;
261         fi
262       fi