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 | ||
ab17b4f7 | 5 | notifications: |
36905f42 VDF |
6 | email: |
7 | if: env(MOODLE_EMAIL) != no | |
ab17b4f7 | 8 | |
88ec0860 AN |
9 | language: php |
10 | ||
9901ce5f LB |
11 | os: linux |
12 | ||
e0f0f763 MM |
13 | dist: xenial |
14 | ||
15 | services: | |
16 | - mysql | |
3ce1eba1 | 17 | - docker |
d3e61fdf | 18 | |
6e6a768c | 19 | addons: |
9f813ab5 | 20 | postgresql: "9.6" |
6e6a768c | 21 | |
9901ce5f | 22 | jobs: |
88ec0860 AN |
23 | # Enable fast finish. |
24 | # This will fail the build if a single job fails (except those in allow_failures). | |
25 | # It will not stop the jobs from running. | |
26 | fast_finish: true | |
27 | ||
7402479c | 28 | include: |
6a662825 EL |
29 | # First all the lowest php ones (7.2) |
30 | - php: 7.2 | |
31 | env: DB=none TASK=CITEST | |
32 | - php: 7.2 | |
33 | env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon' | |
34 | ||
35 | - if: env(MOODLE_DATABASE) = "pgsql" OR env(MOODLE_DATABASE) = "all" OR env(MOODLE_DATABASE) IS NOT present | |
36 | php: 7.2 | |
37 | env: DB=pgsql TASK=PHPUNIT | |
38 | ||
6a662825 EL |
39 | - if: env(MOODLE_DATABASE) = "mysqli" OR env(MOODLE_DATABASE) = "all" |
40 | php: 7.2 | |
a8b2f03d | 41 | env: DB=mysqli TASK=PHPUNIT |
6a662825 | 42 | |
6a662825 EL |
43 | # Then, conditionally, all the highest php ones (7.4) |
44 | - if: env(MOODLE_PHP) = "all" | |
45 | php: 7.4 | |
46 | env: DB=none TASK=CITEST | |
47 | - if: env(MOODLE_PHP) = "all" | |
48 | php: 7.4 | |
49 | env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon' | |
50 | ||
51 | - if: env(MOODLE_PHP) = "all" AND (env(MOODLE_DATABASE) = "pgsql" OR env(MOODLE_DATABASE) = "all" OR env(MOODLE_DATABASE) IS NOT present) | |
52 | php: 7.4 | |
53 | env: DB=pgsql TASK=PHPUNIT | |
54 | ||
6a662825 EL |
55 | - if: env(MOODLE_PHP) = "all" AND (env(MOODLE_DATABASE) = "mysqli" OR env(MOODLE_DATABASE) = "all") |
56 | php: 7.4 | |
57 | env: DB=mysqli TASK=PHPUNIT | |
58 | ||
88ec0860 AN |
59 | cache: |
60 | directories: | |
61 | - $HOME/.composer/cache | |
c366cb08 | 62 | - $HOME/.npm |
88ec0860 | 63 | |
a8b2f03d | 64 | before_install: |
3ce1eba1 | 65 | - docker run -d -p 127.0.0.1:8080:80 --name exttests moodlehq/moodle-exttests |
a8b2f03d | 66 | # Avoid IPv6 default binding as service (causes redis not to start). |
3ce1eba1 | 67 | - sudo service redis-server start --bind 127.0.0.1 |
a8b2f03d | 68 | |
88ec0860 | 69 | install: |
29d409b6 AN |
70 | - > |
71 | if [ "$DB" = 'mysqli' ]; | |
72 | then | |
73 | sudo mkdir /mnt/ramdisk | |
74 | sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk | |
e0f0f763 | 75 | sudo service mysql stop |
29d409b6 AN |
76 | sudo mv /var/lib/mysql /mnt/ramdisk |
77 | sudo ln -s /mnt/ramdisk/mysql /var/lib/mysql | |
e0f0f763 | 78 | sudo service mysql restart |
29d409b6 AN |
79 | fi |
80 | - > | |
81 | if [ "$DB" = 'pgsql' ]; | |
82 | then | |
83 | sudo mkdir /mnt/ramdisk | |
84 | sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk | |
85 | sudo service postgresql stop | |
86 | sudo mv /var/lib/postgresql /mnt/ramdisk | |
87 | sudo ln -s /mnt/ramdisk/postgresql /var/lib/postgresql | |
9f813ab5 | 88 | sudo service postgresql start 9.6 |
29d409b6 | 89 | fi |
7402479c DP |
90 | - > |
91 | if [ "$TASK" = 'PHPUNIT' ]; | |
92 | then | |
93 | if [ -n "$GITHUB_APITOKEN" ]; then | |
94 | composer config github-oauth.github.com $GITHUB_APITOKEN; | |
95 | echo 'auth.json' >> .git/info/exclude | |
96 | fi | |
97 | ||
a8b2f03d EL |
98 | echo 'extension="redis.so"' > /tmp/redis.ini |
99 | phpenv config-add /tmp/redis.ini | |
8ad2afd3 | 100 | |
7402479c DP |
101 | # Install composer dependencies. |
102 | # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone. | |
103 | # Typically it should be able to use the Composer cache if any other job has already completed before we started here. | |
104 | travis_retry composer install --prefer-dist --no-interaction; | |
105 | fi | |
88ec0860 | 106 | |
7402479c DP |
107 | - > |
108 | if [ "$TASK" = 'GRUNT' ]; | |
109 | then | |
110 | nvm install $NVM_VERSION ; | |
111 | nvm use $NVM_VERSION ; | |
112 | fi | |
88ec0860 AN |
113 | |
114 | before_script: | |
189d6ea8 | 115 | - phpenv config-rm xdebug.ini |
88ec0860 | 116 | - > |
ef95f526 | 117 | if [ "$TASK" = 'PHPUNIT' ]; |
88ec0860 AN |
118 | then |
119 | # Copy generic configuration in place. | |
120 | cp config-dist.php config.php ; | |
121 | ||
122 | # Create the moodledata directory. | |
123 | mkdir -p "$HOME"/roots/base | |
124 | ||
125 | # The database name and password. | |
126 | sed -i \ | |
127 | -e "s%= 'moodle'%= 'travis_ci_test'%" \ | |
128 | -e "s%= 'password'%= ''%" \ | |
129 | config.php ; | |
130 | ||
131 | # The wwwroot and dataroot. | |
132 | sed -i \ | |
6e6a768c | 133 | -e "s%http://example.com/moodle%https://localhost%" \ |
88ec0860 AN |
134 | -e "s%/home/example/moodledata%/home/travis/roots/base%" \ |
135 | config.php ; | |
136 | ||
137 | if [ "$DB" = 'pgsql' ]; | |
138 | then | |
139 | # Postgres-specific setup. | |
140 | sed -i \ | |
141 | -e "s%= 'username'%= 'postgres'%" \ | |
142 | config.php ; | |
143 | ||
144 | psql -c 'CREATE DATABASE travis_ci_test;' -U postgres; | |
145 | fi | |
146 | ||
147 | if [ "$DB" = 'mysqli' ]; | |
148 | then | |
149 | # MySQL-specific setup. | |
150 | sed -i \ | |
151 | -e "s%= 'pgsql'%= 'mysqli'%" \ | |
152 | -e "s%= 'username'%= 'travis'%" \ | |
0bbefd81 | 153 | -e "s%=> 'utf8mb4_unicode_ci'%=> 'utf8mb4_bin'%" \ |
88ec0860 AN |
154 | config.php; |
155 | ||
156 | mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ; | |
157 | mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ; | |
0bbefd81 AG |
158 | mysql -u root -e 'SET GLOBAL innodb_large_prefix=ON;' ; |
159 | mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;' ; | |
88ec0860 | 160 | fi |
88ec0860 AN |
161 | fi |
162 | ||
88ec0860 | 163 | - > |
a24aff4e | 164 | if [ "$TASK" = 'PHPUNIT' ]; |
88ec0860 | 165 | then |
a24aff4e AN |
166 | # Create a directory for the phpunit dataroot. |
167 | mkdir -p "$HOME"/roots/phpunit | |
168 | ||
169 | # The phpunit dataroot and prefix.. | |
170 | sed -i \ | |
171 | -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \ | |
172 | -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \ | |
173 | config.php ; | |
3ce1eba1 MS |
174 | # Enable test external resources |
175 | sed -i \ | |
176 | -e "/require_once/i \\define('TEST_EXTERNAL_FILES_HTTP_URL', 'http://127.0.0.1:8080');" \ | |
bd1eaea0 | 177 | -e "/require_once/i \\define('TEST_EXTERNAL_FILES_HTTPS_URL', 'http://127.0.0.1:8080');" \ |
3ce1eba1 | 178 | config.php ; |
bd1eaea0 | 179 | |
a8b2f03d EL |
180 | # Redis cache store tests |
181 | sed -i \ | |
182 | -e "/require_once/i \\define('TEST_CACHESTORE_REDIS_TESTSERVERS', '127.0.0.1');" \ | |
183 | config.php ; | |
184 | # Redis session tests, but not for PHP 7.2 and up. See MDL-60978 for more info. | |
e9aaf755 | 185 | redissession="define('TEST_SESSION_REDIS_HOST', '127.0.0.1');" |
a8b2f03d EL |
186 | sed -i \ |
187 | -e "/require_once/i \\${redissession}" \ | |
188 | config.php ; | |
a24aff4e AN |
189 | |
190 | # Initialise PHPUnit for Moodle. | |
191 | php admin/tool/phpunit/cli/init.php | |
88ec0860 AN |
192 | fi |
193 | ||
c366cb08 AN |
194 | - > |
195 | if [ "$TASK" = 'GRUNT' ]; | |
196 | then | |
7402479c DP |
197 | npm install --no-spin; |
198 | npm install --no-spin -g grunt ; | |
c366cb08 AN |
199 | fi |
200 | ||
88ec0860 AN |
201 | ######################################################################## |
202 | # CI Tests | |
203 | ######################################################################## | |
204 | - > | |
a24aff4e | 205 | if [ "$TASK" = 'CITEST' ]; |
88ec0860 AN |
206 | then |
207 | # Note - this is deliberately placed in the script section as we | |
208 | # should not add any code until after phpunit has run. | |
209 | ||
210 | # The following repositories are required. | |
211 | # The local_ci repository does the actual checking. | |
212 | git clone https://github.com/moodlehq/moodle-local_ci.git local/ci | |
213 | ||
88ec0860 AN |
214 | # We need the official upstream for comparison |
215 | git remote add upstream https://github.com/moodle/moodle.git; | |
5459e754 | 216 | |
ae3af1d8 | 217 | git fetch upstream MOODLE_310_STABLE; |
88ec0860 AN |
218 | export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`"; |
219 | export GIT_COMMIT="$TRAVIS_COMMIT"; | |
220 | export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD` | |
221 | ||
222 | # Variables required by our linter. | |
223 | export gitcmd=`which git`; | |
224 | export gitdir="$TRAVIS_BUILD_DIR"; | |
225 | export phpcmd=`which php`; | |
226 | fi | |
227 | ||
a24aff4e AN |
228 | script: |
229 | - > | |
230 | if [ "$TASK" = 'PHPUNIT' ]; | |
231 | then | |
33dca945 | 232 | vendor/bin/phpunit --fail-on-risky --disallow-test-output --verbose; |
a24aff4e AN |
233 | fi |
234 | ||
235 | - > | |
236 | if [ "$TASK" = 'CITEST' ]; | |
237 | then | |
238 | bash local/ci/php_lint/php_lint.sh; | |
239 | fi | |
95b3ad67 | 240 | |
c366cb08 AN |
241 | - > |
242 | if [ "$TASK" = 'GRUNT' ]; | |
243 | then | |
7402479c | 244 | grunt ; |
c366cb08 AN |
245 | # Add all files to the git index and then run diff --cached to see all changes. |
246 | # This ensures that we get the status of all files, including new files. | |
83a548c1 | 247 | # We ignore npm-shrinkwrap.json to make the tasks immune to npm changes. |
c366cb08 | 248 | git add . ; |
83a548c1 | 249 | git reset -- npm-shrinkwrap.json ; |
c366cb08 AN |
250 | git diff --cached --exit-code ; |
251 | fi | |
252 | ||
99a8358b AN |
253 | after_script: |
254 | - > | |
255 | if [ "$TASK" = 'PHPUNIT' ]; | |
256 | then | |
257 | EXTTESTS_HITS=$(docker logs exttests 2>&1 | grep -Fv -e 'AH00558' -e '[pid 1]' | wc -l) | |
258 | echo -e "\nTest local resources number of hits: ${EXTTESTS_HITS}.\n" | |
259 | fi |