ããã«ã¡ã¯ããããã¯ããã°ãã¯ã
ã ããããµã¼ããµã¤ãã®ã¨ã³ã¸ãã¢ã®(@taclose)ã§ãâ
GitHub Copilotãæ´»èºãã¦ããæ¨ä»ãå¼ç¤¾ã§ã¯GitHubã§æ´ã«éçºå¹çãè¯ããã¦ãããã¨ããæµãã§æ¥ã
èªååãè¡ããã¦ããã¾ãã
ä»åã¯ãããªæ代ã ããããæ±ãããã¦ããGitHub Actionsã«ã¤ãã¦ãåå¿è
åãã«ã¯ã¼ã¯ããã¼ä½æã®éã«ç¥ã£ã¦ããããã³ãã¨æè¨ã«ã¤ãã¦ç´¹ä»ãã¾ãã
GitHub Actionsã®ã¯ã¼ã¯ããã¼ãèªãããã©ãã¾ã èªä¿¡ããªãã¨ããæ¹ã¯ãã²åèã«ãã¦ãã ããï¼
ããããã£ã¨æ©ãç¥ã£ã¦ããããã£ãï¼ããåå¿è
ãã¤ã¾ã¥ããã¡ãªãã¤ã³ãï¼ãã解説ãã¾ãï¼
- èªè ã¿ã¼ã²ãã
- ã¯ã¼ã¯ããã¼ä½æã®ã³ã
- ã¾ã¨ã
- åèè¨äºã»ãå§ããµã¤ã
èªè ã¿ã¼ã²ãã
GitHubã¢ã¯ã·ã§ã³ãªãã¨ãªãæ¸ãã¦ããã©ãæé©ãªæ¸ãæ¹ãåºæ¥ã¦ãããèªä¿¡ããªãæ¹ã¨ãï¼
ã¯ã¼ã¯ããã¼ä½æã®ã³ã
1. run
ã»ã¯ã·ã§ã³ã§å¼ ${{}}
ã¯æ¥µå使ããªã
ä¾ï¼
jobs: example-job: runs-on: ubuntu-latest steps: - run: echo "Hello, ${{ github.event.inputs.name }}!"
ãã®ããã«ãrun
ã»ã¯ã·ã§ã³ã§ ${{ }}
å¼ã使ãããã®ã¯ããè¦ããã¾ãããå®ã¯é¿ããã¹ãã§ãï¼
çç±ã¯ä¸»ã«2ã¤ããã¾ãã
å±éºãã®1ï¼ã³ã¼ãã¤ã³ã¸ã§ã¯ã·ã§ã³ã®ãªã¹ã¯
${{ github.event.inputs.name }}
ãªã©ãç´æ¥ run
ã«æ¸¡ãã¨ããããã®å¤ãæªæã®ãããã®ã§ãã£ãå ´åãæå³ããªãã³ãã³ããå®è¡ãããå±éºãããã¾ãã
ä¾ãã°ãããã·ã¼ã¯ã¬ããã®ä¸ã« rm -rf /
ãªãã¦ãã£ããâ¦ã!!
å±éºãã®2ï¼ãã¼ã¿ã®ãµãã¿ã¤ãºä¸è¶³
ãã¼ã¿ããµãã¿ã¤ãºï¼ç¡å®³åï¼ããã«æ¸¡ããã¨ã§ãç¹å®ã®è¨å·ãæååãäºæããªãåä½ãå¼ãèµ·ãããã¨ãããã¾ãã
GitHub Actionså
ã§å¼ã使ãå ´åã¯ãenv
å¤æ°ãä»ã®æ段ã使ã£ã¦ãã¼ã¿ã®å®å
¨æ§ã確ä¿ãã¾ãããã
è¯ãä¾ï¼
jobs: example-job: runs-on: ubuntu-latest steps: # "${NAME}" ãã®ããã«ã¯ã©ã¼ãã¼ã·ã§ã³ã§å²ãã§ããã®ããã½ï¼ä½ãä»£å ¥ããã¦ãããã¾ããï¼ - run: echo "Hello, ${NAME}!" env: NAME: ${{ github.event.inputs.name }}
ãã®ããã«ãå¼ãç´æ¥ run
ã«æ¸¡ãããç°å¢å¤æ° (env
) ã«æ¸¡ãã¦ãã使ãã¨ã"(ããã«ã¯ã©ã¼ãã¼ã·ã§ã³)
ãæ··ãã£ã¦ããããï¼ã¨ãã®èæ
®ãè¦ããå®å
¨ã§ãã
2. workflow_call
ã使ãéã®æ³¨æç¹
workflow_call
ã使ãã¨ãä»ã®ã¯ã¼ã¯ããã¼ãåå©ç¨ã§ãã¦ä¾¿å©ã§ãã
æã«ã¯ãªãã¸ããªãè·¨ãã§å
±éã®ã¯ã¼ã¯ããã¼ãªãã¦äºãããããã§ãããã
ããããããã¤ãæ°ãä»ããã¹ãç¹ãããã¾ãã
注æç¹ãã®1ï¼github
ã³ã³ããã¹ãã¯å¼ãç¶ããã
å¼ã³åºãå
ã®ã¯ã¼ã¯ããã¼ã§ä½¿ç¨ãã¦ãã github
ã³ã³ããã¹ãã¯ããã®ã¾ã¾å¼ã³åºãå
ã«ãå¼ãç¶ããã¾ãã
ä¾ãã°ãgithub.event
ã github.actor
ãªã©ã¯å¼ã³åºãå
ã®ãã®ãåæ ããããããä½ãç¹å®ã®ã¤ãã³ããã¦ã¼ã¶ã¼ã§åä½ããããå ´åã«ã¯æ³¨æãå¿
è¦ã§ãã
ä¾ï¼
on: workflow_call: inputs: name: required: true type: string jobs: example-job: runs-on: ubuntu-latest steps: # ããã§åºåãããevent_nameã¯å¼ã³åºãå ã«ãªãã¾ãï¼ - run: echo "Running as ${{ github.actor }} for event ${{ github.event_name }}"
注æç¹ãã®2ï¼secrets
ã®æ±ã
workflow_call
ã§ã¯ãsecrets
ãèªåã§æ¸¡ãããããã§ã¯ãªããå¼ã³åºãå´ã§æ示çã«æ¸¡ãå¿
è¦ãããã¾ãã
å¿ããã¡ãªãã¤ã³ããªã®ã§æ³¨æãã¾ãããï¼
ä¾ï¼
# workflow_callãå¼ã³åºãã¦ãå´ã®å®è£ jobs: call-reusable-workflow: uses: ./.github/workflows/reusable-workflow.yml secrets: # secretsã¯ãã®ããã«æ¸¡ãã¦ãããªãã¨åç §åºæ¥ã¾ããï¼ MY_SECRET: ${{ secrets.MY_SECRET }}
å¼ã³åºãå ã§ãã®ã·ã¼ã¯ã¬ãããé©åã«è¨å®ããªãã¨ãã¯ã¼ã¯ããã¼ããã¾ãåããªãå¯è½æ§ãããã®ã§ããã£ããã¨è¨å®ãã¦ãã ããã
3. GITHUB_TOKEN
ã§è¡ã£ãæä½ã¯å度ããªã¬ã¼ãããªã
ä½è¨ã£ã¦ããã ãï¼ã£ã¦æãããããã¾ããããã¯ã¼ã¯ããã¼ã§è²ã
èªååãã¦ããã¨æ¡å¤è©°ã¾ããã¤ã³ãã§ãï¼
GitHub Actionsã§ã¯ãããã©ã«ã㧠GITHUB_TOKEN
ãæä¾ããã¦ãããããã使ã£ã¦APIæä½ããªãã¸ããªã¸ã®å¤æ´ãè¡ããã¨ãã§ãã¾ãã
ããããããã§ä¸ã¤è¦ãã¦ããããä»æ§ãããã¾ãã
ããã¯ãGITHUB_TOKEN
ã§è¡ã£ãæä½ã¯å度ã¯ã¼ã¯ããã¼ãããªã¬ã¼ãããªãã¨ããç¹ã§ãã
ä¾ï¼
# GITHUB_TOKENã使ã£ã¦issueãæ稿ãã¦ãããµã³ãã«ã§ãã jobs: example-job: runs-on: ubuntu-latest steps: - name: Create a new issue run: | curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -d '{"title":"New Issue","body":"This issue is created by GitHub Actions!"}' \ https://api.github.com/repos/your-repo/issues
ãã®ããã« GITHUB_TOKEN
ã使ã£ã¦ä½ãissueãæ稿ããå ´åããã®æä½èªä½ãæ°ããã¯ã¼ã¯ããã¼ãèµ·åãããã¨ã¯ããã¾ããã
ã¤ã¾ãããissueãä½æããããéç¥ããã¯ã¼ã¯ããã¼ãã¨ããä½ã£ã¦ããã¨ãã¦ãéç¥ãé£ã°ãªãçµæã«ãªãã¾ãã
ãããç¥ããªãã¨ããªãã§ã¯ã¼ã¯ããã¼ãåããªããã ããï¼ãã¨ããããã¨ãããã®ã§è¦ãã¦ããã¾ãããï¼
è£è¶³: workflow_run
ããªã¬ã¼ãæ´»ç¨ãã
ãããGITHUB_TOKEN
ã§ã®æä½å¾ã«ã¯ã¼ã¯ããã¼ãèªåçã«èµ·åãããå ´åã¯ãworkflow_run
ããªã¬ã¼ãæ´»ç¨ãããã¨ãæ¤è¨ãã¦ã¿ãã®ãè¯ãããããã¾ããã
ããã§ä»ã®ã¯ã¼ã¯ããã¼ã®å®äºãããªã¬ã¼ã«ã§ãã¾ãã
ã¾ã¨ã
GitHub Actionsã§ã¯ã¼ã¯ããã¼ãä½æããéã«ã¯ãããã¤ãã®è½ã¨ãç©´ãä»æ§ã«æ³¨æããå¿
è¦ãããã¾ãã
ä»åç´¹ä»ãã3ã¤ã®ãã¤ã³ããæ¼ããã¦ããã°ãåå¿è
ã§ãå®å
¨ãã¤ã¹ã ã¼ãºã«ã¯ã¼ã¯ããã¼ãä½æã§ããã¯ãã§ãã
run
ã»ã¯ã·ã§ã³ã§å¼${{}}
ã¯ä½¿ããã代ããã«env
ãæ´»ç¨ããããworkflow_call
ã§ã¯github
ã³ã³ããã¹ãã¨secrets
ã®æ±ãã«æ³¨æï¼GITHUB_TOKEN
ã®æä½ã§ã¯å度ã¯ã¼ã¯ããã¼ãããªã¬ã¼ãããªãä»æ§ãè¦ãã¦ãããã
ãã®ã³ããé ã«å ¥ãã¦ãå¿«é©ãªGitHub Actionsã©ã¤ããéã£ã¦ãã ãããï¼
åèè¨äºã»ãå§ããµã¤ã
æå¾ã«åèã«ããè¨äºããå§ãã®ãµã¤ããç´¹ä»ãã¦ããã¾ãã
- actionlint playground
- workflowã®æ§æãã§ãã¯ãåºæ¥ã¾ããpushããåã«ãµãã¨ç¢ºèªããã¨ç¡é§ãæ¸ãã¾ãï¼
- GitHub CI/CDå®è·µã¬ã¤ãââæç¶å¯è½ãªã½ããã¦ã§ã¢éçºãæ¯ããGitHub Actionsã®è¨è¨ã¨éç¨ (ã¨ã³ã¸ãã¢é¸æ¸)
- åå¿è ããä¸ç´è ã¾ã§å¹ åºã人ã«ãå§ãã§ããè¯æ¸ã§ãï¼