labs42io / circleci-monorepo

An example of monorepo with CircleCI using conditional workflows and pipeline parameters.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Store main/master branch in variable and update documentation

mathewvaughan opened this issue · comments

Some pre-amble:

I borrowed your script (Thank you so much) for a personal project of mine, and I wanted to give back with some feedback! I would also love to be involved with extending your work: I genuinely think the mono-repo is the way to go but it can be very difficult to get tools to play nicely with them! So yeah - thanks again!

Issue:

Github now encourages a default branch of 'main' instead of master, and I guess some people might prefer to use a different name (Who knows why??). So running your script for my new repo fails: it can't find master (my branch is called main)

Solutions:

Initially I thought maybe extracting the name of the main branch into a variable and allowing the user to set this in the script (or even as an Env var in circleci) would be useful, however on second thoughts I wonder if a slightly more robust way might be to query their remote for the "default branch from with .circleci/circle_trigger.sh.

Final comments:

I don't know the exact details of how to get this properly working (some googling led me to a solution that might work, but I'd anticipate hitting some caveats). I'd be happy to put a PR in if you're interested!

Edit: I don't understand bash well yet - so if this is already intended behaviour I may have missed it.

Hi @mathewvaughan, this is a good point. I think I missed it because when I first implemented the v1 script, Github was still using master as a default branch.

In terms of a stable solution, I don't think there is a reliable way to get a remote default branch, or at least I don't know of any ways to get it. My suggestion would be to make it configurable via an env variable like DEFAULT_BRANCH. When present use it, otherwise default to current master.

You're more than welcome to open a PR for this.