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.
7 # We currently disable Travis notifications entirely until https://github.com/travis-ci/travis-ci/issues/4976
15 # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
22 # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
23 # start first so that the total run time is not too high.
25 # We only run MySQL on PHP 5.6, so run that first.
26 # CI Tests should be second-highest in priority as these only take <= 60 seconds to run under normal circumstances.
27 # Postgres is significantly is pretty reasonable in its run-time.
29 # Run unit tests on MySQL
30 - DB=mysqli TASK=PHPUNIT
32 # Run CI Tests without running PHPUnit.
35 # Run unit tests on Postgres
36 - DB=pgsql TASK=PHPUNIT
40 # This will fail the build if a single job fails (except those in allow_failures).
41 # It will not stop the jobs from running.
45 # Run grunt/npm install on lowest supported npm version
47 env: DB=none TASK=GRUNT NVM_VERSION='0.10'
48 # Run grunt/npm install on highest version ('node' is an alias for the latest node.js version.)
50 env: DB=none TASK=GRUNT NVM_VERSION='node'
53 # MySQL - it's just too slow.
54 # Exclude it on all versions except for 7.0
55 # - env: DB=mysqli TASK=PHPUNIT
58 # - env: DB=mysqli TASK=PHPUNIT
61 - env: DB=mysqli TASK=PHPUNIT
64 - env: DB=none TASK=GRUNT
69 - $HOME/.composer/cache
73 # Disable xdebug. We aren't generating code coverage, and it has a huge impact upon test performance.
74 - rm /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
77 if [ "$TASK" = 'PHPUNIT' ];
79 if [ -n "$GITHUB_APITOKEN" ]; then
80 composer config github-oauth.github.com $GITHUB_APITOKEN;
81 echo 'auth.json' >> .git/info/exclude
84 # Install composer dependencies.
85 # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
86 # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
87 travis_retry composer install --prefer-dist --no-interaction;
91 if [ "$TASK" = 'GRUNT' ];
93 nvm install $NVM_VERSION ;
94 nvm use $NVM_VERSION ;
99 if [ "$TASK" = 'PHPUNIT' ];
101 # Copy generic configuration in place.
102 cp config-dist.php config.php ;
104 # Create the moodledata directory.
105 mkdir -p "$HOME"/roots/base
107 # The database name and password.
109 -e "s%= 'moodle'%= 'travis_ci_test'%" \
110 -e "s%= 'password'%= ''%" \
113 # The wwwroot and dataroot.
115 -e "s%http://example.com/moodle%http://localhost%" \
116 -e "s%/home/example/moodledata%/home/travis/roots/base%" \
119 if [ "$DB" = 'pgsql' ];
121 # Postgres-specific setup.
123 -e "s%= 'username'%= 'postgres'%" \
126 psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
129 if [ "$DB" = 'mysqli' ];
131 # MySQL-specific setup.
133 -e "s%= 'pgsql'%= 'mysqli'%" \
134 -e "s%= 'username'%= 'travis'%" \
137 mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
138 mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
139 mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
144 if [ "$TASK" = 'PHPUNIT' ];
146 # Create a directory for the phpunit dataroot.
147 mkdir -p "$HOME"/roots/phpunit
149 # The phpunit dataroot and prefix..
151 -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
152 -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
155 # Initialise PHPUnit for Moodle.
156 php admin/tool/phpunit/cli/init.php
160 if [ "$TASK" = 'GRUNT' ];
162 npm install --no-spin;
163 npm install --no-spin -g grunt ;
166 ########################################################################
168 ########################################################################
170 if [ "$TASK" = 'CITEST' ];
172 # Note - this is deliberately placed in the script section as we
173 # should not add any code until after phpunit has run.
175 # The following repositories are required.
176 # The local_ci repository does the actual checking.
177 git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
179 # We need the official upstream for comparison
180 git remote add upstream https://github.com/moodle/moodle.git;
182 git fetch upstream MOODLE_30_STABLE;
183 export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
184 export GIT_COMMIT="$TRAVIS_COMMIT";
185 export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
187 # Variables required by our linter.
188 export gitcmd=`which git`;
189 export gitdir="$TRAVIS_BUILD_DIR";
190 export phpcmd=`which php`;
193 # Actually run the CI Tests - do this outside of the main test to make output clearer.
195 if [ "$TASK" = 'CITEST' ];
197 bash local/ci/php_lint/php_lint.sh;
202 if [ "$TASK" = 'PHPUNIT' ];
208 if [ "$TASK" = 'CITEST' ];
210 bash local/ci/php_lint/php_lint.sh;
214 if [ "$TASK" = 'GRUNT' ];
217 # Add all files to the git index and then run diff --cached to see all changes.
218 # This ensures that we get the status of all files, including new files.
220 git diff --cached --exit-code ;