Merge branch 'MDL-54944-master' of git://github.com/danpoltawski/moodle
[moodle.git] / .travis.yml
blob5a32a606c3997a7155ca8b24907275cd5d7949ab
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
19 env:
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.
22     #
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.
31     - DB=none     TASK=CITEST
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.
40     - DB=none     TASK=GRUNT
42 matrix:
43     # Enable fast finish.
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.
46     fast_finish: true
48     exclude:
49         # MySQL - it's just too slow.
50         # Exclude it on all versions except for 7.0
52         - env: DB=mysqli   TASK=PHPUNIT
53           php: 5.6
55        # One grunt execution is enough.
56         - env: DB=none     TASK=GRUNT
57           php: 5.6
59         # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
60         - env: DB=pgsql    TASK=UPGRADE
61           php: 7.0
63 cache:
64     directories:
65       - $HOME/.composer/cache
66       - $HOME/.npm
68 install:
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
81 before_script:
82     - >
83       if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
84       then
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.
92         sed -i \
93           -e "s%= 'moodle'%= 'travis_ci_test'%" \
94           -e "s%= 'password'%= ''%" \
95           config.php ;
97         # The wwwroot and dataroot.
98         sed -i \
99           -e "s%http://example.com/moodle%http://localhost%" \
100           -e "s%/home/example/moodledata%/home/travis/roots/base%" \
101           config.php ;
103         if [ "$DB" = 'pgsql' ];
104         then
105           # Postgres-specific setup.
106           sed -i \
107             -e "s%= 'username'%= 'postgres'%" \
108             config.php ;
110           psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
111         fi
113         if [ "$DB" = 'mysqli' ];
114         then
115           # MySQL-specific setup.
116           sed -i \
117             -e "s%= 'pgsql'%= 'mysqli'%" \
118             -e "s%= 'username'%= 'travis'%" \
119             config.php;
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;' ;
124         fi
125       fi
127     - >
128       if [ "$TASK" = 'PHPUNIT' ];
129       then
130         # Create a directory for the phpunit dataroot.
131         mkdir -p "$HOME"/roots/phpunit
133         # The phpunit dataroot and prefix..
134         sed -i \
135           -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
136           -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
137           config.php ;
139         # Initialise PHPUnit for Moodle.
140         php admin/tool/phpunit/cli/init.php
141       fi
143     - >
144       if [ "$TASK" = 'GRUNT' ];
145       then
146         npm install ;
147         npm install -g grunt ;
148         grunt ;
149       fi
151     ########################################################################
152     # CI Tests
153     ########################################################################
154     - >
155       if [ "$TASK" = 'CITEST' ];
156       then
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`;
176       fi
178     ########################################################################
179     # Upgrade test
180     ########################################################################
181     - >
182       if [ "$TASK" = 'UPGRADE' ];
183       then
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
195         git checkout -;
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 ;
202       fi
204 script:
205     - >
206       if [ "$TASK" = 'PHPUNIT' ];
207       then
208         vendor/bin/phpunit;
209       fi
211     - >
212       if [ "$TASK" = 'CITEST' ];
213       then
214         bash local/ci/php_lint/php_lint.sh;
215       fi
217     - >
218       if [ "$TASK" = 'GRUNT' ];
219       then
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.
222         git add . ;
223         git diff --cached --exit-code ;
224       fi
226     ########################################################################
227     # Upgrade test
228     ########################################################################
229     - >
230       if [ "$TASK" = 'UPGRADE' ];
231       then
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` ;
236         if (($count > 0));
237         then
238           echo "$result"
239           exit 1 ;
240         fi
241       fi