🤖 Automate your version management 🤖
Tags: javascript, npm, devops
Published: 2022-06-25 18:57:48

## Introduction

Version management, or the art of passing from 1.0.0 to 1.0.1, is a process, in our technical world, that is very important but sometimes vastly underestimated and somewhat disregarded by some of us (me included 😅).

The benefits of good version management, to list a few, could be:

- Information - When the versioning is well done, it can provide very useful information to users and softwares (technical and non technical).
- Security - For us, technical people, we use versioning to make sure we run the latest, security threat free, packages.
- Compatibility - For a package manager such as NPM, it helps creating the perfect package mix and alert of breaking changes and security threats.
- More information - For end users, it helps understanding if they are up to date, or not!
- Activity - A great measure to understand if a project is still ongoing is the frequency at which it releases new versions to adapt to security threat and updates from other packages.
- more ... I don't know, let me know in the comments 😁

Essentially, a version is often written as 0.0.1. This versioning style is essentially composed of three components: the lead 0, the middle 0 and the 1. In most cases, they indicate the following:

Lead 0 indicates the major version.
Middle 0 indicates the minor version.
The 1 indicates the patch version.

**MAJOR, MINOR, PATCH** versions. As simple as that.

If you want to respect those rules, which are commonly accepted, the idea is that you update your version according to the following principles:

1. Major version changes are made when a breaking change is introduced or when the product changes profoundly
2. Minor version changes are made when your team introduces a new feature
3. Patch version changes are made when changes occur in the code base that do not introduce new features. Could be a security patch, some bug fixes, more stuff.

## How we automate it

In my world, in which most projects front and back are managed with a `package.json`, version management is usually forgotten and updated from time to time in a not so much established process. Usually the impact is slim to none we run most of our development internally and with a very closed IT environment. However, we recently decided to kick our devOps a notch and one of our projects was to automate version management. We wanted it automated to 1. never think about it and 2. show the state of each platform we develop. Hopefully a 1.0.22 shows more work than a 0.0.2.

In our efforts to automate the process of going from 0.0.1 to 0.0.2, we built a small (1 script), lightweight (17kb) and git ready package for reusability across all our projects.

Enters *bumpme*, a cli that helps you automate your package.json version management.

Bumpme is a simple CLI that helps you automate your version management. You can run it like so `bumpme` or with arguments like `-s` or `-i`. `-s` represents severity (patch, minor, major) and `-i` represents increment (by how much it should be changed).

A cool feature of `bumpme` is the automated integration with git. The idea from the get go was to integrate it with git in order to read the commit message and bump the version accordingly. `bumpme` reads the git commit message and tries to find a specific command which can be something like [[patch:1]]. Such a command, as you guess, will pass the package.json from 0.0.1 to 0.0.2. Pretty cool!

## Automate it

It would be silly of us to keep the responsibility of versioning and running a specific `bumpme` command for each commit to our main branch to a human! We decided to use Github workflows for that. If you do not know what a Github workflow is, I encourage you to learn about it. It is a very useful automation tool. For each commit merged into our main branch, for which one person is responsible to press the button, a github worklow will trigger. In this github workflow we simply insruct the machine to un `npx bumpme` or `npm run bumpme` (how you want to do it is really your problem). The `bumpme` command simply reads the latest git commit message (which comes with the merging of branch) and bumps the version accordingly. Again, pretty cool!

If you want to test or use it, here is the NPM link: [@food7go/bumpme](https://www.npmjs.com/package/@food7go/bumpme).

This is an open source project, meaning that we welcome review, new ideas and obviously contribution.

Thanks for reading!