åºç¤ãã¼ã ã®å·äº (@fohte) ã§ãã
ä»åã¯ãmonorepo ã¨å¼ã°ããè¤æ°ã®ãªãã¸ããªãåä¸ã®ãªãã¸ããªã§ç®¡çããéç¨æ¹æ³ã®ç´¹ä»ã¨ãå®éã«ãã®éç¨ã«åãæ¿ãã話ããã¾ãã
å¼ç¤¾ã¯ GitHub Enterprise ã使ã£ã¦ãããGit Flow ãç¬èªã«æ¡å¼µãã master, develop, feature ãã©ã³ãã® 3 種é¡ãããªãéç¨ããã¼ãæ¡ç¨ãã¦ãã¾ãã ä»åã¯ãã®ç°å¢ãåæã¨ãã¦ã話ãã¾ãã
monorepo ã¨ã¯ï¼
monorepo ã¯ãè¤æ°ãªãã¸ããªãåä¸ã®ãªãã¸ããªã§ç®¡çããã¨ãã Git ãªãã¸ããªã®éç¨æ¹æ³ã®ä¸ã¤ã§ãã
monorepo ã®ã¡ãªããã¨ãã¦ã¯ä»¥ä¸ã®ç¹ãæãããã¾ãã
- å¯çµåãªãªãã¸ããªã®éç¨ã楽ã«ãªã
- è¤æ°ãªãã¸ããªã«æ¨ªæããä¿®æ£ãç°¡åã«ã§ããããã«ãªã
ä¾ãã°ããããªãã¸ã㪠A ã®å¤æ´ã«å¾ã£ã¦å¥ã®ãªãã¸ã㪠B ãå¤æ´ããã¨ãããªãã¸ããªãè¤æ°åããã¦ããã¨ããããã®ãªãã¸ããªã« commit ãåæ£ãããã¨ã«ãªãã¾ãã ããã¯åç´ã«é¢åã§ãããä½ãã commit å¯èªæ§ãæªããªãã¾ãã
ã¾ãããã®ãããªã¨ãã¯ãªãã¸ããªãã¨ã« Pull Request ãç«ã¦ãå¿ è¦ãããã¾ãããmonorepo ã§ã¯ 1 ã¤ã«ã¾ã¨ã¾ããããPull Request ã®å¯èªæ§ãåä¸ãã¾ãã
å対㫠monorepo ã®ãã¡ãªããã¨ãã¦ã¯ä»¥ä¸ã®ç¹ãæãããã¾ãã
- ãªãã¸ããªã巨大ã«ãªã
è¤æ°ã«åæ£ãã¦ãããªãã¸ããªã 1 ã¤ã«ã¾ã¨ãã¦ãã¾ãã®ã§ãçµæã¨ã㦠Git ãªãã¸ããªã¯çµ±åãããªãã¸ããªã®åã ã大ãããªãã¾ãã
ãã¾ãè¦æ £ããªãéç¨æ¹æ³ã§ã¯ããã¾ãããRailsãBabelãReact ã¨ãã£ã巨大㪠OSS ããã¸ã§ã¯ãã§ãæ¡ç¨ããã¦ãã¾ãã
monorepo ã¸ã·ã¼ã ã¬ã¹ã«ç§»è¡ãã
monorepo ã«ç§»è¡ããã¨ãªãã¨ãåãªãã¸ããªã®ãã©ã³ãã monorepo å´ã«ç§»ããªããã°ããã¾ããã ããã§ãéçºè ã®æãæ¢ãããã¨ãªã monorepo ã«ç§»è¡ããæ段ã¨ãã¦ã以ä¸ã®æ¹æ³ãæ¤è¨ãã¾ããã
- åãªãã¸ããªã® feature ãã©ã³ããå«ãããã©ã³ãå ¨ã¦ã monorepo ã«ç§»ãã移è¡ç´å¾ãã monorepo å´ã® feature ãã©ã³ãã§éçºãã
- master ãã©ã³ãã ãã monorepo ã«ç§»ããåãªãã¸ããªã§éçºä¸ã® feature ãã©ã³ã㯠merge å¾ã«ç§»è¡ãã
åè ã®å ´åãåéçºè ã®æå ã®å¤æ´ã¯ monorepo å´ã«åãè¾¼ã¾ããªãã¨ããæ¬ ç¹ããããããä»åã¯å¾è ã®æ段ãé¸æãã¾ããã ã¾ããå¼ç¤¾ã§ã¯ master ãã©ã³ãã¨ã¯å¥ã« develop ãã©ã³ããããã¾ãããdevelop ãã©ã³ããå¾è¿°ã®æ¹æ³ã§ç§»è¡ãã㨠master 㨠develop ãå ¨è¡å·®åã«ãªã£ã¦ãã¾ãåé¡ããã£ããããmaster ãã©ã³ã移è¡å¾ã«æ°è¦ã« master ãã develop ãã©ã³ããåãç´ãã¾ããã
移è¡æé
ä»å㯠git subtree
ã³ãã³ããç¨ãã¦ç§»è¡ãã¦ãã¾ãã
git subtree
èªä½ã¯ git ã«å
èµããã¦ããã³ãã³ãã§ã¯ãªããããç°å¢ã«ãã£ã¦ã¯ã³ãã³ããç¡ãããã®å ´åã¯æåã§ã¤ã³ã¹ãã¼ã«ããå¿
è¦ãããã¾ãã
git clone https://github.com/git/git.git cd git/contrib/subtree make cp git-subtree /usr/local/bin # ãã¹ãéã£ã¦ãããã£ã¬ã¯ããªã«ã³ãã¼ãã
åãªãã¸ããªã® master ãã©ã³ãã monorepo ã«ç§»è¡ãã
å ã« monorepo åããåãªãã¸ããªã® remote ãç»é²ããfetch ãã¦ããã¾ãã
git remote add <name> <repo_url> git fetch -a <name>
<name>
: remote ã®ååã§ããä»å㯠monorepo ã®ãµããã£ã¬ã¯ããªåã¨ãã¾ãã<repo_url>
: åãªãã¸ããªã® URL ã§ãã (ä¾:[email protected]:rails/rails.git
,https://github.com/rails/rails.git
)
ã¾ãã空 commit ãä½æãã¦ããã¾ãã
git checkout --orphan master git commit --allow-empty -m 'Root commit for master branch'
次ã«ãgit subtree add
ã³ãã³ãã§åãªãã¸ããªã monorepo ã®ãµããã£ã¬ã¯ããªã¨ãã¦è¿½å ãã¾ãã
git subtree add --prefix=apps/<name> <name>/master
--prefix
ã«æå®ãããã£ã¬ã¯ããªã«ãªãã¸ããªãåãè¾¼ã¾ãã¾ãã
ä»å㯠apps
ãã£ã¬ã¯ããªä¸ã«ãã©ããã«ãªãã¸ããªãç½®ãã¦ãã¾ãã
æå¾ã«ã念ã®ãã git diff-tree
ã§å·®åããã§ãã¯ããåé¡ããªããã° master ãã©ã³ãã®ç§»è¡ã¯å®äºã§ãã
git diff-tree -r --stat <name>/master master:apps/<name>
feature ãã©ã³ãã®å¤æ´å 容ã monorepo ã«åãè¾¼ã
ä»åã¯ãåãªãã¸ããªã§éçºä¸ã® feature ãã©ã³ãã¯ãã®ãªãã¸ããªã« merge ãã¦ãã¾ãããã®å¾ monorepo å´ã«åãè¾¼ã¿ã¾ãã
ãã®å¾ãgit subtree merge
ã³ãã³ãã§ãµããã£ã¬ã¯ããªã« merge ããmonorepo å´ã«åãªãã¸ããªã§ã®å¤æ´ãåãè¾¼ã¿ã¾ãã
git checkout master git subtree merge --prefix=apps/<name> <name>/<branch>
master ãã©ã³ã移è¡æåæ§ã«å·®åããã§ãã¯ããåé¡ããªããã° feature ãã©ã³ãã®å¤æ´ã®åãè¾¼ã¿ã¯å®äºã§ãã
git diff-tree -r --stat <name>/master master:apps/<name>
ææ
移è¡åã«æ¸å¿µãã¦ãããã¨ã¨ãã¦ãä¸è¿°ã®ãã¡ãªããã¨ãã¦ãæãã Git ãªãã¸ããªãéããªããããããªãã¨ããç¹ãããã¾ããã
ä»åã¯ã¢ã¯ãã£ã㪠Rails ã¢ããªã±ã¼ã·ã§ã³ã®ã¿ (5, 6 ãªãã¸ããª) ã monorepo åããcommit ã®ç·æ°ã¯ 6,000 ã»ã©ã¨ãªãã¾ããããç¾æç¹ã§ã¯ git ã³ãã³ãã«éããæãããã¨ã¯ããã¾ããã
ãã¡ã¤ã«ãå¢ãã¦ããå容éèªä½ã¯å¤§ãããªã£ã¦ãããã git clone
æãªã©ã«éããæãã¾ãããããã¯è¤æ°ãªãã¸ããªã git clone
ãã¦ãããããªãã®ã§ãããã許容ãã¦ãã¾ãã
ã¾ãã移è¡ã®é£æ度ãã³ã¹ããé«ãã®ã§ã¯ã¨ããæ¸å¿µãããã¾ããããæ³å以ä¸ã«å®¹æã«ç§»è¡ãããã¨ãã§ããå ¨ãåé¡ã¯ããã¾ããã§ããã
monorepo åã㦠1 ã¶æã»ã©éç¨ããã¦ãã¾ãããç¹ã«å¤§ããªåé¡ããªãã1 ãªãã¸ããªã§å®çµãããã¨ã®æ©æµã大ãã«åãã¦çç£æ§ãåä¸ãã¦ããã¨æãã¾ãã
ã¾ã¨ã
ä»å㯠monorepo ã¨ãã Git ãªãã¸ããªã®éç¨æ¹æ³ã«ã¤ãã¦ç´¹ä»ãã¾ããã
git subtree
ã³ãã³ããç¨ããã¨æ軽㫠monorepo åã§ããã®ã§ãå¯çµåãªãªãã¸ããªãããã¨ãã®è§£æ±ºçã® 1 ã¤ã¨ãã¦ãã²æ¤è¨ãã¦ã¿ã¦ãã ãã!
ã·ã³ã¯ãã»ãã¼ãã§ã¯éçºåºç¤è¨è¨ã«èå³ã®ããã¨ã³ã¸ãã¢ãåéãã¦ãã¾ãããèå³ã®ããæ¹ã¯ä»¥ä¸ãããé£çµ¡ãã ãã!