GitHub Actions ã®æ°ãã¼ã¸ã§ã³ã 8/8 ã«çºè¡¨ããã¾ããã
èªåã¯éå»ã«ãæ§ãã¼ã¸ã§ã³æã« GitHub Actions ã®å ¥éè¨äºãæ¸ãã¦ããã®ã§ãããæ°ãã¼ã¸ã§ã³ãããã¾ã§ã¨å¤§ããå¤ãã£ã¦ãã¾ã£ã¦ããã®ã§ããã®è¨äºã§ã¯ãããã㦠GitHub Actions ã«ã¤ãã¦ãããã調ã¹ããåããã¦ã¿ããããå 容ãã¾ã¨ãã¾ãã
ç®æ¬¡
- 注æäºé
- GitHub Actions ã¨ã¯
- ããã¾ã§ã® GitHub Actions ã¨ã©ããå¤ãã£ãã
- GitHub Actions 㨠Azure Pipelines
- ç°¡åãªä¾ (Hello, World)
- ã¯ã¼ã¯ããã¼ã®è¨å®
- ã¯ã¼ã¯ããã¼ã¨ã¯
- ã¯ã¼ã¯ããã¼ãå®è¡ããã¤ãã³ã
- ã¯ã¼ã¯ããã¼ã®å®è¡ããã©ã³ããã¿ã°ãå¤æ´ããããã¡ã¤ã«ã®ãã¹ã§ãã£ã«ã¿ãã
- needs ã使ã£ãããã¼å¶å¾¡
- ä»®æ³ç°å¢ã®é¸æã¨ã³ã³ããå ãã«ã
- context 㨠expression 㨠if ã«ããã¹ãããã®æ¡ä»¶å®è¡
- ç°å¢å¤æ°ã¨ç§å¯æ å ±
- ã¢ã¯ã·ã§ã³
- ãããªã¯ã¹ãã«ã
- 権é
- éç¥
- å¶éäºé
- ã¾ã¨ã
注æäºé
GitHub Actions ã¯ãã®è¨äºã®å·çæç¹ï¼2019/08/19ï¼ã§ã¯ã¾ã ãã¼ã¿ã§ãã11/13 ã® GitHub Universe ã®ã¿ã¤ãã³ã°ã§ GA ã«ãªãäºå®ã¨ã®å ¬å¼çºè¡¨ãããã®ã§ä»å¾å¤§ããã¯å¤ãããªãã¨æãã¾ãããã¾ã ãªã«ãããå¤æ´ã«ãªãå¯è½æ§ã¯ããã¾ãã
ãã¼ã¿ã¸ã®ç³ããã¿ã¯ãGitHub Actions ã®ãã¼ã¸ããå¯è½ã§ããèªåã¯å ã GitHub Actions ã®ãã¼ã¿ã«åå ãã¦ãã¾ããããæ°ãã¼ã¸ã§ã³ã®çºè¡¨ããæ°æ¥ãã¦ããããããã¦ãã¼ã¿å©ç¨å¯è½ã«ãªã£ãã¨ããã¡ã¼ã«ããã¦ããã®ã¿ã¤ãã³ã°ããæ°ãã¼ã¸ã§ã³ã®æ©è½ã使ããããã«ãªãã¾ããã
GitHub Actions ã¨ã¯
GitHub Actions ã¨ã¯ãGitHub ã®ãªãã¸ããªã§ã¤ãã³ããçºçããã¨ãã«ã¯ã¼ã¯ããã¼ãå®è¡ã§ããä»çµã¿ã§ããã¯ã¼ã¯ããã¼ã¯è¤æ°ã®ã¢ã¯ã·ã§ã³ã¨å¼ã°ããã¿ã¹ã¯ããæ§æããã¾ãã
ä¾ãã°ããªãã¸ããªã« push ãããã¨ãã«èªåãã¹ããå®è¡ããããæ°ãã PR ã issue ãä½æãããã¨ãã« slack ã«éç¥ãé£ã°ãããã¨ãã£ããã¨ãã§ãã¾ãã
ã¢ã¯ã·ã§ã³ã¯ GitHub ãªãã¸ããªã Docker Hub ãªã©ã§å ¬éã§ããã®ã§ãä¸çä¸ã§å ±æãããã¨ãã§ãã¾ãã
ããã¾ã§ã® GitHub Actions ã¨ã©ããå¤ãã£ãã
GitHub Actions ã¯ããã¾ã§ããã¼ã¿ã¨ãã¦å©ç¨å¯è½ã§ããããæ°ãã¼ã¸ã§ã³ã«ãªã£ã¦å¤§ããå¤æ´ã«ãªãã¾ããããªã®ã§ãæ§ãã¼ã¸ã§ã³ã® GitHub Actions ã«ã¤ãã¦ã®æ å ±ã¯åºæ¬çã«ããåèã«ãªããªãã¨èãã¦ããã£ã¦ããã§ãã
ã³ã³ã»ãã
ã¾ããã³ã³ã»ããé¢ã¨ãã¦ã¯ãCI/CD ãåé¢ã«æ¼ãåºãã¦ãã¦ãã¾ããããã¾ã§ã CI/CD ã¨ãã¦ã®å©ç¨ã¯ãã¡ããå¯è½ã ã£ãã®ã§ãããå ¬å¼ã¨ãã¦ã¯ã¯ã¼ã¯ããã¼ã¨ããè¨èã使ããã¨ãå¤ãããã¾ã CI/CD ãã¼ã«ã¨ãã¦ã¯ã¢ãã¼ã«ãã¦ããªãã¨ããå°è±¡ã§ãããããããæ°ãã¼ã¸ã§ã³ã§ã¯æ確㫠CI/CD ç¨éã¨ãã¦ä½¿ã£ã¦ããããã¨ãç®çã¨ãã¦ããããã§ãã
ãã«ããã©ãããã©ã¼ã 対å¿
ããã¾ã§ã¯ Linux ã®ã¿ã§ããããWindows 㨠macOS ãå©ç¨ã§ããããã«ãªãã¾ããããããªã¯ã¹ãã«ããå¯è½ãªã®ã§ãå OS ä¸ã§åæã«ãã¹ããå®è¡ãããã¨ãã§ããããã«ãªãã¾ããã
HCL ãã YAML ã¸
ã¯ã¼ã¯ããã¼ã®è¨è¿°æ¹æ³ã大ããå¤ããã¾ãããããã¾ã§ã¯ HCL ã¨ãã HashiCorp 社製ã®è¨å®è¨èªã§è¨è¿°ãã¦ããã®ã§ãããæ°ãã¼ã¸ã§ã³ã§ã¯ YAML ã§è¨è¿°ããããã«ãªã£ã¦ãã¾ããå ¬å¼ããã¥ã¡ã³ãã«ã
Support for the HCL syntax in GitHub Actions will be deprecated on September 30, 2019.
ã¨ããã®ã§ãGitHub Actions ã® HCL è¨æ³ç㯠9/30 ã§å°ãªãã¨ãéæ¨å¥¨ã¨ãªãããã§ãããã®ã¿ã¤ãã³ã°ã§å®å ¨ã«å©ç¨ã§ããªããªãã®ãã¯ãããããã¾ããããHCL ã YAML ã«å¤æãããã¤ã°ã¬ã¼ã·ã§ã³ãã¼ã«ãå ¬éããã¦ããã移è¡æé ãå ¬å¼ããã¥ã¡ã³ãã«æ¸ããã¦ããã®ã§ãæ§ãã¼ã¸ã§ã³ã¦ã¼ã¶ã¼ã¯æ°ãã¼ã¸ã§ã³ã®ãã¼ã¿ãæå¹ã«ãªã次第ãæ©ãã«ç§»è¡ãã¾ãããã
https://github.com/actions/migrategithub.com
æé
æéã«ã¤ãã¦ãæ確ã«ããã¦ããããããªãã¯ãªãã¸ããªã¯å®å ¨ç¡æããã©ã¤ãã¼ããªãã¸ããªã¯å¾éå¶ã®èª²éä½ç³»ãçºè¡¨ããã¦ãã¾ããå ·ä½çãªéé¡ã¯å ¬å¼ãã¼ã¸ã®ä¸ã®æ¹ã«æ¸ããã¦ãã¾ãã
ãã®ä»
ããã¾ã§ã«æ¸ãã以å¤ã«ããGitHub Package Registry ã¨ã®é£æºããã°ã®æ¹åãªã©ãæ§ã ãªç¹ãå¤æ´ã«ãªã£ã¦ãã¾ããä¸æ¹ã§ãªããªã£ãæ©è½ãããããã¸ã¥ã¢ã«ã¨ãã£ã¿ã¨ããè¦å½ãããªããªã£ã¦ãã¾ãã
GitHub Actions 㨠Azure Pipelines
ä»åã®å¤§ããªå¤æ´ã«ã¯ãGitHub Actions ã®ããã¯ã¨ã³ãã Azure Pipelines ã® fork çã«ãªã£ãã¨ãããã¨ãèæ¯ã¨ãã¦ããã¾ããå ¬å¼ããã¥ã¡ã³ãã«ä»¥ä¸ã®ããã«æ¸ããã¦ãã¾ãã
The GitHub Actions virtual environments are hosted on virtual machines in Microsoft Azure with the GitHub Actions runner installed. The GitHub Actions runner is a fork of the Azure Pipelines Agent. ï¼è¨³: GitHub Actions ã®ä»®æ³ç°å¢ã¯ Microsoft Azure ä¸ã® VM ã« GitHub Actions runner ãã¤ã³ã¹ãã¼ã«ãã¦ãã¹ãããã¦ãã¾ããGitHub Actions runner 㯠Azure Pipelines Agent ã® fork ã§ããï¼
fork ãªã®ã§ Azure Pipelines ãã®ã¾ã¾ä½¿ããã¨ããããã§ã¯ãªããYAML ã®è¨è¿°ãªã©ã§ç°ãªãã¨ãããããããã§ãã
ç°¡åãªä¾ (Hello, World)
å®éã«ç°¡å㪠GitHub Actions ãä½æãã¦ã¿ã¾ãã
GitHub Actions ãæå¹ã«ãªã£ãã¦ã¼ã¶ã¼ã organization ä¸ã«é©å½ãªãªãã¸ããªãä½æãã以ä¸ã®ãã㪠.github/workflows/hello.yml
ãã¡ã¤ã«ãä½æãã¾ãã
name: Hello, World! on: push jobs: build: name: Greeting runs-on: ubuntu-latest steps: - run: echo "Hello, World!"
ãã®ãã¡ã¤ã«ã¯ã¯ã¼ã¯ããã¼ãå®ç¾©ãã¦ãã¾ãã
æåã® name
ã¯ã¯ã¼ã¯ããã¼ã®ååã§ãã次㮠on
ã§ãªãã¸ããªã¸ã® push
ã¤ãã³ãæã«ãã®ã¯ã¼ã¯ããã¼ã¯å®è¡ãããã¨å®ç¾©ãã¦ãã¾ãã
jobs
ãããã¯ã§ã¯ã¼ã¯ããã¼å
ã§å®è¡ãããã¸ã§ããå®ç¾©ãã¦ãã¾ããbuild
ã¨æ¸ãã¦ããã¨ããã¯ã¸ã§ãã® ID ã§ãjobs
ã®ãã¼ã¨ãã¦ã¦ãã¼ã¯ã§ããã°ä»ã®æååã§ã大ä¸å¤«ã§ããname
ã§ã¸ã§ãåãruns-on
ã§ãã®ã¸ã§ããå®è¡ãããä»®æ³ç°å¢ãæå®ãã¦ãã¾ãã
steps
ã§ã¸ã§ãå
ã§å®è¡ãããã¹ããããå®ç¾©ãã¦ãã¾ããä»åã¯ãrun
ã§ã·ã§ã«ã¹ã¯ãªãããå®è¡ããã ãã§ãã
ãã®ãã¡ã¤ã«ãä½æãã¦ãªãã¸ããªã« push ããã¨ãGitHub Actions ãå®è¡ããã¾ããGitHub ã®ãªãã¸ããªã®ãã¼ã¸ä¸ã§ Actions ã¿ããã¯ãªãã¯ããã¨è¦ããã¾ãã
Workflow runs
ã«è¡¨ç¤ºããã¦ããææ°ã®å®è¡ãã¯ãªãã¯ããã¨åã¹ãããã表示ãããRun ã¹ããããã¯ãªãã¯ããã¨æ¨æºåºåã« "Hello, World!" ã¨è¡¨ç¤ºããã¦ãããã¨ã確èªã§ãã¾ãã
以ä¸ã§ããªãã¸ããªã« push ããããã³ã« "Hello, World!" ã¨è¡¨ç¤ºããã ãã®ç°¡åãªã¯ã¼ã¯ããã¼ãä½æã§ãã¾ããã
ã¯ã¼ã¯ããã¼ã®è¨å®
ã¯ã¼ã¯ããã¼ã«ã¤ãã¦ãã詳細ã«è§£èª¬ãã¦ããã¾ãã
ã¯ã¼ã¯ããã¼ã¨ã¯
ã¯ã¼ã¯ããã¼ã®å®ç¾©ã¯ããªãã¸ããªã® .github/workflows
ãã£ã¬ã¯ããªä¸ã« YAML å½¢å¼ã®ãã¡ã¤ã«ã¨ãã¦ä¿åããã¾ãã
ã¯ã¼ã¯ããã¼ã¯è¤æ°ã®ã¸ã§ãããæ§æãããèªååãããããã»ã¹ã§ãã1 ã¤ã®ãªãã¸ããªã«å¯¾ãã¦è¤æ°ã®ã¯ã¼ã¯ããã¼ãä½æå¯è½ã§ãã
ã¸ã§ãã¯è¤æ°ã®ã¹ãããããæ§æããã¾ããã¹ãããã¯ã³ãã³ãã®å®è¡ãã¢ã¯ã·ã§ã³ã®ä½¿ç¨ãå¯è½ã§ããã¢ã¯ã·ã§ã³ã¯èªä½ãããã¨ãã§ãã¾ãããã³ãã¥ããã£ã§å ±æãããã¢ã¯ã·ã§ã³ãå©ç¨ãããã¨ãå¯è½ã§ãã
ã¯ã¼ã¯ããã¼ãå®è¡ããã¤ãã³ã
ã¯ã¼ã¯ããã¼ãå®è¡ãããæ¹æ³ã¯ã3 ã¤ããã¾ãã
1 ã¤ç®ã¯ãGitHub ã¤ãã³ãã§å®è¡ãããæ¹æ³ã§ããããã¯ç°¡åãªä¾ã¨åãããã« on: push
ã®ããã«è¨è¿°ãããã¨ã§æå®ãã GitHub ã¤ãã³ããçºçããã¨ãã«ã¯ã¼ã¯ããã¼ãå®è¡ã§ãã¾ããon: [push, pull_request]
ã®ããã«æ¸ããã¨ã§è¤æ°ã®ã¤ãã³ãã«å¯¾å¿ããããã¨ãã§ãã¾ããã¤ãã³ãã®ç¨®é¡ã«ã¤ãã¦ã¯å
¬å¼ããã¥ã¡ã³ããåç
§ãã¦ãã ããã
ã¡ãªã¿ã«ãfork å ã®ãªãã¸ããªãã PR ãä½æãããå ´åãpull_request ã¤ãã³ã㯠fork å ã®ãªãã¸ããªã§å®è¡ããã¾ããfork å 㧠CI çãªã¯ã¼ã¯ããã¼ãå®è¡ãããå ´åã¯ãpush ã¤ãã³ããè¨å®ããã»ããããããã§ãã
2 ã¤ç®ã¯ãcron å½¢å¼ã§è¨è¿°ãã¦å®æå®è¡ãããæ¹æ³ã§ããä¾ã¨ãã¦ã15 åãã¨ã«å®è¡ãããå ´å㯠on
ã«ä»¥ä¸ã®ããã«è¨è¿°ãã¾ãã
on: schedule: - cron: "*/15 * * * *"
*
㯠YAML ã§ç¹æ®æåãªã®ã§ãcron
ã®è¨è¿°ã¯ã¯ãªã¼ãããå¿
è¦ãããã¾ãã
3 ã¤ç®ã¯ãå¤é¨ããã¯ã¼ã¯ããã¼ãå®è¡ããããã®æ¹æ³ã§ããrepository_dispatch
ã¤ãã³ããå¼ãèµ·ããããã® REST API ã¨ã³ããã¤ã³ããç¨æããã¦ããã®ã§ãã¯ã¼ã¯ããã¼å´ã¯ on: repository_dispatch
ã®ããã«è¨è¿°ããå¤é¨ããã¨ã³ããã¤ã³ãã«ãªã¯ã¨ã¹ããæããã¨å®è¡ããã¾ããä¾ã¨ãã¦ãcurl
ãªã以ä¸ã®ããã«ã¨ã³ããã¤ã³ãã«ãªã¯ã¨ã¹ããæãã¦ã¯ã¼ã¯ããã¼ãå®è¡ã§ãã¾ãã
curl -X POST -H "Authorization: token PERSONAL_ACCESS_TOKEN" -H "Accept: application/vnd.github.everest-preview+json" --data '{"event_type": "test-hello"}' https://api.github.com/repos/:owner/:repo/dispatches
Authorization
ãããã¼ã«ä¹ãããã¼ã½ãã«ã¢ã¯ã»ã¹ãã¼ã¯ã³ã«ã¯ repo
権éãå¿
è¦ãªããã§ããPOST ãããã¼ã¿ã® event_type
ã¯å¿
é ã§ãããä»»æã®å¤ã§å¤§ä¸å¤«ã§ããAccept: application/vnd.github.everest-preview+json
ãããã¼ã¯ãã®æ©è½ãç¾æç¹ã§ãã¬ãã¥ã¼ãªã®ã§å¿
è¦ã«ãªã£ã¦ãã¾ãã
ã¯ã¼ã¯ããã¼ã®å®è¡ããã©ã³ããã¿ã°ãå¤æ´ããããã¡ã¤ã«ã®ãã¹ã§ãã£ã«ã¿ãã
CI/CD ã§ããããã®ããmaster
ãã©ã³ããå¤æ´ãããã¨ããç¹å®ã®å½åè¦åã®ã¿ã°ãä½æãããã¨ãã ãå®è¡ããããç¹å®ã®ãã£ã¬ã¯ããªä»¥ä¸ã«å¤æ´ãããã¨ãã ãå®è¡ããããã¨ãã£ãã¯ã¼ã¯ããã¼å®è¡ã®ãã£ã«ã¿ãªã³ã°ã§ãã
GitHub Actions ã§ã on
ã®è¨å®ã§ãããã£ããã¨ãå¯è½ã§ããããã©ã«ã㧠push
ã¤ãã³ãã®ã¿ãæå®ããã¨ãã¯ãã¹ã¦ã®ãã©ã³ãããã¹ã¦ã®ã¿ã°ã¸ã® push
ã¤ãã³ãã«å¯¾ãã¦å®è¡ããã¦ãã¾ãã¾ãããä¾ãã°ãmaster
ãã©ã³ãã« push ãããã¨ãã®ã¿å®è¡ãããã¨ãã¯ä»¥ä¸ã®ããã«è¨è¿°ãã¾ãã
on: push: branches: - master tags: - "!*"
v
ã§å§ã¾ãã¿ã°ãä½æãããã¨ãã®ã¿å®è¡ãããã¨ãã¯ä»¥ä¸ã®ããã«è¨è¿°ãã¾ãã1
on: push: branches: - "!*" tags: - "v*"
tests
ãã£ã¬ã¯ããªç´ä¸ã®ãã¡ã¤ã«ãå¤æ´ãããã¨ãã®ã¿å®è¡ãããã¨ãã¯ä»¥ä¸ã®ããã«è¨è¿°ãã¾ãã
on: push: paths: - "tests/**"
branches
, tags
, paths
ã®ææ³ã¯ã.gitignore ã¨åãã¨å
¬å¼ããã¥ã¡ã³ãã«ã¯æ¸ããã¦ãã¾ãã2
ææã¨ãã¦ã¯ããªã«ãæå®ããªãã¨ã¿ã°ã§ãåãã¦ãã¾ãã®ãã¡ãã£ã¨ç½ ã§ãããã¿ã°ãé¤å¤ããæå®ãå¿ããã¨ãmaster
ãã©ã³ãã®ã¿ã«ããã¤ããã§ãæ°ã¥ãããã¿ã°ã§ãåãã¦ã¦ãã©ãã«çºçã¨ãã¯ããããã§ãã
needs ã使ã£ãããã¼å¶å¾¡
ãªã«ãæå®ããªãã¨ã¯ã¼ã¯ããã¼å
ã®ãã¹ã¦ã®ã¸ã§ãã¯ä¸¦åå®è¡ããã¾ãããneeds
ãæå®ãããã¨ã«ããã¸ã§ãã®å®è¡é åºãå¶å¾¡ãããã¨ãã§ãã¾ãã
name: Flow Control on: push jobs: job1: name: Greeting 1 runs-on: ubuntu-latest steps: - run: echo "Hello, World 1" job2: name: Greeting 2 needs: job1 runs-on: ubuntu-latest steps: - run: echo "Hello, World 2" job3: name: Greeting 3 needs: job1 runs-on: ubuntu-latest steps: - run: echo "Hello, World 3" job4: name: Greeting 4 needs: [job2, job3] runs-on: ubuntu-latest steps: - run: echo "Hello, World 4"
ä¸è¨ã®ä¾ã ã¨ãjob1
ãå®äºããå¾ã« job2
, job3
ã並åå®è¡ããã両æ¹ã®ã¸ã§ããå®äºãã㨠job4
ãå®è¡ããã¾ãã
ãã®ããããç¾æç¹ã ã¨ã¸ã§ãã®ä¾åé¢ä¿ãè¦è¦çã«å¯è¦åããã¦ããªãã®ã§ããããããã¤ãã©ã¤ã³ã®ã°ã©ãçãªã®ã表示ãããããã«ãªã£ã¦ã»ããã§ãã
ä»®æ³ç°å¢ã®é¸æã¨ã³ã³ããå ãã«ã
ã¸ã§ããã¨ã« runs-on
ã¯å¿
é ã§ãã¸ã§ããå®è¡ãããä»®æ³ç°å¢ãé¸æããå¿
è¦ãããã¾ããæå®ã§ããç°å¢ã¯å
¬å¼ããã¥ã¡ã³ããåç
§ãã¦ãã ããã
ä»®æ³ç°å¢ã«å ¥ã£ã¦ãã½ããã¦ã§ã¢ãå ¬å¼ããã¥ã¡ã³ãã§å ¬éããã¦ãã¾ããä¸éãã®éçºç°å¢ã¯å ¨é¨å ¥ãã¨ããæãã§ããã
ä¸ã¤ã®ã¸ã§ãã®ãã¹ã¦ã®ã¹ãããã¯åãä»®æ³ç°å¢ã¤ã³ã¹ã¿ã³ã¹ä¸ã§å®è¡ããã¾ããåãã¸ã§ãå ã§ããã°ãã¡ã¤ã«ã·ã¹ãã ãéãã¦ãã¼ã¿ã®ããåããå¯è½ã¨ãããã¨ã§ãã
é常ã ã¨ä»®æ³ç°å¢ãç´æ¥ä½¿ã£ã¦ãã¹ã¦ã®ã¹ããããå®è¡ããã¾ãããcontainer
ãæå®ãããã¨ã§ã³ã³ããå
ãã«ããå¯è½ã§ãã
name: Hello, World! on: push jobs: build: name: Greeting runs-on: ubuntu-latest container: image: node steps: - run: node -e 'console.log("Hello, World!");'
ä¸ã®ä¾ã ã¨ãnode
ã¤ã¡ã¼ã¸ã使ã£ã¦ãã®ã¸ã§ãã®ã¹ãããããã¹ã¦å®è¡ããã¾ããï¼å¾è¿°ããã³ã³ããå
ã§å®è¡ãããã¢ã¯ã·ã§ã³ã«ã¤ãã¦ã¯ãã®éãã§ã¯ããã¾ããï¼
context 㨠expression 㨠if ã«ããã¹ãããã®æ¡ä»¶å®è¡
ã¯ã¼ã¯ããã¼ã¯èªèº«ã®å®è¡ææ å ±ã context ã¨ãã¦æã£ã¦ãã¾ããã©ãããæ å ±ãæã£ã¦ãããã¯ãå ¬å¼ããã¥ã¡ã³ãããåç §ãã ããã
ã¯ã¼ã¯ããã¼ã® YAML ãã¡ã¤ã«ãããã® context æ å ±ã«ã¢ã¯ã»ã¹ããããã«ãexpression ã使ç¨ãã¾ããexpression 㯠context ã«ã¢ã¯ã»ã¹ããã ãã§ãªããæ¼ç®å¼ãé¢æ°ãå¼ã³åºããã¨ãã§ãã¾ãã
${{ <expression> }}
ã®ããã«ã¯ã¼ã¯ããã¼ãã¡ã¤ã«ã«æ¸ããã¨ã§å®è¡æã«è©ä¾¡ãã¦ããã¾ããä¾ã¨ãã¦ã以ä¸ã®ããã«è¨è¿°ãããã¨ã§ GitHub ã®ã³ã³ããã¹ãæ
å ±ãåºåãããã¨ãã§ãã¾ããgithub
ãçµã¿è¾¼ã¿ã® GitHub ã®ã³ã³ããã¹ãæ
å ±ã表ãå¤æ°ã§ãtoJson
ãåãåã£ãå¤ã JSON å½¢å¼ã®æååã«ãã¦è¿ãçµã¿è¾¼ã¿é¢æ°ã§ãã
name: GitHub Context on: push jobs: github-context: name: GitHub Context runs-on: ubuntu-latest steps: - name: Dump GitHub Context env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "${GITHUB_CONTEXT}"
ã¯ã¼ã¯ããã¼ãããªã¬ã¼ãã GitHub ã®ã¤ãã³ãæ å ±ã¨ããå«ã¾ãã¦ããã®ã§ãã¸ã§ãã®æåã«ã¨ããããåºåãã¦ããã¨ãããã°æã«å½¹ã«ç«ã¡ããã§ãã
ããã«ãif
ã¨ãã® expression ãçµã¿åããããã¨ã§ãã¹ããããç¹å®ã®æ¡ä»¶ãæºããã¨ãã ãå®è¡ãããããã«è¨å®ã§ãã¾ããä¾ãã°ãpull_request
ã¤ãã³ã㧠action
ã opened
ãªã¨ãã ãå®è¡ãããããã«ãããã¨ãã¯ä»¥ä¸ã®ããã«è¨å®ãã¾ãã3
name: If on: pull_request jobs: if-pull-request-is-opened: name: If runs-on: ubuntu-latest steps: - name: echo if pull request is opened if: github.event_name == 'pull_request' && github.event.action == 'opened' run: echo "pull request is opened"
if
ã®è¨å®ã§ã¯ã${{ <expression> }}
ã®ããã«è¨è¿°ããã®ã§ã¯ãªããç´æ¥ expression ãæ¸ããããã«ãªã£ã¦ãã¾ããã¾ããalways
ã failure
ã®ãããªçµã¿è¾¼ã¿ã®æ¡ä»¶å¼ãããã®ã§ãå
¬å¼ããã¥ã¡ã³ãããåç
§ãã ããã
ç°å¢å¤æ°ã¨ç§å¯æ å ±
GitHub Actions ã¯å®è¡æã«ããã©ã«ãã§ç°å¢å¤æ°ãè¨å®ããã¾ããå ¬å¼ããã¥ã¡ã³ãããåç §ãã ããã
ããã«ãã¯ã¼ã¯ããã¼ã®è¨å®ãã¡ã¤ã«ã§ã env
ã§ç°å¢å¤æ°ãè¨å®ã§ãã¾ãã
name: env hello on: push jobs: build: name: Greeting runs-on: ubuntu-latest steps: - env: NAME: Mona run: echo "Hello, ${NAME}"
ä¸ã®ä¾ã§ã¯ãNAME
ç°å¢å¤æ°ã«å¤ãè¨å®ã㦠run
ã®ä¸ã§ä½¿ç¨ãã¦ãã¾ããã¡ãªã¿ã«ãGITHUB_
ã§å§ã¾ãç°å¢å¤æ°ã¯ GitHub å´ã®äºç´èªã¨ãã¦ä½¿ããªãããã«ãªã£ã¦ããããã§ãã
ç§å¯æ
å ±ã«ã¤ãã¦ã¯ããªãã¸ããªã® Settings
â Secrets
ããè¨å®ãã¾ãã
ããã¨ã以ä¸ã®ããã« expression 㧠secrets
ã³ã³ããã¹ãããå©ç¨ã§ããããã«ãªãã¾ãã
name: secret hello on: push jobs: build: name: Greeting runs-on: ubuntu-latest steps: - run: echo "Hello, ${{ secrets.SECRET_VALUE }}"
ã¡ãªã¿ã«ããã°ä¸ã§ã¯ç§å¯æ å ±ã¯ãã¹ã¯ãããããã§ãã
ããã«ãçµã¿è¾¼ã¿ã§ GITHUB_TOKEN
ã¨ããç§å¯æ
å ±ãåå¨ãã¾ããã¸ã§ãå
㧠GitHub API ãå©ãããããã¨ãã«ä½¿ãã¾ãããã¼ã¯ã³ãæã£ã¦ããã¼ããã·ã§ã³ã¯å
¬å¼ããã¥ã¡ã³ãããåç
§ãã ããã
ã¡ãªã¿ã«ãfork ããããªãã¸ããªããããªã¬ã¼ãããã¯ã¼ã¯ããã¼ã§ã¯ GITHUB_TOKEN
以å¤ã®ç§å¯æ
å ±ã¯æ¸¡ããã¾ãããGITHUB_TOKEN
ã¯æ¸¡ããã¯ãã¾ãããwrite
権éãå¥å¥ªãã read
権éã®ã¿ã«ãªãã¾ãã
ã¢ã¯ã·ã§ã³
ããããå¦çã¯ãã¢ã¯ã·ã§ã³ã¨ããåä½ã§å
¬éãå
±æãå¯è½ã§ãsteps
ã®ä¸ã§å¼ã³åºããã¨ãå¯è½ã§ãã
ä¾ã¨ãã¦ããªãã¸ããªããã§ãã¯ã¢ã¦ããã actions/checkout ã¢ã¯ã·ã§ã³ã使ç¨ãã¦ã¿ã¾ãã
name: Checkout on: push jobs: build: name: Greeting runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - run: cat README.md
uses: actions/checkout@v1
ã§ã¢ã¯ã·ã§ã³ãå®è¡ããããªãã¸ããªããã§ãã¯ã¢ã¦ãããã¾ãã@
㧠git ã® SHA ããã©ã³ãããªãªã¼ã¹ãªã©ãæå®ãã¦ç¹å®ã®ãã¼ã¸ã§ã³ã®ã¢ã¯ã·ã§ã³ãå©ç¨ãããã¨ãã§ãã¾ãã
以ä¸ã®ããã« with
ã§ã¢ã¯ã·ã§ã³ã«ãã©ã¡ã¼ã¿ã渡ããã¨ãå¯è½ã§ãã
name: Checkout on: push jobs: build: name: Greeting runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 with: fetch-depth: 1 - run: cat README.md
actions/checkout
㯠fetch-depth: 1
ãæå®ãããã¨ã§ããããã shallow clone ç¸å½ã®æåã«ãªãããã§ãã
actions/checkout
ã®ãã㪠GitHub 社製ã®ã¢ã¯ã·ã§ã³ã¯ actions org ã§å
¬éããã¦ãã¾ãã
ã¢ã¯ã·ã§ã³ã¯ 2 種é¡ã®æ¹æ³ã§ä½æãããã¨ãã§ãã¾ãã1 ã¤ç®ã¯ Docker ã³ã³ããã§ããã®ç¨®é¡ã®ã¢ã¯ã·ã§ã³ã¯ Linux ã®ä»®æ³ç°å¢ã®ã¿ã§å©ç¨å¯è½ã§ãããã 1 ã¤ã¯ JavaScript ã§ããã¡ãã¯ãã¹ã¦ã®ä»®æ³ç°å¢ã§å©ç¨å¯è½ã§ããå ·ä½çãªä½ææ¹æ³ã«ã¤ãã¦ã¯ããã®è¨äºã§ã¯çãã¾ãã
ãããªã¯ã¹ãã«ã
strategy
ã使ããã¨ã§è¤æ°ã® OS ãè¨èªãã¼ã¸ã§ã³ã®çµã¿åããã§åãã¸ã§ããå®è¡ããããããããããªã¯ã¹ãã«ãçãªãã¨ãå¯è½ã«ãªãã¾ãã以ä¸ã¯ãactions/setup-node ã¢ã¯ã·ã§ã³ãå©ç¨ãããè¤æ° OSãè¤æ° Node ãã¼ã¸ã§ã³ã§ã®ãããªã¯ã¹ãã«ãã®ä¾ã§ãã
name: Node.js Matrix Build on: push jobs: build: name: Node.js ${{ matrix.os }} ${{ matrix.node }} runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, windows-latest] node: [6, 8, 10] steps: - name: Set Node.js uses: actions/setup-node@v1 with: node-version: ${{ matrix.node }} - run: node -v
actions/setup-node
ã¯ãä»®æ³ç°å¢ä¸ã® node ç°å¢ãæå®ãããã¼ã¸ã§ã³ã«ãã¦ããã¾ãããã®ä¾ã§ã¯ node -v
ãå©ãã¦ãã ãã§ãããå®éã® CI ã§ã¯ npm install
ã npm test
ã¨ãã£ããã¨ãè¡ã£ã¦ããæ³å®ã§ãã
権é
ã¯ã¼ã¯ããã¼ã®ä½æãç·¨éãActions ã¿ãã®é²è¦§ã«ã¯ãªãã¸ããªã® write
ã admin
ã®æ¨©éãå¿
è¦ãªããã§ãã
2019/08/22 追è¨: âåã§ãããActions ã¿ãã®é²è¦§ã¯ read
権éããã°ã§ããããã§ãã
éç¥
GitHub ã® Settings
â Notifications
ãã GitHub Actions ã®éç¥ã«ã¤ãã¦ã®è¨å®ãããã¾ãã
ã¡ã¼ã«éç¥ã¨ Web Notifications ã«ããéç¥ãããã失æããã¨ãã ãéãããã«ãããã®è¨å®ãããã¾ãã
å¶éäºé
GitHub Actions ã®å©ç¨ã«ã¤ãã¦ã¯ä»¥ä¸ã®å¶éãããã¾ãã
- ãªãã¸ããªãã¨ã«æ大㧠20 ã¯ã¼ã¯ããã¼ã¾ã§åæå®è¡ã§ãã
- ãªãã¸ããªå ã®ãã¹ã¦ã®ã¢ã¯ã·ã§ã³å ¨ä½ã§ 1 æéã«ã¤ã 1,000 API ãªã¯ã¨ã¹ãã¾ã§å®è¡ã§ãã
- ã¯ã¼ã¯ããã¼å ã®ãã¹ã¦ã®ã¸ã§ãã®æ大å®è¡æé㯠6 æéã¾ã§
- ãªãã¸ããªãã¨ã«ãã¹ã¦ã®ã¯ã¼ã¯ããã¼å ¨ä½ã§ 20 ã¸ã§ãã¾ã§åæå®è¡ã§ãã
ãã¨ã¯ãå½ããåã§ããæå·é貨æ¡æã®ãããªæ¬æ¥ä½¿ãããã¹ãã§ãªãç®çã§ã®å©ç¨ãæ確ã«ç¦æ¢ããã¦ãã¾ããæ°ã«ãªã人ã¯å ¬å¼ããã¥ã¡ã³ããèªã¿ã¾ãããã
ã¾ã¨ã
GitHub Actions ã«ã¤ãã¦ãæ§ãã¼ã¸ã§ã³ã¨ã®éããã¯ã¼ã¯ããã¼ã®è¨å®ã§ã©ã®ãããªãã¨ãè¨å®ã§ãããã¨ãã£ããã¨ãä¸å¿ã«æ¸ãã¾ãããå®è·µçãªã¯ã¼ã¯ããã¼ã¨ããã¢ã¯ã·ã§ã³ã®ä½æï¼å ±ææ¹æ³ã¨ãã«ã¤ãã¦ã¯ã¾ã¨ããããªãã£ãã®ã§ãã¾ãå¥ã®è¨äºã§ããã¾ããï¼æéãããã°â¦ï¼
åºæ¬çã«ã¯å ¬å¼ããã¥ã¡ã³ãã®æ å ±ãã¾ã¨ããã ãã®è¨äºãªã®ã§ãææ°æ å ±ã確èªããã¨ãã¯ãã¡ããè¦ã¦ãã ããã
å人çãªææã¨ãã¾ãã¦ã¯ããã¯ããããªãã¯ãªãã¸ããªå®å ¨ç¡æ㧠20 並åã使ããã®ã¯ã¨ã¦ãå¼·ãã§ãããWindows ã macOS 対å¿ãå¼·ãã§ãããã¡ãã£ã¨ãã OSS ã®ãã«ãã®é¸æè¢ã¨ãã¦ã¯ããªãæåã ã¨æãã¾ãã
ä¸æ¹ã§ãç¾ç¶æ°ã«ãªã£ã¦ãç¹ã¨ãã¦ã¯ä»¥ä¸ã®é¨åãããã¾ãã
- CPU ãã¡ã¢ãªã¨ãã£ããªã½ã¼ã¹ãå¼·åã§ããã®ã
- ãã£ãã·ã¥
- ã¸ã§ãéã®ææç©ã®åã渡ã
- upload-artifact ã¨ããããã£ã½ãã¢ã¯ã·ã§ã³ã¯ãããã©ãå ¬å¼ããã¥ã¡ã³ãä¸ã§ã¯è¦å½ãããªã
ããã«ããã¯ãã¾ã ãã¼ã¿ã ãããæåãæªããã¨ãããã¡ããã¡ããããã¾ããæ¬æ ¼çãªéç¨ã¯ GA ã¾ã§å¾ ã£ã¦ãããããã§ãã
ã¾ããæ§ãã¼ã¸ã§ã³ã¨ã¯ã ãã¶å¥ç©ã«ãªã£ã¦ãã¾ã£ã¦ãã®ã§ãGitHub Actions ã¨ããååã¯ãã®æ©ä¼ã«å¤ãã¦ãã¾ã£ã¦ãããã£ãã®ã§ã¯ã¨æãã¾ããä»å¾ GitHub Actions ã«ã¤ãã¦æ¤ç´¢ããã¨ãã«ãæ§ãã¼ã¸ã§ã³ã«ã¤ãã¦ã®è¨äºãéªéããããã§ãã
å ¨ä½ã¨ãã¦ã¯ CI/CD æ¥çãçãä¸ãããã¨èªä½ã¯ã¨ã¦ãããããããã¾ãæ°ã㪠CI æ¢æ±æ²¼ãå¢ãããªã¨ããæ°æã¡ãªã®ã§ãå¼ãç¶ããããã試ãã¦ããããã§ãã
追è¨
ã¢ã¯ã·ã§ã³ã®ä½ææ¹æ³ãç¶ç·¨ã¨ãã¦æ¸ãã¾ããã
2020/02/27 追è¨
ãGitHub Actions å®è·µå ¥éãã®é»åæ¸ç±çã BOOTH ã§è²©å£²éå§ãã¾ããããã詳細㪠GitHub Actions ã®è§£èª¬ãææ°æ å ±ãæ¸ããã¦ãã¾ãã
-
2019/08/22 追è¨: ãã¡ãã®æ¸ãè¾¼ã¿ãè¦ã¦ç¢ºèªããã¨ããã
branches
ã«refs/tags/*
ãæå®ããã¨ã¿ã°ã¸ã® push ã ããã«ãã§ããããã«ãªãã¾ããï¼æ£ç´ãã®ãããã®æåã¯ã¾ã å¤ãããããªæ°ããã¾ãããï¼↩ -
tests/**
ãæå®ããã°tests
ãã£ã¬ã¯ããªç´ä¸ã ãã§ãªããµããã£ã¬ã¯ããªå ¨ä½ã対象ã«ã§ããã¯ãã§ãããæå ã§è©¦ããã¨ãã¯ãããªããããã£ã¬ã¯ããªç´ä¸ã®ãã¡ã¤ã«ãå¤æ´ããã¨ãã®ã¿ã¯ã¼ã¯ããã¼ãéå§ããã¾ããããã®ãããã¯ãµãã¼ãã«åãåããä¸ã§ãã↩ -
ç¾ç¶ãªãã
pull_request
ã¤ãã³ããçºçããã®ãopened
ã ãã«ãªã£ã¦ãã¾ã£ã¦ãã®ã§æå³ããªãè¨å®ã«ãªã£ã¦ãã¾ã£ã¦ã¾ãããµãã¼ãã«åãåããä¸ã§ãã↩