Managing Your Application Version with SemVer

I’m in the midst of designing a CI/CD pipeline and was looking for a way to auto-increment the the application versions somewhere within there.

The first step was to try to track down some kind of web service or script that would do this for me. I ended up coming across a bash implementation of the Semantic Versioning specification which you’re probably already familiar with to some degree. It operates on the following format <major>.<minor>.<patch> i.e. 1.0.0.

It’s really easy to use. All you have to do is download the ZIP from GitHub and place the semver script in your path.

Version Bumping

So, we’ll go through a few examples of how to bump your application versions.

Bumping Patch Version

To see what a simple patch version bump would look like, just execute the following command:

semver bump patch 1.0.0

This will return:

1.0.1

Bumping Minor Version

Now for minor version, all you had to do is swap out minor for patch which looks like this:

semver bump minor 1.0.0

And that will spit out:

1.1.0

You’ll notice too that if you do a minor version bump and you have already made a few patches, it’ll reset the patch version to 0. Just enter the following into your terminal:

semver bump minor 1.0.3

And you’ll see the patch version reset with the minor version bump:

1.1.0

Bumping Major Version

Now for the major version bump. Not only will this increase the major version from 1 to 2, it will also reset the minor and patch values as well. Just issue this command:

semver bump major 1.2.3

And you’ll see that the major version increased and the minor and patch versions reset to 0.

2.0.0

Next Steps

Now that I have a tool for auto-incrementing my version numbers, the next thing will be fitting that into my CI/CD pipeline somewhere. Given I’m using Docker images and Kubernetes, I’ll want to find a way to set the image tag with this increased version and ensure that the Kubernetes manifests have this version set as a label as well.