Travis CI host edilmiş bir sürekli entegrasyon servisidir. Kullanmak için, Travis CI'ı GitHub projenizin ayarlarına bir servis olarak eklemeniz ve GitHub projenizi Travis CI hesabınızda aktif hale getirmeniz gerekir. Hepsi bu kadar! Jenkins'e baktığımız zaman, kendi sisteminize kurulumu yapıldıktan sonra konfigürasyon yapılması gerekir ki bu işlemler genelde zorlayıcı olur. Şimdi sözü kıs kesip, size bilmek istediklerini göstereceğim.

Örneğimizde bir symfony uygulaması kullanacağız ve test olarak, "test" ortamında php-cs-fixer, phpspec ve behat testlerini çalıştıracağız. Bununla birlikte behat testler için bir virtual host kuracağız. Uygulamamızın ismi travis, virtual hostumuzun ismi ise travis.dev olacak.


Bilinmesi gerekenler



Kurulum


Kurulum ile ilgili iyi bir bilgi isterseniz Travis CI for Complete Beginners adresini ziyaret etmenizi tavsiye ederim. Projenizde, GitHub ayarlarında ve Travis CI hesabınızda ne tür şeyler yapmanız gerektiği tek tek belirtilmiş.


Konfigürasyon dosyaları


Aşağıda da gördüğünüz gibi, satırları mümkün olduğunca açıkladım bu nedenle daha fazla açıklamaya gerek duyacağınızı zannetmiyorum.


.travis.yml


Dosya ismi .travis.yml mecburidir. Dosyayı projenin temelinde tutacaksınız.


language: php

cache:
directories:
# Cache composer directory ...
- $HOME/.composer/cache

php:
# Test against the given PHP version ...
- 5.6

env:
global:
# Set build specific variables ...
- SOURCE_DIR=src
- VHOST_FILE=.travis.vhost
- VHOST_CONF=travis.conf
- VHOST_URL=travis.dev

install:
# Install Apache web server and FastCGI module ...
- sudo apt-get install apache2 libapache2-mod-fastcgi > /dev/null

before_script:
# Enable PHP-FPM and FastCGI ...
- sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
- sudo a2enmod rewrite actions fastcgi alias
- echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
# Disable Xdebug ...
- phpenv config-rm xdebug.ini
# Configure application's virtual host ...
- sudo cp -f $VHOST_FILE /etc/apache2/sites-available/$VHOST_CONF
- sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/$VHOST_CONF
- sudo sed -e "s?%VHOST_URL%?$VHOST_URL?g" --in-place /etc/apache2/sites-available/$VHOST_CONF
- echo "127.0.0.1 $VHOST_URL" | sudo tee -a /etc/hosts
- sudo a2enmod rewrite
- sudo a2ensite $VHOST_CONF
- sudo service apache2 restart
# Set application parameters ...
- cp app/config/parameters.yml.dist app/config/parameters.yml
# Composer install ...
- travis_retry composer install --no-interaction
# Remove application cache and logs ...
- rm -Rf app/cache/*
- rm -Rf app/logs/*
# Prepare application cache ...
- php app/console cache:warm --env=test
# Grant application cache and logs permissions ...
- chmod -Rf 777 app/cache/
- chmod -Rf 777 app/logs/
# Install application assets ...
- php app/console assets:install --symlink --relative --env=test
- php app/console assetic:dump --no-debug --env=test
# Create application database ...
- php app/console doctrine:schema:create --env=test
# Update application doctrine entities ...
- php app/console doctrine:generate:entities ApplicationTravisBundle --no-backup --env=test
# Load application data fixtures ...
- php app/console doctrine:fixtures:load --no-interaction --no-debug --env=test

script:
# Check coding standards ...
- bin/php-cs-fixer fix $SOURCE_DIR --dry-run --diff --verbose --fixers=-yoda_conditions,-phpdoc_align,short_array_syntax
# Run phpspec tests ...
- bin/phpspec run --no-ansi --format=dot
# Run behat tests ...
- bin/behat --profile=default -f progress

.travis.vhost


Dosya ismi .travis.vhost mecburi değildir. Sadece .travis.yml ismine benzesin diye o şekilde adlandırdım. Dosyayı projenin temelinde tutacaksınız. Build çalıştırıldığında yukarıdaki yml dosyasındaki virtual host ile ilgili komutlar TRAVIS_BUILD_DIR ve VHOST_URL değişkenlerini değiştirecektir.


<VirtualHost *:80>

DocumentRoot %TRAVIS_BUILD_DIR%/web
ServerName %VHOST_URL%

<Directory "%TRAVIS_BUILD_DIR%/web">
Options FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>

# Wire up Apache to use Travis CI's php-fpm.
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
</IfModule>

ErrorLog ${APACHE_LOG_DIR}/%VHOST_URL%.error.log
CustomLog ${APACHE_LOG_DIR}/%VHOST_URL%.access.log common

</VirtualHost>

İmajlar


Travis CI proje ayarları



GitHub içindeki başarılı sonuç



Travis CI içindeki başarılı sonuç



GitHub içindeki başarısız sonuç



Travis CI içindeki başarısız sonuç