What are the differences between the {before_,}{install,script} .travis.yml options?

Daniele Orlando picture Daniele Orlando · Dec 20, 2015 · Viewed 10.3k times · Source

Inside the .travis.yml configuration file what is the practical difference between before_install, install, before_script and script options?

I have found no documentation explaining the differences between these options.

Answer

localheinz picture localheinz · Dec 20, 2015

You don't need to use these sections, but if you do, you communicate the intent of what you're doing:

before_install:
  # execute all of the commands which need to be executed 
  # before installing dependencies
  - composer self-update
  - composer validate

install:
  # install all of the dependencies you need here
  - composer install --prefer-dist

before_script:
  # execute all of the commands which need to be executed 
  # before running actual tests
  - mysql -u root -e 'CREATE DATABASE test'
  - bin/doctrine-migrations migrations:migrate

script:
  # execute all of the commands which 
  # should make the build pass or fail
  - vendor/bin/phpunit
  - vendor/bin/php-cs-fixer fix --verbose --diff --dry-run

See, for example, https://github.com/localheinz/composer-normalize/blob/0.8.0/.travis.yml.