Merge branch 'MDL-51458-master' of git://github.com/andrewnicols/moodle
[moodle.git] / .travis.yml
CommitLineData
88ec0860
AN
1sudo: false
2
ab17b4f7
AN
3# We currently disable Travis notifications entirely until https://github.com/travis-ci/travis-ci/issues/4976
4# is fixed.
5notifications:
6 email: false
7
88ec0860
AN
8language: php
9
10php:
11 # Moodle supports versions 5.4, 5.5, and 5.6 of PHP.
12 # Order by fastest to slowest.
13 # We currently only run the highest and lowest versions to reduce the load on travis-ci.org.
14 - 5.6
15 # - 5.5
16 - 5.4
17
18 # We hope to offer PHP 7 support in the near future.
19 - nightly
20
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
30 - DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
31
32 # Run CI Tests without running PHPUnit.
33 - DB=none PHPUNIT=false INSTALL=false CITEST=true
34
35 # Run unit tests on Postgres
36 - DB=pgsql PHPUNIT=true INSTALL=false CITEST=false
37
38matrix:
39 # Enable fast finish.
40 # This will fail the build if a single job fails (except those in allow_failures).
41 # It will not stop the jobs from running.
42 fast_finish: true
43
44 # Always allow failure on nightly.
45 # It's a nightly build and failures can happen.
46 allow_failures:
47 - php: nightly
48
49 exclude:
50 # PHP 7 is not yet supported for actual runs.
51 # Exclude it by default - we include it for CITEST only later.
52 - php: nightly
53
54 # MySQL - it's just too slow.
55 # Exclude it on all versions except for 5.6.
56 # - env: DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
57 # php: 5.5
58
59 - env: DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
60 php: 5.4
61
62 include:
63 # Attempt to run the CITEST set on PHP 7.
64 - php: nightly
65 env: DB=none PHPUNIT=false INSTALL=false CITEST=true
66
67cache:
68 directories:
69 - $HOME/.composer/cache
70
71install:
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
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 - >
82 if [ "$INSTALL" = 'true' -o "$PHPUNIT" = 'true' ];
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
124
125 if [ "$PHPUNIT" = 'true' ];
126 then
127 # Create a directory for the phpunit dataroot.
128 mkdir -p "$HOME"/roots/phpunit
129
130 # The phpunit dataroot and prefix..
131 sed -i \
132 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
133 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
134 config.php ;
135
136 # Initialise PHPUnit for Moodle.
137 php admin/tool/phpunit/cli/init.php
138 fi
139 fi
140
141script:
142 ########################################################################
143 # PHPUnit
144 ########################################################################
145 - >
146 if [ "$PHPUNIT" = 'true' ];
147 then
148 vendor/bin/phpunit;
149 fi
150
151 ########################################################################
152 # CI Tests
153 ########################################################################
154 - >
155 if [ "$CITEST" = 'true' ];
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.
159
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
163
164 # Determine the branch
165 grep '^$release.*dev' version.php > /dev/null
166 if [ $? -eq 0 ];
167 then
168 # This is master
169 export branchname='master';
170 else
171 # This is a stable branch. Use the version from version.php to determine which one.
172 export branchname="MOODLE_`grep '^$branch' version.php | sed "s/^.*'\([0-9]*\)'.*$/\1/"`_STABLE";
173 fi
174
175 # We need the official upstream for comparison
176 git remote add upstream https://github.com/moodle/moodle.git;
177 git fetch upstream "$branchname";
178 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
179 export GIT_COMMIT="$TRAVIS_COMMIT";
180 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
181
182 # Variables required by our linter.
183 export gitcmd=`which git`;
184 export gitdir="$TRAVIS_BUILD_DIR";
185 export phpcmd=`which php`;
186 fi
187
188 - >
189 if [ "$CITEST" = "true" -a "$GIT_PREVIOUS_COMMIT" != "$UPSTREAM_FETCH_HEAD" ];
190 then
191 # This is a CI test, but it is based on an older weekly release.
192 # Warn in a way that will fail the test.
193 echo "Current commit is based on an older weekly release" && false;
194 fi
195
196 # Actually run the CI Tests - do this outside of the main test to make output clearer.
197 - >
198 if [ "$CITEST" = 'true' ];
199 then
200 bash local/ci/php_lint/php_lint.sh;
201 fi