ã¨ããPHPæ¡å¼µã®CIäºæ
PHP Advent Calendar 2017ã®3æ¥ç®ã§ããå ¬éãé ããªã£ã¦ãã¾ãã¾ãããããããªããã
çè
ã¯php-timecopã¨ããPHPæ¡å¼µã5å¹´éã»ã©ã¡ã³ããã³ã¹ãã¦ãã¾ãããã®PHPæ¡å¼µã¯Cã§æ¸ããã¦ããã®ã§ãããTravis CIãAppVeyorãªã©è¤æ°ã®ã¯ã©ã¦ãCIãµã¼ãã¹ãçµã¿åããã¦ãã¹ããåãã¦ãã¾ããæ¬ç¨¿ã§ã¯åãµã¼ãã¹ãã©ã®ããã«å©ç¨ãã¦ããããããããã®ä½¿ãåããç¹å¾´ãªã©ãç´¹ä»ãã¦ããããã¨æãã¾ãã
èæ¯
æ¬é¡ã«å ¥ãã¾ãã«ããªãPHPæ¡å¼µã§CIãå¿ è¦ããã¨ãã話ãç´¹ä»ãã¾ãã
Cè¨èªã§æ¸ãããããã°ã©ã ã¯ãã¼ã¿ããªãã£ãé«ããããªå°è±¡ãæã¤äººãå¤ãããããã¾ããããå®éã¯ãããéã§ããã¼ã¿ãã«ã«æ¸ãã®ãé£ããè¨èªã®1ã¤ã§ããCã§ã¯ã·ã¹ãã ã³ã¼ã«ãã©ã¤ãã©ãªé¢æ°ãç´æ¥å¼ã³åºãã®ãæ®éã§ããããããã¯ç°å¢ã«ãã£ã¦åå¨ããªããã¨ãããã¾ãããç´°ããæåãç°ãªããã¨ãçããããã¾ãããã¾ããã³ã³ãã¤ã©ãã¨ã®æ¹è¨ãåå¨ãã¾ãã
ããããäºæ
ãããCè¨èªã§æ¸ããã¦ããOSSã§ã¯ç°å¢ã®å·®ãåããããã«Autoconf/Automake/Libtoolãå©ç¨ããã®ãå®çªã§ãããããã§ãæªç¥ã®ç°å¢ã§ãªã³ã¯ã«å¤±æãããã¨ãçããããã¾ããããç°å¢ã®å·®ãæ¤åºããããã®configure
ã¹ã¯ãªããããã°ã§åæ¢ãããããªãã¨ãèµ·ããããã®ã§ãåç°å¢ã§ãã¹ããã¦ããã«è¶ãããã¨ã¯ããã¾ããã
ããã«é¢åãªãã¨ã«ãPHPæ¡å¼µã§ã¯PHPæ¬ä½ã®C APIãå¼ã³åºãããæ¬ä½ã§å®ç¾©ããã¦ããæ§é ä½ãæä½ããããããã¨ãããã®ã§ãPHPã®ç¹å®ãã¼ã¸ã§ã³ã§ã ãåããªããã¨ãããããªãã°ããããã¾ãã
è¦ããã«ãPHPæ¡å¼µãã¡ã³ããã³ã¹ããããã«ã¯ãæ§ã
ãªOSãã³ã³ãã¤ã©ãPHPãã¼ã¸ã§ã³ã®çµã¿åããã§ãã¹ãããç¶ããå¿
è¦ãããã®ã§ããã²ã¨ãã¨ã§è¨ãã°å°çã®ãããªç¶æ³ ãã¸ãã£ããªè¨ããããããã¨ãã¨ã¦ãCIãããã®ããé¡æã ã¨è¨ããã§ãããã
åCIãµã¼ãã¹ã®ç¹å¾´ã¨å®éã®ä½¿ãæ¹
php-timecopã§ç¾å¨å©ç¨ãã¦ããCIãµã¼ãã¹ã¯ä¸è¨ã®4ã¤ã§ãã
ãããã®ãµã¼ãã¹ãç¡æãã©ã³ã§å©ç¨ãã¦ãã¾ããçè
èªèº«ããã®PHPæ¡å¼µã§ãéãå¾ã¦ããããã§ã¯ãªãã®ã§ãéãæã£ã¦ã¾ã§CIããæ°ã«ã¯ãªããªãã§ãããå社ããOSSã¸ã®å¿æ´ã®æå³ãè¾¼ãã¦å
¬éãªãã¸ããªã®CIãç¡æã§æä¾ãã¦ããã¨æãã®ã§ãããããã使ããã¦ããã£ã¦ãã¾ãã
以ä¸ãåå¥ã®ãµã¼ãã¹ã«ã¤ãã¦ç´¹ä»ãã¾ãã
Travis CI
è¨ããã¨ç¥ããæ大æã¯ã©ã¦ãCIãµã¼ãã¹ã§ãã
- Linuxï¼Ubuntuï¼ã¨macOSã®2ã¤ã®OSä¸ã§CIã§ãã
- PHP 5.4ãã7.2ã¾ã§ã®6ãã¼ã¸ã§ã³ããã«ãæ¸ã¿ãè¨å®ã§ç°¡åã«åãæ¿ããããï¼è¨äºå·çæï¼
- ç¡æãã©ã³ã§ã¯æ大5並åã§ã¸ã§ããèµ°ã
ç¡æãã©ã³ã§ãããªãã®å¤§ç¤æ¯ãèããªã®ã§ãOSSã§CIãããå ´åã¯æåã®é¸æè¢ã«ãªãã§ãããã
ã¾ããPHPæ¡å¼µã®CIã«é¢ãã¦ããã¨PHPã®å ¨ãã¤ãã¼ãã¼ã¸ã§ã³ã®ææ°çãæä¾ããã¦ããã®ãç´ æ´ãããç¹ã§ããPHPã§ã¯ãã¤ãã¼ãã¼ã¸ã§ã³ã¢ããã®ã¿ã¤ãã³ã°ã§å é¨æ§é ã®å¤§å¤æ´ãå ¥ããã¨ãçãããªãï¼5.3â5.4ãªã©ï¼ã®ã§ãå ¨ãã¤ãã¼ãã¼ã¸ã§ã³ã§ãã¹ãããã®ã¯é常ã«éè¦ã§ãããããè¨å®ãå°ãæ¸ãã ãã§ç°¡åã«å¯¾å¿ã§ããã®ã¯æ¬å½ã«å©ããã¾ãã
å®éãçè ã¯Linuxç°å¢ä¸ã§7ã¤ã®PHPãã¼ã¸ã§ã³*1ã®ãã¹ããèµ°ããã¦ãã¾ãã
Travis CIã§ã¯ãã«ãæ¸ã¿ã®PHPãã¤ããªãZTSï¼Zend Thread Safeï¼æå¹ã«ãªã£ã¦ããã®ãç¹å¾´çã§ãã大æµã®äººã¯PHPãNTSï¼Non Thread Safeï¼ã§å©ç¨ãã¦ããã¯ããªã®ã§ãããæå³ãã¹ãç°å¢ã¨ãã¦ä¸é©åã¨è¨ããªããããã¾ãããä¸æ¹ã§ãZTSã§ã ããã«ããéããªããããªãã°ãããããã®ã§ãå人çã«ã¯ãã¹ãç°å¢ã¨ãã¦ãããããã¨æãã¾ãã
AppVeyor
Windowsç°å¢ã®CIãå¿
è¦ãªãã»ã¼å¯ä¸ã®é¸æè¢*2ã¨è¨ããã§ãããã
- Windowsç°å¢ã§ã®ãã«ãã«å¯¾å¿
PHPã®Windowsçã¯ãã¼ã¸ã§ã³ãã¨ã«è¦æ±ããVisual C++ã®ãã¼ã¸ã§ã³ãç°ãªããããèªåã§CIç°å¢ãæºåããã®ã¯æ¯è¼çé¢åã§ãããã®æå³ã§ãã¯ã©ã¦ãCIãµã¼ãã¹ãå©ç¨ã§ããã®ã¯è¯ãã§ããã
php-timecopã§ã¯ç¾å¨PHP 5.4ãPHP5.6ãPHP 7.1ã®3ãã¼ã¸ã§ã³ã§ãã¹ããè¡ã£ã¦ãã¾ãã
Wercker
æè¿Oracleã«è²·åãããã¯ã©ã¦ãCIãµã¼ãã¹ã§ããããã¼ãã¼ãã¨èªããããã§ãããCIç°å¢ãæ´ããå½æãDockerã³ã³ããã®æ±ããä¸çªæ¥½ããã ã£ãã®ã§å©ç¨ãããã¨ã«ãã¾ããã
php-timecopã§ã¯CentOSã¨32bit Ubuntuã®2ç°å¢ã§ã®ãã¹ããèµ°ãããã®ã«å©ç¨ãã¦ãã¾ãã
CentOSã§ã®ãã¹ãã¯ãspecãã¡ã¤ã«ã«ãããã¤ããªããã±ã¼ã¸ä½æã®åä½ç¢ºèªã®ããã«è¡ã£ã¦ãã¾ããé常Linuxãã£ã¹ããªãã¥ã¼ã·ã§ã³ãã¨ã®ãã¹ããè¡ãå¿ è¦æ§ã¯ãã¾ãç¡ãã¨æãã¾ãããããã±ã¼ã¸ã³ã°ã®ãã¹ããããã¤ããªããã±ã¼ã¸ã®ãããã¤ãªã©ã®å¿ è¦æ§ãããã°ãã£ã¹ããªãã¥ã¼ã·ã§ã³ã®æ°ãå¢ããå¿ è¦ãããã§ãããã
ä¸æ¹ã32bit Ubuntuã§ã®ãã¹ãã¯æ¡å¼µèªä½ã®ãã¹ãç®çã§ããPHPã¯32bitç°å¢ã¨64bitç°å¢ã¨ã§æ´æ°ã®ãµã¤ãºãå¤ãããªã©è¨èªã¬ãã«ã§å½±é¿ãããã®ã§ã32bitç°å¢ã§ã®ãã¹ãã«ã¯ååæå³ãããã¾ãã
CircleCI
ã¯ã©ã¦ãCIãµã¼ãã¹ã®ä¸ã§ãæåã©ããã®1ã¤ã§ããæè¿å¤§å¹ ãã¼ã¸ã§ã³ã¢ãããã¦ã³ã³ãããã¼ã¹ã«ãªã£ãã¨èãã¾ããããçè ã¯ã¾ã å¤ããã¼ã¸ã§ã³ãå©ç¨ãã¦ãã¾ãã
ç¾ç¶ã§ã¯NTSç°å¢ã§ã®ãã¹ãã®æå³ã§èµ°ããã¦ããã ãã§ããã¾ãæ´»ç¨ã§ãã¦ãã¾ããã
å®éã«CIã¯æç¨ãï¼
PHPæ¡å¼µã§ã®CIãåãã¦ã¿ã¦å人çã«ã¯é常ã«æç¨ã ã¨æãã¦ãã¾ãã客観ç証æ ã®ãããªãã®ã¯æãã«ããã®ã§ãããã¡ãªããã ã¨æãããå 容ãä½ç¹ãç´¹ä»ãã¾ãã
ãã¨ãã°ãæ°æ©è½ãå®è£ ããã¨ããªã©ã大å¤æ´ã®éã¯CIã®ãããã§ç¹å®ãã¼ã¸ã§ã³ã§ã®ãã°ãæªç¶ã«é²ãããã¨ã¯çããããã¾ãããããã¾ã§ã®çµé¨ã¨ãã¦ã¯OSãã³ã³ãã¤ã©ã®å·®ã§æããããã¨ã¯ããã»ã©å¤ããªããPHPã®ç¹å®ãã¼ã¸ã§ã³ã§åããªããã°ãå¤ãã®ã§ãã¾ãã¯Travis CIã§è¤æ°PHPãã¼ã¸ã§ã³ã§ã®ãã¹ããèµ°ãããã®ããªã¹ã¹ã¡ã§ãã
ã¾ãããã£ãããã¹ãã§ãã¦ããã¨Pull Requestãåãåã£ãã¨ãã®å®å¿æã大ããã®ã§ããã®æå³ã§ããªã¹ã¹ã¡ã§ãã
PHP 5æ代ã¯ZTSç°å¢ã§å¿ è¦ãªããã¾ããªããã®ä»ãå¿ãã«CIã§æ°ã¥ããã¨ãããã¨ãé »ç¹ã«ããã¾ããããPHP 7ã«ãªã£ã¦ãã¾ããªããæ¸ã£ãã®ã§ãæè¿ã¯ãã¾ããããªãã¨ã¯ããã¾ããã
å¤ãã£ãã¨ããã§ã¯ãWindowsä¸ã§ãã¹ãã失æããã¨æã£ããWindowsçPHPã®ãã°ï¼ä»æ§ï¼ï¼ã ã£ããã¨ãããã¨ãããã¾ãããï¼åç
§ï¼ãPHPのsleep関数とusleep関数の挙動を調べてみたãï¼
ã¾ã¨ã
php-timecopã®CIã§ã¯è¤æ°ãµã¼ãã¹ãæ´»ç¨ãã¦ãããæç¨ã ã¨æãã¦ããã¨ãã話ãç´¹ä»ãã¾ãããã¾ãããã¹ãã®è»¸ãè¤æ°ãããã¨ãç´¹ä»ãã¾ããã
ä½åãCIãµã¼ãã¹ã使ãã®ã¯è¥å¹²è¶£å³çã«æãããããããã¾ããããLinuxã¨Windowsã®ä¸¡OSã«å¯¾å¿ããããã«Travis CIã¨AppVeyorã®2ãµã¼ãã¹ä½µç¨ããããã¾ã§ã¯ååå®ç¨çã ã¨æãã¾ãã
PHPæ¡å¼µãå ¬éãã¦ãããã©ãã¹ããã¦ãªãã¨ããæ¹ã¯php-timecopã®ãªãã¸ããªããè¨å®ãã¡ã¤ã«ãã³ãã¼ããã°ç°¡åã«å°å ¥ã§ãã¾ãã®ã§ããã²ã試ããã ããã