Share
Embed
Travis CI - Testiranje open source projekata
Bez obzira na to da li ste zagovornik test-driven razvoja ili mrzitelj istog, većina se slaže da je testiranje koda korisan, ako ne i nužnan, dio razvojnog ciklusa. Ovo predavanje će pokazati kako koristiti Travis CI platformu kako bi testirali svoj PHP projekt pri svakom pushu na GitHub.
Ivan Habunek
September 14, 2013
Transcript
54 slides
-
IVAN HABUNEK @IHABUNEK voditelj tima razvojnih programera u Zagrebačkoj burzi
Apache Software Foundation PMC member preko 10 godina iskustva u struci open source entuzijast u strci s vremenom -
ORGANIZACIJA PROJEKTA D : \ P r o j e
c t s \ t r a v i s - d e m o + - - p h p u n i t . x m l + - - R E A D M E . m d | + - - - s r c | \ - - R a n d o m . p h p | \ - - - t e s t s \ - - R a n d o m T e s t . p h p omg windowz wtf n00b -
KÔD / s r c / R a n d
o m . p h p c l a s s R a n d o m { p u b l i c f u n c t i o n g e t R a n d o m N u m b e r ( ) { / / C h o o s e n b y a f a i r d i c e r o l l . / / G u a r a n t e e d t o b e r a n d o m . r e t u r n 4 ; } } http://xkcd.com/221/ -
TESTOVI / t e s t s / R a
n d o m T e s t . p h p r e q u i r e _ _ D I R _ _ . ' / . . / s r c / R a n d o m . p h p ' ; c l a s s R a n d o m T e s t e x t e n d s P H P U n i t _ F r a m e w o r k _ T e s t C a s e { p u b l i c f u n c t i o n t e s t G e t R a n d o m N u m b e r ( ) { $ r a n d o m = n e w R a n d o m ( ) ; $ a c t u a l = $ r a n d o m - > g e t R a n d o m N u m b e r ( ) ; $ t h i s - > a s s e r t S a m e ( 4 , $ a c t u a l ) ; } } -
CONFIGURE PHPUNIT / p h p u n i t
. x m l < p h p u n i t > < t e s t s u i t e > < d i r e c t o r y > t e s t s < / d i r e c t o r y > < / t e s t s u i t e > < / p h p u n i t > -
RUN PHPUNIT > p h p u n i t
P H P U n i t 3 . 7 . 2 1 b y S e b a s t i a n B e r g m a n n . C o n f i g u r a t i o n r e a d f r o m D : \ P r o j e c t s \ t r a v i s - d e m o \ p h p u n i t . x m l . T i m e : 0 s e c o n d s , M e m o r y : 2 . 7 5 M b O K ( 1 t e s t , 1 a s s e r t i o n ) -
KONTINUIRANA INTEGRACIJA Continuous Integration is a software development practice where
members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. MARTIN FOWLER (2006) http://www.martinfowler.com/articles/continuousIntegration.html -
RUČNA PROVEDBA CI okolina na razvojnom stroju je potencijalno kontaminirana
testiranje ovisi o developeru ("ma bit će ok" sindrom) zahtjevno testiranje pull requestova -
a hosted continuous integration service for the open source community
distribuiran otvorenog kôda besplatan za sve javne projekte na GitHubu -
Programski jezici: C C++ Clojure Erlang Go Groovy Haskell Java
JavaScript Objective-C Perl PHP Python Ruby Scala -
Servisi i baze podataka: MySQL PostgreSQL MongoDB CouchDB Redis Riak
RabbitMQ Memcached Cassandra Neo4J ElasticSearch Kestrel SQLite3 -
PHP moduli: bcmath bz2 Core ctype curl date dom ereg
exif fileinfo filter ftp gd gettext hash iconv intl json libxml mbstring mcrypt mysql mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql pdo_pgsql pdo_sqlite pgsql Phar posix readline Reflection session shmop SimpleXML soap sockets SPL sqlite3 standard sysvsem sysvshm tidy tokenizer xdebug xml xmlreader xmlrpc xmlwriter xsl zip zlib -
PUSH! > g i t p u s h C
o u n t i n g o b j e c t s : 1 0 , d o n e . D e l t a c o m p r e s s i o n u s i n g u p t o 2 t h r e a d s . C o m p r e s s i n g o b j e c t s : 1 0 0 % ( 7 / 7 ) , d o n e . W r i t i n g o b j e c t s : 1 0 0 % ( 7 / 7 ) , 7 7 7 b y t e s , d o n e . T o t a l 7 ( d e l t a 3 ) , r e u s e d 0 ( d e l t a 0 ) T o h t t p s : / / g i t h u b . c o m / i h a b u n e k / t r a v i s - d e m o . g i t 8 b f 4 a 4 d . . 2 c b 2 3 e b m a s t e r - > m a s t e r -
.TRAVIS.YML ODABIR VERZIJE l a n g u a g
e : p h p p h p : 5 . 4 -
.TRAVIS.YML VIŠE VERZIJA l a n g u a g
e : p h p p h p : - 5 . 2 - 5 . 3 - 5 . 4 - 5 . 5 -
.TRAVIS.YML SCRIPT (DEFAULT) l a n g u a g
e : p h p p h p : - 5 . 3 - 5 . 4 - 5 . 5 s c r i p t : p h p u n i t -
.TRAVIS.YML SCRIPT l a n g u a g e
: p h p p h p : - 5 . 3 - 5 . 4 - 5 . 5 s c r i p t : p h p u n i t - - c o n f i g u r a t i o n e t c / p h p u n i t . x m l -
.TRAVIS.YML SCRIPT l a n g u a g e
: p h p p h p : - 5 . 3 - 5 . 4 - 5 . 5 s c r i p t : . / b i n / b u i l d . s h -
TESTIRANJE U VIŠE OKOLINA D : \ P r o
j e c t s \ t r a v i s - d e m o + - - p h p u n i t . x m l + - - R E A D M E . m d | + - - - e t c | + - - p o s t g r e s . p h p u n i t . x m l | + - - m y s q l . p h p u n i t . x m l | \ - - s q l i t e . p h p u n i t . x m l | + - - - s r c | \ - - R a n d o m . p h p | \ - - - t e s t s \ - - R a n d o m T e s t . p h p -
BUILD MATRIX l a n g u a g e
: p h p e n v : - D B = p o s t g r e s - D B = m y s q l - D B = s q l i t e p h p : - 5 . 3 - 5 . 4 - 5 . 5 s c r i p t : p h p u n i t - - c o n f i g u r a t i o n e t c / $ D B . p h p u n i t . x m l -
SCRIPTS b e f o r e s c r
i p t : e c h o " Z d r a v o s v i j e t e " a f t e r _ s c r i p t : - e c h o " T a k o m i m l i j e k a u p r a h u " - e c h o " G i b a m n a l i j e v o " a f t e r _ s u c c e s s : e c h o " O h y e s s ! " a f t e r _ f a u l u r e : e c h o " O h n o e s ! " -
DEPENDANCY MANAGEMENT COMPOSER.JSON { " r e q u i
r e " : { " s y m f o n y / c o n s o l e " : " 2 . 3 . * " } } .TRAVIS.YML l a n g u a g e : p h p p h p : - 5 . 3 - 5 . 4 - 5 . 5 b e f o r e _ s c r i p t : - c o m p o s e r i n s t a l l -
PECL .TRAVIS.YML b e f o r e _ s
c r i p t : - p e c l i n s t a l l o a u t h -
RUČNA INSTALACIJA .TRAVIS.YML l a n g u a g
e : p h p p h p : - 5 . 3 - 5 . 4 - 5 . 5 b e f o r e _ s c r i p t : - w g e t h t t p : / / g o o g l e - a p i - p h p - c l i e n t . g o o g l e c o d e . c o m / f i l e s / g o o g l e - a p i - p h p - c l i e n t - 0 . 6 . 6 . t a r . g z - m k d i r v e n d o r - t a r x z v f g o o g l e - a p i - p h p - c l i e n t - 0 . 6 . 6 . t a r . g z - C v e n d o r -
.TRAVIS.YML NOTIFICATIONS n o t i f i c a
t i o n s : e m a i l : - i v a n . h a b u n e k @ g m a i l . c o m - i v a n @ b e z d o m n i . n e t -
.TRAVIS.YML NOTIFICATIONS n o t i f i c a
t i o n s : i r c : - " i r c . f r e e n o d e . o r g # z g p h p " -
.TRAVIS.YML NOTIFICATIONS n o t i f i c a
t i o n s : w e b h o o k s : u r l s : - h t t p : / / b e z d o m n i . n e t / h o o k s / t r a v i s { " i d " : 1 1 1 2 7 9 1 0 , " r e p o s i t o r y " : { " i d " : 1 2 2 0 4 1 7 , " n a m e " : " t r a v i s - d e m o " , " o w n e r _ n a m e " : " i h a b u n e k " , " u r l " : " h t t p s : \ / \ / g i t h u b . c o m \ / i h a b u n e k \ / t r a v i s - d e m o " } , " n u m b e r " : " 2 5 " , " c o n f i g " : { " l a n g u a g e " : " p h p " , " p h p " : [ 5 . 3 , 5 . 4 , 5 . 5 ] , " b e f o r e _ s c r i p t " : [ " c o m p o s e r s e l f - u p d a t e " , " c o m p o s e r i n s t a l l " ] , " n o t i f i c a t i o n s " : { " w e b h o o k s " : { " u r l s " : [ -
API G E T h t t p s :
/ / a p i . t r a v i s - c i . o r g / b u i l d s / 1 1 1 2 7 9 1 0 { " b u i l d " : { " i d " : 1 1 1 2 7 9 1 0 , " r e p o s i t o r y _ i d " : 1 2 2 0 4 1 7 , " c o m m i t _ i d " : 3 2 6 6 0 4 8 , " n u m b e r " : " 2 5 " , " p u l l _ r e q u e s t " : f a l s e , " s t a t e " : " p a s s e d " , " s t a r t e d _ a t " : " 2 0 1 3 - 0 9 - 0 8 T 1 8 : 2 5 : 2 8 Z " , " f i n i s h e d _ a t " : " 2 0 1 3 - 0 9 - 0 8 T 1 8 : 2 6 : 0 3 Z " , " d u r a t i o n " : 6 8 , . . . } , " c o m m i t " : { " i d " : 3 2 6 6 0 4 8 , " s h a " : " f b 7 5 7 c 4 3 a 9 6 f 6 c f 8 8 8 6 d 6 1 2 9 4 3 d a 5 7 a 9 c 0 6 a 6 1 6 c " , " b r a n c h " : " m a s t e r " , " m e s s a g e " : " T e s t i n g I R C n o t i f i c a t i o n s " , " c o m m i t t e d _ a t " : " 2 0 1 3 - 0 9 - 0 8 T 1 8 : 2 4 : 5 7 Z " , " a u t h o r _ n a m e " : " I v a n H a b u n e k " , " a u t h o r _ e m a i l " : " i v a n . h a b u n e k @ g m a i l . c o m " , " c o m m i t t e r _ n a m e " : " I v a n H a b u n e k " , " c o m m i t t e r _ e m a i l " : " i v a n . h a b u n e k @ g m a i l . c o m " , " c o m p a r e _ u r l " : " h t t p s : \ / \ / g i t h u b . c o m \ / i h a b u n e k \ / t r a v i s - d e m o \ / c o m p a r e \ / 5 9 c f d } . . . } -
CLI > g e m i n s t a
l l t r a v i s > t r a v i s h e l p A v a i l a b l e c o m m a n d s : a c c o u n t s d i s p l a y s a c c o u n t s a n d t h e i r s u b s c r i p t i o n s t a t u s b r a n c h e s d i s p l a y s t h e m o s t r e c e n t b u i l d f o r e a c h b r a n c h c a n c e l c a n c e l s a j o b o r b u i l d c o n s o l e i n t e r a c t i v e s h e l l d i s a b l e d i s a b l e s a p r o j e c t e n a b l e e n a b l e s a p r o j e c t e n c r y p t e n c r y p t s v a l u e s f o r t h e . t r a v i s . y m l e n d p o i n t d i s p l a y s o r c h a n g e s t h e A P I e n d p o i n t h e l p h e l p s y o u o u t w h e n i n d i r e n e e d o f i n f o r m a t i o n h i s t o r y d i s p l a y s a p r o j e c t s b u i l d h i s t o r y i n i t g e n e r a t e s a . t r a v i s . y m l a n d e n a b l e s t h e p r o j e c t l o g i n a u t h e n t i c a t e s a g a i n s t t h e A P I a n d s t o r e s t h e t o k e n l o g s s t r e a m s t e s t l o g s m o n i t o r l i v e m o n i t o r f o r w h a t ' s g o i n g o n o p e n o p e n s a b u i l d o r j o b i n t h e b r o w s e r p u b k e y p r i n t s o u t a r e p o s i t o r y ' s p u b l i c k e y r a w m a k e s a n ( a u t h e n t i c a t e d ) A P I c a l l a n d p r i n t s o u t t h e r e s u l t r e s t a r t r e s t a r t s a b u i l d o r j o b s e t u p s e t s u p a n a d d o n o r d e p l o y t a r g e t s h o w d i s p l a y s a b u i l d o r j o b s t a t u s c h e c k s s t a t u s o f t h e l a t e s t b u i l d s y n c t r i g g e r s a n e w s y n c w i t h G i t H u b t o k e n o u t p u t s t h e s e c r e t A P I t o k e n v e r s i o n o u t p u t s t h e c l i e n t v e r s i o n -
CLI > t r a v i s h i
s t o r y # 2 5 p a s s e d : m a s t e r T e s t i n g I R C n o t i f i c a t i o n s # 2 1 p a s s e d : m a s t e r T e s t i n g n o t i f i c a t i o n s # 2 0 p a s s e d : m a s t e r R e m o v e d t e s t i n g o n 5 . 2 # 1 9 e r r o r e d : m a s t e r A d d e d ' c o m p o s e r i n s t a l l ' t o t r a v i s . y m l # 1 8 p a s s e d : m a s t e r A d d e d d e p e n d e n c y o n s y m f o n y / c o n s o l e # 1 7 p a s s e d : m a s t e r M e r g e p u l l r e q u e s t # 3 f r o m i h a b u n e k / c o r r e c t a m o n d o # 1 6 p a s s e d : P u l l R e q u e s t # 3 A d d e d a n o d t o X K C D -
CLI > t r a v i s s h
o w 2 5 B u i l d # 2 5 : T e s t i n g I R C n o t i f i c a t i o n s S t a t e : p a s s e d T y p e : p u s h B r a n c h : m a s t e r C o m p a r e U R L : h t t p s : / / g i t h u b . c o m / i h a b u n e k / t r a v i s - d e m o / c o m p a r e / 5 9 c f d 3 4 c 8 6 0 a . . . f b 7 5 7 D u r a t i o n : 1 m i n 8 s e c S t a r t e d : 2 0 1 3 - 0 9 - 0 8 2 0 : 2 5 : 2 8 F i n i s h e d : 2 0 1 3 - 0 9 - 0 8 2 0 : 2 6 : 0 3 # 2 5 . 1 p a s s e d : 2 6 s e c p h p : 5 . 3 # 2 5 . 2 p a s s e d : 1 8 s e c p h p : 5 . 4 # 2 5 . 3 p a s s e d : 2 4 s e c p h p : 5 . 5 -
PHP TRAVIS CLIENT https://github.com/l3l0/php-travis-client $ c l i e n
t = n e w T r a v i s \ C l i e n t ( ) ; $ r e p o = $ c l i e n t - > f e t c h R e p o s i t o r y ( ' i h a b u n e k / t r a v i s - d e m o ' ) ; e c h o " B u i l d s : \ n " ; f o r e a c h ( $ r e p o - > g e t B u i l d s ( ) a s $ b u i l d ) { $ i d = $ b u i l d - > g e t I D ( ) ; $ r e s u l t = $ b u i l d - > g e t R e s u l t ( ) ? " P a s s e d " : " F a i l e d " ; e c h o " - $ i d : $ r e s u l t \ n " ; } -
STATUSNA SLIKA h t t p s : / /
t r a v i s - c i . o r g / < u s e r n a m e > / < p r o j e c t > . p n g h t t p s : / / t r a v i s - c i . o r g / i h a b u n e k / t r a v i s - d e m o . p n g Prikazuje jedno od: