Semantic Versioning

October 24, 2022

Semantic Versioning

The guide below will show you how to auto-increment the version of your application in any Git repository using Buddy's pipeline.

Actions used in this guide:

The pipeline will perform the following tasks:

  • use parameters to define which digit we want to raise (major/minor/patch)
  • determine $latest_version with a script
  • push the tag to your repository:

Pipeline overviewPipeline overview

1. Add Git repository

The first step is adding the repo with your project. In this example, we'll use GitHub:

Creating new projectCreating new project

2. Configure pipeline settings

Now we can add the delivery pipeline. Let's configure it so that it runs on every push to the Master branch:

Adding new pipelineAdding new pipeline

3. Configure pipeline actions

3.1 Add environment variables

Before we get down to the actions we need to add a couple of variables that we'll use in a script later on. Switch to the Variables tab and add these three keys:

  • $major
  • $minor
  • $patch

Variables overviewVariables overview

  • Set the type to Settable as we need the action to remember the value before every execution
  • Set the variable scope to pipeline – we don't want to use them anywhere else
  • Unless you already have a tag version in your repo, set all values to zero.

3.2 Set version type

By default, the pipeline will increment the patch version (0.0.1) on every push. Let's add an action that will allow us to raise a minor (0.1.0) or major (1.0.0) number on manual trigger.

Look up Pass Arguments in the Flow section:

Pass Arguments actionPass Arguments action

Add these two parameters:

  • $is_major
  • $is_minor

Set the input mode to option and set the value to:

true
false

Defining parametersDefining parameters

Trigger condition

Since we want to run this action only in manual mode, we need to configure a trigger condition for that in the Condition tab:

  • select 'Run only if ENV VAR has specific value'
  • set the variable to: $BUDDY_EXECUTION_MODE is CLICK

Creating trigger conditionCreating trigger condition

From now on, whenever you run the pipeline manually, Buddy will ask you which version type you want to increase. If neither major nor minor is selected, the patch number will be incremented.

3.3 Set version number

The next step is adding an action with the versioning script. Select the Custom build action and paste the script below in the commands field. The script raises the selected version type by 1 and creates the tag for your commit:

if [ -n "$is_major" ] && ($is_major) ; then
 ((major=major+1))
 minor=0
 patch=0
elif [ -n "$is_minor" ] && ($is_minor) ; then
 ((minor=minor+1))
 patch=0
else
 ((patch=patch+1))
fi
latest_version=$major"."$minor"."$patch
#add tag
git tag "$latest_version"
$$$$$$$$$$$$$

Run commands with incrementation scriptRun commands with incrementation script

Installing Git

The script requires Git to work, so make sure to install it in the Packages & Tools tab of the action's image settings:

apt-get update && apt-get -y install git
$

Installing GitInstalling Git

3.4 Push tag to repository

With the version defined and tag created, we can finally push it to our project. Select the Git Push action and configure authentication details to your repository:

Action detailsAction details

You can also use environment variables to store sensitive data like server credentials.

Summary

When ready, make a push to your repository and check the results. Then, run the pipeline in manual mode: if everything's been configured correctly, Buddy will ask you for the version type and increment the tag in your repository:

GitHub panelGitHub panel

Alexander Kus

Alexander Kus

Customer Success Manager

A story-teller and conversation-lover, Alexander decided to invest his skills to help his friends at Buddy transform the cold language of patch notes into exciting narratives. Also: an avid gamer, hip-hop DJ, Liverpool FC fan, absentminded husband, and the father of two.

With Buddy even the most complicated CI/CD workflows take minutes to create

Sign up for Buddy CI/CD

Start a free trial

Trusted by customers from 170+ countries