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:
Image loading...
1. Add Git repository
The first step is adding the repo with your project. In this example, we'll use GitHub:
Image loading...
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:
Image loading...
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
Image loading...
- 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:
Image loading...
Add these two parameters:
$is_major
$is_minor
Set the input mode to option
and set the value to:
true
false
Image loading...
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
isCLICK
Image loading...
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:
bashif [ -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"
$$$$$$$$$$$$$
Image loading...
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:
bashapt-get update && apt-get -y install git
$
Image loading...
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:
Image loading...
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:
Image loading...
Jarek Dylewski
Customer Support
A journalist and an SEO specialist trying to find himself in the unforgiving world of coders. Gamer, a non-fiction literature fan and obsessive carnivore. Jarek uses his talents to convert the programming lingo into a cohesive and approachable narration.