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