I am trying to implement a solution to increment a version. Here's what I have come up with:
#!/bin/sh -x
VAR=1.0.1 # retrieved from Gitlab API
case $1 in
patch)
TAG=${VAR%.*}.$((${VAR##*.} + 1))
;;
major)
TAG=$((${VAR%%.*} + 1)).0.0
;;
*)
tmp=${VAR%.*}
minor=${tmp#*.}
TAG=${VAR%%.*}.$((minor + 1)).0
;;
esac
echo $TAG
major
& patch
work as expected; however, I'm facing problems incrementing minor
.
When bumping 1.0.1
, the minor should be 1.1.0
; however, my code produces 1.2.0
. What am I doing wrong?
Some more info, the script is executed inside a GitlabCI pipeline.
Edit: Updated the code with the suggested answer from @jhnc