Auto Semantic Versioning


Working at a startup, we are a little behind the curve with our tech. This creates a new opportunity to institute standards for the org. Our CTO asked myself and my manager to look into get Semantic Versioning in place. If you don't know what Sem Versioning is, it's kind of the standard for versioning software: v1.2.3=Major, Minor, Patch. More info here: https://semver.org/
He want us to start building releases built into our GitLab pipelines and having semantic version tags attached to each release for tracking purposes. Wanting to not have to manually input versions, we started looking for anything that could automated the semantic versioning process. Enter GitVersion: https://gitversion.net/
GitVersion is a tool use to setup Automated Semantic Versioning by configuring a YAML file for each branch in your Git workflow. We use the traditional workflow of:
Feature -> Develop -> Release -> Master/Main. Also the occasional Offcycle or Hotfix branch as well
We started by configuring the yml file follow this flow, by defining the incrementing of either Patch, Minor, or Major for each branch. Once this was configured we setup a .pre step in the GitLab pipeline.
Side-note: A .pre step runs at the beginning of a pipeline as long as there is another job also in the pipeline.
The .pre.yml file had steps to pull down a GitVersion docker container, setting the GIT_STRATEGY to fetch and GIT_DEPTH: 0, so we get the entire repository to get an accuracy of commits. Since GitVersion is C# based, you have to use .NET tooling to run this as well as export the artifact as a .env file. In this artifact, we can then extract the SemVersion from there. Downstream in our release job, we then grab the SemVersion, use the GitLab Release CLI to pass in the versioning.
Overall the tool was a challenge to get work and tweaked, but it is totally worth not having to work about manual versioning.
Subscribe to my newsletter
Read articles from Tyler Durham directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Tyler Durham
Tyler Durham
Hi everyone, Nice to meet you all! I found Hashnode from a cloud tech channel that I follow and I am glad to be here.Tech has always been a passion of mine and I enjoy how expansive it is. A little about me, I've been in tech for ~12 years, started by doing a help desk role supporting the first iPhone. Most of my experience is in QA/Test from mobile devices, to SaaS platforms, automation, Ci/CD, etc... Currently, I am looking to learn all can about "the cloud" in the form of AWS. I am very interested in building a career as a DevOps/SRE. Most of blog will be about learning cloud technologies and how they fit together.