Travis CIã®cron jobsã使ã£ã¦GitHubã«å®æçã«commitããæ¹æ³
ã¿ãªãããTravis CI使ã£ã¦ã¾ããï¼Trais CIã¯ã¯ã©ã¦ãCIãµã¼ãã¹ã®1ã¤ã§ãGitHubä¸ã§å ¬éãã¦ããOSSãèªåãã¹ãããç®çã§ããã°å®çªä¸ã®å®çªã¨ãã£ã¦ãããµã¼ãã¹ã§ãã
ã¨ããã§ãããããç§ã®å ¬éãã¦ããããã¸ã§ã¯ããhnw/wsouiãã§ä»¥ä¸ã®ãã¨ãå®ç¾ãããã¨èãã¾ããã
- ãããä¸ã®ãã¼ã¿ãå å·¥ãã¦Goã®é£æ³é
åã®å½¢ã§æä¾ããã
- å¤æã¹ã¯ãªããã¯ä½ææ¸ã¿
- èªåæ´æ°ããã
- æ å ±ã½ã¼ã¹ã¯ä¸å®æã«æ´æ°ããã
- ããããææ°ã®ãã¼ã¿ãåæ ãã¦ãã¦ã»ãã
ãããå®ç¾ããæ¹æ³ã¯ä½ç¨®é¡ãæãã¤ãã¾ãããä»åTravis CI ã®cron jobsã使ã£ã¦1é±éã«1åãæ´æ°ããã£ãã¨ãã ãgit commit
ãããããªä»çµã¿ãä½ãã¾ããã®ã§ããããç´¹ä»ãã¾ãã
Travis CI ã®cron jobs
Travis CIã§ã¯ãgitãªãã¸ããªã«æ°ããªcommitãpushããããã³ã«ãã¹ãã¹ã¯ãªãããå®è¡ããã¾ããããã«ãããä¸ä¸ãã°ããã£ãå ´åã§ãæ©æã«æ°ä»ããã¨ãã§ããããã©ã®commitã§ã¨ã³ãã°ããã調ã¹ãææã«ãªã£ããããããã§ãã
ã¾ããcommitãã¨ã®ãã¹ãå®è¡ã¨ã¯å¥ã«ãå®æçã«ãã¹ããè¡ããããªæ©è½ãCron Jobsããæä¾ããã¦ãã¾ããããã¯Travis CIã®ã³ã³ã½ã¼ã«ç»é¢ãSettingsããCron Jobsãããè¨å®ã§ãã¾ãããã«ãééã¯æ¥æ¬¡ãé±æ¬¡ãæ次ã®ããããä¸ã¤ãé¸æã§ãã¾ãã
æ¬æ¥cron jobsã¯ä¾åã©ã¤ãã©ãªã®ãã¼ã¸ã§ã³ã¢ãããªã©ã§ä»¥åéã£ã¦ãããã¹ãã失æããããã«ãªã£ã¦ããªãããå®æçã«ãã§ãã¯ããæ©è½ã§ããä»åã®ããã«cron jobsã®ã¨ãã ãå¥ã®å¦çãè¡ãã¨ããã®ã¯å¤åçãªä½¿ãæ¹ã§ã¯ããã¾ãããè²ã ã¨ä¾¿å©ãªå¿ç¨ãèããããã®ã§ã¯ãªãã§ããããã
é常ã®ãã¹ãã¨èªåæ´æ°ã¨ã®å ±å
ãã¦ãTravis CIä¸ã§ã¸ã§ããå®æå®è¡ã§ãããã¨ã¯ãããã¾ããããã¹ãã¹ã¯ãªããå ã§ç°å¢å¤æ°ãè¦ãã°cron jobsãã©ããå¤å®ã§ãã¾ãããããå®æå®è¡ãããã¨ãã ãèªåæ´æ°ãå®è¡ãããã¨ããä»åã®ç®æ¨ã¯ååå®ç¾ã§ãããã§ãã
ã¨ã¯ããããã¹ãã¹ã¯ãªããã«ãã¹ã以å¤ã®å¦çã追è¨ãã¦ãã¾ãã¨ä¿å®æ§ãä¸ãã£ã¦ãã¾ãããããã¾ãããããå°ã綺éºã«å®ç¾ããæ¹æ³ã¯ãªãã®ã§ããããã
2018/6æç¹ã§ã¯Î²æ©è½ã§ãããTravis CIã«ã¯Build Stageã¨ããä»çµã¿ãããããcron jobsã®ã¨ãã ãå®è¡ããã·ã³ãã«ã«å®ç¾ãããã¨ãã§ãã¾ããå
·ä½çã«ã¯ã.travis.yml
ã次ã®ããã«è¨è¿°ã§ãã¾ãã
jobs: include: - stage: 'Test' script: - go test -v . - stage: 'Update Check' if: type = cron script: - [cron jobsã®ã¨ãã«å®è¡ãããã³ãã³ã1] ... - [cron jobsã®ã¨ãã«å®è¡ãããã³ãã³ã2] ...
ãã®ããã«è¨è¿°ããã¨æ®æ®µã¯ãã¹ãã ããå®è¡ããcron jobsã®ã¨ãã ããã¹ãæåå¾ã«ãUpdate Checkãå¦çãèµ°ãã¾ããå°ããªãã¨ã§ãããå¥ã®å¦çãå¥ã®å ´æã«è¨è¿°ã§ããæ¹ãå®å¿ã§ãããã
git commitããããã«
ãã¦ãããã¾ã§ã®ç¥èã§Travis CIä¸ã§curlã§ãã¼ã¿ãåã£ã¦ãã¦å¤æã¹ã¯ãªãããåããã¨ããã¾ã§ã¯ã§ãããã§ãããã¨ã¯çæããããã¡ã¤ã«ãgit commit
ããã ãã§ããããããæå¤ã¨é¢åã§ãã
ã¾ãã¯å¯¾è±¡ãªãã¸ããªã®ãããã¤ãã¼ãç¨æãã¾ããããã¯SSHéµãã¢ãæ°è¦ä½æããä¸ã§ãå ¬ééµãGitHubã®ãªãã¸ããªãã¼ã¸ãããSettingsããDeploy keysãã§è¨å®ãã¾ãã
$ ssh-keygen -t ed25519 -f /tmp/id_ed25519 $ cat /tmp/id_ed25519.pub ssh-ed25519 ******************************************************************** [email protected]
ä»åã®ããã«ãããã¤ãã¼ã§å¤é¨ããpushãããããªå ´åã¯ãAllow write accessãã¯å¿ é ã«ãªãã¾ãã®ã§æ³¨æãã¦ãã ããã
次ã«ãå ã»ã©çæããç§å¯éµãæå·åãã¦ãªãã¸ããªã«ã¢ãããã¼ããã¾ããã¾ãtravisã³ãã³ããã¤ã³ã¹ãã¼ã«ãã¦ãããå©ç¨ãã¾ãã
$ gem install travis (snip) $ travis encrypt-file /tmp/id_ed25519 Detected repository as hnw/wsoui, is this correct? |yes| encrypting /tmp/id_ed25519 for hnw/wsoui storing result as id_ed25519.enc storing secure env variables for decryption Please add the following to your build script (before_install stage in your .travis.yml, for instance): openssl aes-256-cbc -K $encrypted_****_key -iv $encrypted_****_iv -in id_ed25519.enc -out /tmp/id_ed25519 -d Pro Tip: You can add it automatically by running with --add. Make sure to add id_ed25519.enc to the git repository. Make sure not to add /tmp/id_ed25519 to the git repository. Commit all changes to your .travis.yml. $ git add id_ed25519.enc
æå·åããç§å¯éµã¯Travis CIä¸ã§å¾©å·ãã¦$HOME/.ssh/
以ä¸ã«ã³ãã¼ãã¦ä½¿ãã¾ããè¨å®ãã¡ã¤ã«.travis.yml
ã¯æçµçã«æ¬¡ã®ããã«ãªãã¾ããã
language: go go: - "1.10" jobs: include: - stage: 'Test' script: - go test -v . - stage: 'Update Check' if: type = cron script: - git checkout master - curl "https://code.wireshark.org/****" > /tmp/manuf - scripts/oui-convert.pl /tmp/manuf > ouidata.go - go test -v . - openssl aes-256-cbc -K $encrypted_****_key -iv $encrypted_****_iv -in id_ed25519.enc -out $HOME/.ssh/id_ed25519 -d - chmod 600 $HOME/.ssh/id_ed25519 - scripts/push-if-updated.sh ouidata.go
ããã§æ³¨æãã¹ããã¨ã§ãããTravis CIã®ãã¹ã対象ã¯ç¹å®commitã§ããGitã§ããã¨ããã®ãdetached HEADãã¨å¼ã°ããç¶æ ã«ãªã£ã¦ããããããã®ã¾ã¾ã§ã¯å ã®ãªãã¸ããªã«pushã§ãã¾ããããã®ãããã¾ãmasterãã©ã³ãã«åãæ¿ããã¨ããå¦çãè¡ã£ã¦ãã¾ããã¡ãã£ã¨ããTIPSã§ãããç§ã¯å°ã ãããã¾ããã
Travis CIä¸ã§èªåæ´æ°ãè¡ãã¡ãªãã
ä¸è¨è¨å®ã«ãããTravis CIä¸ã§èªããã¸ã§ã¯ãã®èªåæ´æ°ãã§ããããã«ãªãã¾ãããããããcronã§å®è¡ããã ãã§ããã°ãVPSãå©ç¨ãããã¨ãã§ãã¾ããããããæéãããã¦Travis CIã§å®è¡ããã¡ãªããã¯ä½ã§ããããã
å人çã«ã¯ãGitHub+Travis CIç°å¢ã§ã¯å®è¡ã«å¿ è¦ãªå ¨ãã¡ã¤ã«ãå ¬éããã¦ãããã¨ãã¾ãå®è¡ãã°ãæ®ããã¨ãã¡ãªããã ã¨èãã¦ãã¾ãã
ä»åã¯èªåçæããã½ã¼ã¹ã³ã¼ããèªåcommitãã¦ããããã§ããããããããªå 容ãcommitããã¦ãã¾ãå¯è½æ§ãã¼ãã§ã¯ããã¾ããããããªå ´åã§ããå¿ è¦ãã¡ã¤ã«ã¨ãã°ãå ¬éããã¦ããã°ã赤ã®ä»äººã§ãã£ã¦ãåå ãã¤ãã¨ãã¦ä¿®æ£ãã¦Pull Requestãéããã¨ãå¯è½ã§ãã
ãããªéçããã¸ã§ã¯ãã§èª°ãPull Requestéããªãã§ãããã¨ããããã³ããããã¨ã¯æãã¾ãããå¯è½æ§ã£ã¦å¤§äºã ã¨æããã§ãããã
ã¾ã¨ã
- Travis CIã®cron jobsã使ãã¨å®æå®è¡ã¸ã§ããã½ã¼ã¹ã³ã¼ãã¤ãã»ãã°ã¤ãã§å
¬éã§ãã
- ã¤ã³ã¿ã¼ãããä¸ã§æ´æ°ããç¶ãã¦ããä½ããå¤æãã¦git commitãããããªç¨éã«ã¯é常ã«è¯ãã®ã§ã¯ï¼ãã¨ãã°æ¥æ¬ã®ç¥æ¥ã«ã¬ã³ãã¼ã©ã¤ãã©ãªãªã©ã