Written on 2024-04-10 by Adam Drake - 4 min read
I work in a Monorepo in my day-to-day work as a Frontend Developer. It has it’s pros and cons like anything and it helps us achieve our goals as a software team. Through working in a monorepo though we have had to come up with a release strategy around our Git branches as we have to be able to release multiple apps at different times to different environments.
Our general strategy is:
We are using Terraform to help handle deployments so it’s not just a case of merging something into develop and it goes to the staging environment. We have to actively configure a few things and press a button to enable an actual deployment. (There are a few more nuances to it but I don’t want to get into those details here).
This strategy works well for us but there was one situation we were running into which was:
So how to solve this?
This is where Git tags came in to help us. Git tags allow you to “tag” specific points in a repository’s history. These are very often used to mark something important such as a release. We started using them to mark “pre-releases”.
Therefore when we were happy with the state of develop and deployed this to staging we would create a tag from the develop branch to mark this as the code we would want to merge to master if approved. The tag name would be something like:
This tag allows us to get the code in exactly the state it was merged to develop and released to staging.
Once everything is staging is approved and we’re good to release to production we then create a branch from the git tag. To do this locally you can run the following:
2. Checkout the tag you want to make the branch from:
3. Create a branch off this tag. Bear in mind at this point the code is in a “detached HEAD” state meaning you aren’t working from the top of any branch.
With this branch you can now create a Pull Request into master and it will only push the changes that were deployed to staging and not include any code changes since that were merged to develop.
I have found working in a monorepo brings many benefits to a development team including quicker local development, catching changes early that could potentially cause production issues and easily having all the most up to date code running in your development environment. However, it comes with it’s own set of challenges too and one of these is deployments. When you have many changes going into the “main” working branch it can be tricky to make sure you only deploy what you want to deploy.
This strategy above has really helped us as a team gain finer control over what should and what shouldn’t be included in our deployments. It’s a simple approach and really shows the power of versioning systems when working in a collaborative environment.
Loading...
Adam Drake is a Frontend React Developer who is very passionate about the quality of the web. He lives with his wife and three children in Prague in the Czech Republic.
Adam Drakes Site © 2024