Merge branch 'wip-mdl-56369-m31' of https://github.com/rajeshtaneja/moodle into MOODL...
[moodle.git] / .travis.yml
blobf84a94103174479d359e62d9181e89a66cc0bba1
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     # Disable xdebug. We aren't generating code coverage, and it has a huge impact upon test performance.
81     - rm /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
83     - >
84         if [ "$TASK" = 'PHPUNIT' ];
85         then
86             if [ -n "$GITHUB_APITOKEN" ]; then
87                 composer config github-oauth.github.com $GITHUB_APITOKEN;
88                 echo 'auth.json' >> .git/info/exclude
89             fi
91             # Install composer dependencies.
92             # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
93             # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
94             travis_retry composer install --prefer-dist --no-interaction;
95         fi
97     - >
98         if [ "$TASK" = 'GRUNT' ];
99         then
100             nvm install $NVM_VERSION ;
101             nvm use $NVM_VERSION ;
102         fi
104 before_script:
105     - >
106       if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
107       then
108         # Copy generic configuration in place.
109         cp config-dist.php config.php ;
111         # Create the moodledata directory.
112         mkdir -p "$HOME"/roots/base
114         # The database name and password.
115         sed -i \
116           -e "s%= 'moodle'%= 'travis_ci_test'%" \
117           -e "s%= 'password'%= ''%" \
118           config.php ;
120         # The wwwroot and dataroot.
121         sed -i \
122           -e "s%http://example.com/moodle%http://localhost%" \
123           -e "s%/home/example/moodledata%/home/travis/roots/base%" \
124           config.php ;
126         if [ "$DB" = 'pgsql' ];
127         then
128           # Postgres-specific setup.
129           sed -i \
130             -e "s%= 'username'%= 'postgres'%" \
131             config.php ;
133           psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
134         fi
136         if [ "$DB" = 'mysqli' ];
137         then
138           # MySQL-specific setup.
139           sed -i \
140             -e "s%= 'pgsql'%= 'mysqli'%" \
141             -e "s%= 'username'%= 'travis'%" \
142             config.php;
144           mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
145           mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
146           mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_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           config.php ;
162         # Initialise PHPUnit for Moodle.
163         php admin/tool/phpunit/cli/init.php
164       fi
166     - >
167       if [ "$TASK" = 'GRUNT' ];
168       then
169         npm install --no-spin;
170         npm install --no-spin -g grunt ;
171       fi
173     ########################################################################
174     # CI Tests
175     ########################################################################
176     - >
177       if [ "$TASK" = 'CITEST' ];
178       then
179         # Note - this is deliberately placed in the script section as we
180         # should not add any code until after phpunit has run.
182         # The following repositories are required.
183         # The local_ci repository does the actual checking.
184         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
186         # We need the official upstream for comparison
187         git remote add upstream https://github.com/moodle/moodle.git;
189         git fetch upstream MOODLE_31_STABLE;
190         export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
191         export GIT_COMMIT="$TRAVIS_COMMIT";
192         export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
194         # Variables required by our linter.
195         export gitcmd=`which git`;
196         export gitdir="$TRAVIS_BUILD_DIR";
197         export phpcmd=`which php`;
198       fi
200     ########################################################################
201     # Upgrade test
202     ########################################################################
203     - >
204       if [ "$TASK" = 'UPGRADE' ];
205       then
206         # We need the official upstream.
207         git remote add upstream https://github.com/moodle/moodle.git;
209         # Checkout 27 STABLE branch.
210         git fetch upstream MOODLE_27_STABLE;
211         git checkout MOODLE_27_STABLE;
213         # Perform the upgrade
214         php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
216         # Return to the previous commit
217         git checkout -;
219         # Perform the upgrade
220         php admin/cli/upgrade.php --non-interactive --allow-unstable ;
222         # The local_ci repository can be used to check upgrade savepoints.
223         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
224       fi
226 script:
227     - >
228       if [ "$TASK" = 'PHPUNIT' ];
229       then
230         vendor/bin/phpunit;
231       fi
233     - >
234       if [ "$TASK" = 'CITEST' ];
235       then
236         bash local/ci/php_lint/php_lint.sh;
237       fi
239     - >
240       if [ "$TASK" = 'GRUNT' ];
241       then
242         grunt ;
243         # Add all files to the git index and then run diff --cached to see all changes.
244         # This ensures that we get the status of all files, including new files.
245         git add . ;
246         git diff --cached --exit-code ;
247       fi
249     ########################################################################
250     # Upgrade test
251     ########################################################################
252     - >
253       if [ "$TASK" = 'UPGRADE' ];
254       then
255         cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
256         result=`php check_upgrade_savepoints.php`;
257         # Check if there are problems
258         count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;
259         if (($count > 0));
260         then
261           echo "$result"
262           exit 1 ;
263         fi
264       fi