MDL-51458 Testing: Support for Travis-CI.org
[moodle.git] / .travis.yml
CommitLineData
88ec0860
AN
1sudo: false
2
3language: php
4
5php:
6 # Moodle supports versions 5.4, 5.5, and 5.6 of PHP.
7 # Order by fastest to slowest.
8 # We currently only run the highest and lowest versions to reduce the load on travis-ci.org.
9 - 5.6
10 # - 5.5
11 - 5.4
12
13 # We hope to offer PHP 7 support in the near future.
14 - nightly
15
16env:
17 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
18 # start first so that the total run time is not too high.
19 #
20 # We only run MySQL on PHP 5.6, so run that first.
21 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
22 # Postgres is significantly is pretty reasonable in its run-time.
23
24 # Run unit tests on MySQL
25 - DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
26
27 # Run CI Tests without running PHPUnit.
28 - DB=none PHPUNIT=false INSTALL=false CITEST=true
29
30 # Run unit tests on Postgres
31 - DB=pgsql PHPUNIT=true INSTALL=false CITEST=false
32
33matrix:
34 # Enable fast finish.
35 # This will fail the build if a single job fails (except those in allow_failures).
36 # It will not stop the jobs from running.
37 fast_finish: true
38
39 # Always allow failure on nightly.
40 # It's a nightly build and failures can happen.
41 allow_failures:
42 - php: nightly
43
44 exclude:
45 # PHP 7 is not yet supported for actual runs.
46 # Exclude it by default - we include it for CITEST only later.
47 - php: nightly
48
49 # MySQL - it's just too slow.
50 # Exclude it on all versions except for 5.6.
51 # - env: DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
52 # php: 5.5
53
54 - env: DB=mysqli PHPUNIT=true INSTALL=false CITEST=false
55 php: 5.4
56
57 include:
58 # Attempt to run the CITEST set on PHP 7.
59 - php: nightly
60 env: DB=none PHPUNIT=false INSTALL=false CITEST=true
61
62cache:
63 directories:
64 - $HOME/.composer/cache
65
66install:
67 # Set the encrypted GITHUB_TOKEN if it's available to raise the API limit.
68 - if [ -n "$GITHUB_APITOKEN" ]; then composer config github-oauth.github.com $GITHUB_APITOKEN; fi
69
70 # Install composer dependencies.
71 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
72 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
73 - travis_retry composer install --prefer-dist --no-interaction
74
75before_script:
76 - >
77 if [ "$INSTALL" = 'true' -o "$PHPUNIT" = 'true' ];
78 then
79 # Copy generic configuration in place.
80 cp config-dist.php config.php ;
81
82 # Create the moodledata directory.
83 mkdir -p "$HOME"/roots/base
84
85 # The database name and password.
86 sed -i \
87 -e "s%= 'moodle'%= 'travis_ci_test'%" \
88 -e "s%= 'password'%= ''%" \
89 config.php ;
90
91 # The wwwroot and dataroot.
92 sed -i \
93 -e "s%http://example.com/moodle%http://localhost%" \
94 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
95 config.php ;
96
97 if [ "$DB" = 'pgsql' ];
98 then
99 # Postgres-specific setup.
100 sed -i \
101 -e "s%= 'username'%= 'postgres'%" \
102 config.php ;
103
104 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
105 fi
106
107 if [ "$DB" = 'mysqli' ];
108 then
109 # MySQL-specific setup.
110 sed -i \
111 -e "s%= 'pgsql'%= 'mysqli'%" \
112 -e "s%= 'username'%= 'travis'%" \
113 config.php;
114
115 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
116 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
117 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
118 fi
119
120 if [ "$PHPUNIT" = 'true' ];
121 then
122 # Create a directory for the phpunit dataroot.
123 mkdir -p "$HOME"/roots/phpunit
124
125 # The phpunit dataroot and prefix..
126 sed -i \
127 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
128 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
129 config.php ;
130
131 # Initialise PHPUnit for Moodle.
132 php admin/tool/phpunit/cli/init.php
133 fi
134 fi
135
136script:
137 ########################################################################
138 # PHPUnit
139 ########################################################################
140 - >
141 if [ "$PHPUNIT" = 'true' ];
142 then
143 vendor/bin/phpunit;
144 fi
145
146 ########################################################################
147 # CI Tests
148 ########################################################################
149 - >
150 if [ "$CITEST" = 'true' ];
151 then
152 # Note - this is deliberately placed in the script section as we
153 # should not add any code until after phpunit has run.
154
155 # The following repositories are required.
156 # The local_ci repository does the actual checking.
157 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
158
159 # Determine the branch
160 grep '^$release.*dev' version.php > /dev/null
161 if [ $? -eq 0 ];
162 then
163 # This is master
164 export branchname='master';
165 else
166 # This is a stable branch. Use the version from version.php to determine which one.
167 export branchname="MOODLE_`grep '^$branch' version.php | sed "s/^.*'\([0-9]*\)'.*$/\1/"`_STABLE";
168 fi
169
170 # We need the official upstream for comparison
171 git remote add upstream https://github.com/moodle/moodle.git;
172 git fetch upstream "$branchname";
173 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
174 export GIT_COMMIT="$TRAVIS_COMMIT";
175 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
176
177 # Variables required by our linter.
178 export gitcmd=`which git`;
179 export gitdir="$TRAVIS_BUILD_DIR";
180 export phpcmd=`which php`;
181 fi
182
183 - >
184 if [ "$CITEST" = "true" -a "$GIT_PREVIOUS_COMMIT" != "$UPSTREAM_FETCH_HEAD" ];
185 then
186 # This is a CI test, but it is based on an older weekly release.
187 # Warn in a way that will fail the test.
188 echo "Current commit is based on an older weekly release" && false;
189 fi
190
191 # Actually run the CI Tests - do this outside of the main test to make output clearer.
192 - >
193 if [ "$CITEST" = 'true' ];
194 then
195 bash local/ci/php_lint/php_lint.sh;
196 fi