With Semantic Versioning a version consists of 3 elements and the change determined by this legality:
- Major — when there is a change in API
- Minor — when there is a functionality in a backward-compatible manner
- Patch — when there is a bug fix
Automating the versioning process has always been a challenge in Configuration Management, with microservices it must be automated, here enters Semantic-Release
Semantic Release
Semantic Release is an Open-Source Software tool for automatically versioning your software with Semantic Versions, based on your Git commit messages
Sounds simple? Yes, it is!
The semantic release is a library that implements the “policy” of semver in a given project, it was initially designed to automatically release packages to npm, in addition, it has adopted the Angular commit convention
The commit prefix will help choose which version level we want to upgrade by the convention of the commit message:
- fix: patch change
- feat: minor change
- perf: major change
Another great benefit of semantic-release is that you can define which branch is a release branch and which is a pre-release and which aren’t eligible for release. The pre-release branch gets the ‘-’ / hyphen character with the branch name and build number. e.g example: 1.2.3-feature.1
How it actually works you can see at https://semantic-release.gitbook.io/semantic-release/
Ok, but why should I use it?
Let’s see our use case
Background
Like everyone, we moved from a monolith to microservices. from the slow release once a month we moved to almost daily releases. We needed to find a fast solution that will work swiftly.
Our mixture of programming languages include maven, python, Docker containers and helm charts.
Each method needs its own version and we wanted to create uniformity.
In three words — Speed, efficiency & Predictability!
How?
Let’s look at our GitLab (of course!).
As we said we have maven, python, and charts for now…
What do they all have in common? Nothing.
Here comes the semantic release.
We will demonstrate it on maven code:
We have 50 repositories divided into groups.
In every repository, there is a pom.xml file and in most of them Dockerfile either
We build the .gitlab-ci.yml with include files to create uniformity:
- stage.gitlab-ci.yml,
- variables.gitlab-ci.yml,
- maven-build.gitlab-ci.yml,
- deploy.gitlab-ci.yml
In every repo, we put the stage, variables, and maven-build files because every pom needs a maven build minimum.
In the repo that has Dockerfile, we insert deploy.gitlab-ci.yml too.
Where does the version change? between the build and the deploy.
We create another file called semantic-release.gitlab-ci.yml