Merge branch 'MDL-23128-30' of git://github.com/danpoltawski/moodle into MOODLE_30_STABLE
[moodle.git] / .travis.yml
blob256b0dc4cd6ed85f0634133abeb6b7c39a56e1c0
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 sudo: false
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
12 language: php
14 php:
15     # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
16     - 7.0
17     # - 5.6
18     # - 5.5
19     - 5.4
21 env:
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.
24     #
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   PHPUNIT=true    INSTALL=false   CITEST=false
32     # Run CI Tests without running PHPUnit.
33     - DB=none     PHPUNIT=false   INSTALL=false   CITEST=true
35     # Run unit tests on Postgres
36     - DB=pgsql    PHPUNIT=true    INSTALL=false   CITEST=false
38 matrix:
39     # Enable fast finish.
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.
42     fast_finish: true
44     exclude:
45         # MySQL - it's just too slow.
46         # Exclude it on all versions except for 7.0
47         # - env: DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
48         #   php: 5.6
49         #
50         # - env: DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
51         #   php: 5.5
53         - env: DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
54           php: 5.4
56 cache:
57     directories:
58       - $HOME/.composer/cache
60 install:
61     # Set the encrypted GITHUB_TOKEN if it's available to raise the API limit.
62     - if [ -n "$GITHUB_APITOKEN" ]; then composer config github-oauth.github.com $GITHUB_APITOKEN; fi
64     # Install composer dependencies.
65     # We need --no-interaction in case we hit API limits for composer. This causes it to fall back to a standard clone.
66     # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
67     - travis_retry composer install --prefer-dist --no-interaction
69 before_script:
70     - >
71       if [ "$INSTALL" = 'true' -o "$PHPUNIT" = 'true' ];
72       then
73         # Copy generic configuration in place.
74         cp config-dist.php config.php ;
76         # Create the moodledata directory.
77         mkdir -p "$HOME"/roots/base
79         # The database name and password.
80         sed -i \
81           -e "s%= 'moodle'%= 'travis_ci_test'%" \
82           -e "s%= 'password'%= ''%" \
83           config.php ;
85         # The wwwroot and dataroot.
86         sed -i \
87           -e "s%http://example.com/moodle%http://localhost%" \
88           -e "s%/home/example/moodledata%/home/travis/roots/base%" \
89           config.php ;
91         if [ "$DB" = 'pgsql' ];
92         then
93           # Postgres-specific setup.
94           sed -i \
95             -e "s%= 'username'%= 'postgres'%" \
96             config.php ;
98           psql -c 'CREATE DATABASE travis_ci_test;' -U postgres;
99         fi
101         if [ "$DB" = 'mysqli' ];
102         then
103           # MySQL-specific setup.
104           sed -i \
105             -e "s%= 'pgsql'%= 'mysqli'%" \
106             -e "s%= 'username'%= 'travis'%" \
107             config.php;
109           mysql -u root -e 'SET GLOBAL innodb_file_format=barracuda;' ;
110           mysql -u root -e 'SET GLOBAL innodb_file_per_table=ON;' ;
111           mysql -e 'CREATE DATABASE travis_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
112         fi
114         if [ "$PHPUNIT" = 'true' ];
115         then
116           # Create a directory for the phpunit dataroot.
117           mkdir -p "$HOME"/roots/phpunit
119           # The phpunit dataroot and prefix..
120           sed -i \
121             -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
122             -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
123             config.php ;
125           # Initialise PHPUnit for Moodle.
126           php admin/tool/phpunit/cli/init.php
127         fi
128       fi
130 script:
131     ########################################################################
132     # PHPUnit
133     ########################################################################
134     - >
135       if [ "$PHPUNIT" = 'true' ];
136       then
137         vendor/bin/phpunit;
138       fi
140     ########################################################################
141     # CI Tests
142     ########################################################################
143     - >
144       if [ "$CITEST" = 'true' ];
145       then
146         # Note - this is deliberately placed in the script section as we
147         # should not add any code until after phpunit has run.
149         # The following repositories are required.
150         # The local_ci repository does the actual checking.
151         git clone https://github.com/moodlehq/moodle-local_ci.git local/ci
153         # We need the official upstream for comparison
154         git remote add upstream https://github.com/moodle/moodle.git;
156         git fetch upstream MOODLE_30_STABLE;
157         export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
158         export GIT_COMMIT="$TRAVIS_COMMIT";
159         export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
161         # Variables required by our linter.
162         export gitcmd=`which git`;
163         export gitdir="$TRAVIS_BUILD_DIR";
164         export phpcmd=`which php`;
165       fi
167     # Actually run the CI Tests - do this outside of the main test to make output clearer.
168     - >
169       if [ "$CITEST" = 'true' ];
170       then
171         bash local/ci/php_lint/php_lint.sh;
172       fi