Today I was working on setting up Travis CI for Cronhub builds. It took me around two hours to make it work. I was expecting the integration should be a breeze, but Travis CI configuration is not trivial. It has many moving pieces, and everything should be in place.
Since I finally got it working, I thought I’d share my
.env.travis files to save you time.
Make sure to use the
xenial Ubuntu dist in your travis.yml file and add
mysql externally under the services. This will tell your build to install the latest stable version of MySQL. Otherwise, your migrations are going to fail due to an older version of MySQL.
dist: bioniclanguage: phpphp:
- vendorbefore_script: - cp .env.travis .env - sudo mysql -e 'create database homestead;' - composer self-update - composer install --prefer-source --no-interaction --dev - php artisan key:generate - php artisan migratescript: - vendor/bin/phpunit
Nothing special here just make sure you set DB_CONNECTION to
database.php file you need to add a new connection as follows:
...'testing' => [ 'driver' => 'mysql', 'host' => env('DB_TEST_HOST', 'localhost'), 'database' => env('DB_TEST_DATABASE', 'homestead'), 'username' => env('DB_TEST_USERNAME', 'homestead'), 'password' => env('DB_TEST_PASSWORD', 'secret'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false,],...
Once you do everything here, your build should start getting green. I hope this is useful and let me know if you have questions.