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