MDL-54059 testing: Simplify travis output
[moodle.git] / .travis.yml
CommitLineData
cf84a5d2
DP
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.
4
88ec0860
AN
5sudo: false
6
ab17b4f7
AN
7# We currently disable Travis notifications entirely until https://github.com/travis-ci/travis-ci/issues/4976
8# is fixed.
9notifications:
10 email: false
11
88ec0860
AN
12language: php
13
14php:
87b7314a
DP
15 # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
16 - 7.0
17 # - 5.6
88ec0860
AN
18 # - 5.5
19 - 5.4
20
88ec0860
AN
21env:
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.
28
29 # Run unit tests on MySQL
a24aff4e 30 - DB=mysqli TASK=PHPUNIT
88ec0860
AN
31
32 # Run CI Tests without running PHPUnit.
a24aff4e 33 - DB=none TASK=CITEST
88ec0860
AN
34
35 # Run unit tests on Postgres
a24aff4e 36 - DB=pgsql TASK=PHPUNIT
88ec0860 37
95b3ad67 38 # Perform an upgrade test too.
a24aff4e 39 - DB=pgsql TASK=UPGRADE
95b3ad67 40
88ec0860
AN
41matrix:
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
46
88ec0860 47 exclude:
88ec0860 48 # MySQL - it's just too slow.
87b7314a 49 # Exclude it on all versions except for 7.0
a24aff4e 50 # - env: DB=mysqli TASK=PHPUNIT
87b7314a
DP
51 # php: 5.6
52 #
a24aff4e 53 # - env: DB=mysqli TASK=PHPUNIT
88ec0860
AN
54 # php: 5.5
55
a24aff4e 56 - env: DB=mysqli TASK=PHPUNIT
88ec0860
AN
57 php: 5.4
58
95b3ad67 59 # Moodle 2.7 is not compatible with PHP 7 for the upgrade test.
a24aff4e 60 - env: DB=pgsql TASK=UPGRADE
95b3ad67
AN
61 php: 7.0
62
88ec0860
AN
63cache:
64 directories:
65 - $HOME/.composer/cache
66
67install:
eb474609
AN
68 # Disable xdebug. We aren't generating code coverage, and it has a huge impact upon test performance.
69 - rm /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
70
88ec0860
AN
71 # Set the encrypted GITHUB_TOKEN if it's available to raise the API limit.
72 - if [ -n "$GITHUB_APITOKEN" ]; then composer config github-oauth.github.com $GITHUB_APITOKEN; fi
a24aff4e 73 - echo 'auth.json' >> .git/info/exclude
88ec0860
AN
74
75 # Install composer dependencies.
76 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
77 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
78 - travis_retry composer install --prefer-dist --no-interaction
79
80before_script:
81 - >
a24aff4e 82 if [ "$TASK" = 'PHPUNIT' -o "$TASK" = 'UPGRADE' ];
88ec0860
AN
83 then
84 # Copy generic configuration in place.
85 cp config-dist.php config.php ;
86
87 # Create the moodledata directory.
88 mkdir -p "$HOME"/roots/base
89
90 # The database name and password.
91 sed -i \
92 -e "s%= 'moodle'%= 'travis_ci_test'%" \
93 -e "s%= 'password'%= ''%" \
94 config.php ;
95
96 # The wwwroot and dataroot.
97 sed -i \
98 -e "s%http://example.com/moodle%http://localhost%" \
99 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
100 config.php ;
101
102 if [ "$DB" = 'pgsql' ];
103 then
104 # Postgres-specific setup.
105 sed -i \
106 -e "s%= 'username'%= 'postgres'%" \
107 config.php ;
108
109 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
110 fi
111
112 if [ "$DB" = 'mysqli' ];
113 then
114 # MySQL-specific setup.
115 sed -i \
116 -e "s%= 'pgsql'%= 'mysqli'%" \
117 -e "s%= 'username'%= 'travis'%" \
118 config.php;
119
120 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
121 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
122 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
123 fi
88ec0860
AN
124 fi
125
88ec0860 126 - >
a24aff4e 127 if [ "$TASK" = 'PHPUNIT' ];
88ec0860 128 then
a24aff4e
AN
129 # Create a directory for the phpunit dataroot.
130 mkdir -p "$HOME"/roots/phpunit
131
132 # The phpunit dataroot and prefix..
133 sed -i \
134 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
135 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
136 config.php ;
137
138 # Initialise PHPUnit for Moodle.
139 php admin/tool/phpunit/cli/init.php
88ec0860
AN
140 fi
141
142 ########################################################################
143 # CI Tests
144 ########################################################################
145 - >
a24aff4e 146 if [ "$TASK" = 'CITEST' ];
88ec0860
AN
147 then
148 # Note - this is deliberately placed in the script section as we
149 # should not add any code until after phpunit has run.
150
151 # The following repositories are required.
152 # The local_ci repository does the actual checking.
153 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
154
88ec0860
AN
155 # We need the official upstream for comparison
156 git remote add upstream https://github.com/moodle/moodle.git;
5459e754 157
b2e859bc 158 git fetch upstream master;
88ec0860
AN
159 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
160 export GIT_COMMIT="$TRAVIS_COMMIT";
161 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
162
163 # Variables required by our linter.
164 export gitcmd=`which git`;
165 export gitdir="$TRAVIS_BUILD_DIR";
166 export phpcmd=`which php`;
167 fi
168
95b3ad67
AN
169 ########################################################################
170 # Upgrade test
171 ########################################################################
172 - >
a24aff4e 173 if [ "$TASK" = 'UPGRADE' ];
95b3ad67
AN
174 then
175 # We need the official upstream.
176 git remote add upstream https://github.com/moodle/moodle.git;
177
178 # Checkout 27 STABLE branch.
179 git fetch upstream MOODLE_27_STABLE;
180 git checkout MOODLE_27_STABLE;
181
182 # Perform the upgrade
183 php admin/cli/install_database.php --agree-license --adminpass=Password --adminemail=admin@example.com --fullname="Upgrade test" --shortname=Upgrade;
184
185 # Return to the previous commit
186 git checkout -;
187
188 # Perform the upgrade
189 php admin/cli/upgrade.php --non-interactive --allow-unstable ;
190
191 # The local_ci repository can be used to check upgrade savepoints.
192 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci ;
a24aff4e
AN
193 fi
194
195script:
196 - >
197 if [ "$TASK" = 'PHPUNIT' ];
198 then
199 vendor/bin/phpunit;
200 fi
201
202 - >
203 if [ "$TASK" = 'CITEST' ];
204 then
205 bash local/ci/php_lint/php_lint.sh;
206 fi
95b3ad67 207
a24aff4e
AN
208 ########################################################################
209 # Upgrade test
210 ########################################################################
211 - >
212 if [ "$TASK" = 'UPGRADE' ];
213 then
95b3ad67
AN
214 cp local/ci/check_upgrade_savepoints/check_upgrade_savepoints.php ./check_upgrade_savepoints.php
215 result=`php check_upgrade_savepoints.php`;
216 # Check if there are problems
217 count=`echo "$result" | grep -P "ERROR|WARN" | wc -l` ;
218 if (($count > 0));
219 then
220 echo "$result"
221 exit 1 ;
222 fi
223 fi