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