ãã¾ã«ãããããªããã¤ã¡ã¢
- ã¢ããã¼ã·ã§ã³
- å®éã®ã¹ã¯ãªãã
- ãã¾ãï¼å®éã«GitLab CIã§åããã¦ããã¤
- 2024/06/28 22:06追è¨ï¼GitHub Actionsã®å ´åã®æ³¨æç¹
ã¢ããã¼ã·ã§ã³
CIã§Terraformãåããã¦ããã¨
- mainãã©ã³ããèªåapply
- PRã¨ãã§ãã¼ã¸åã«æåã確èªãããå ´åã¯PRã«åºã¦ãããã©ã³ããæåapply
ã¨ããã¯ã¼ã¯ããã¼ãä½ããã¨ããããããã§ãããææ°ã®mainãã©ã³ããããå¤ããã©ã³ããapplyããæã«applyæ¸ã®æ§æãå·»ãæ»ã£ã¦äºæ ã«ãªãããããããªããªãããã«é²æ¢ãããã£ãã¨ãããã¤ã§ãã
å®éã®ã¹ã¯ãªãã
ã©ã®CIã§åãããã«ãã£ã¦å¤å°ã¯å¤ãã£ã¦ããã¨æããã©ã ãããããã§åãã¨æãã¾ãã
default_branch=`git remote show origin | grep 'HEAD branch:' | cut -d : -f 2 | tr -d '[[:space:]]'` commit_sha=`git show --format='%H' --no-patch` echo '[ERROR] ä¸è¨ã§ã¨ã©ã¼ã«ãªã£ãå ´åãå®è¡ä¸ã®ãã©ã³ããå¤ãã®ãåå ãªã®ã§ git rebase ãè¡ã£ã¦ãã ãã' git merge-base --is-ancestor origin/${default_branch} ${commit_sha}
解説
- ããã©ã«ããã©ã³ããmainã¨ãmasterã¨ãdevelopã¨ãæ°ã«ããããªãã®ã§èªåã§å¤æããããã«ãã¦ãã¾ã
commit_sha
ï¼ç¾å¨ã®ã³ãããããã·ã¥ï¼ã«é¢ãã¦ã¯ãåCIã§ç°å¢å¤æ°ãããã®ã§ãããå©ç¨ããã¨ããã§ããã- ããç¾å¨ã®ã³ãããããã·ã¥ãææ°ã®mainãã©ã³ããããå¤ãã£ãå ´åã«ã¯
git merge-base --is-ancestor
*3 ã§ã¨ã©ã¼ã«ãªãã¾ã - CIãã¨ã©ã¼ã«ãªã£ããã ãããã¿ããªãã°ãè¦ã«è¡ãã¨æãã®ã§ããã§ãã¯ã³ãã³ãã®ç´åã«éã«echoã§ã¨ã©ã¼ãã°ãåºãã¦ãã¾ã
ãã¾ãï¼å®éã«GitLab CIã§åããã¦ããã¤
GitLab CIã®å ´åãã¸ã§ãå®è¡æç¹ã§remoteã®ãã©ã³ãã®å
容ãåã£ã¦ããã¦ããªãããæ示çã« git fetch
ãã¦ãã¾ãã
before_script: - "default_branch=`git remote show origin | grep 'HEAD branch:' | cut -d : -f 2 | tr -d '[[:space:]]'`" - git fetch - echo '[ERROR] ä¸è¨ã§ã¨ã©ã¼ã«ãªã£ãå ´åãå®è¡ä¸ã®ãã©ã³ããå¤ãã®ãåå ãªã®ã§ git rebase ãè¡ã£ã¦ãã ãã' - git merge-base --is-ancestor origin/${default_branch} ${CI_COMMIT_SHA}
2024/06/28 22:06追è¨ï¼GitHub Actionsã®å ´åã®æ³¨æç¹
GitHub Actionsã® actions/checkout
ã¯ããã©ã«ã㧠ææ°1件ã®å±¥æ´ããcheckoutããªã ï¼v4æç¹ï¼*4ã¨ããä»æ§ãªã®ã§ãPRã®ãã©ã³ã㧠git merge-base --is-ancestor origin/main ${GITHUB_SHA}
ããã¦ãorigin/mainãæãã³ãããããã·ã¥ãåå¨ããã¨ã©ã¼ã«ãªãã¾ãã
ãã®ãããfetch-depth: 0
ã«ãã¦å
¨ã¦ã®å±¥æ´ãckeckoutããããfetch-depth: 100
ã®ããã«ååã«å¤§ããæ°å¤ãæå®ããå¿
è¦ãããã¾ããï¼å人çã«ã¯å¾è
ãæ¨å¥¨ï¼