At work we’re using debian packaging to prepare our release, this mean we need to prepare the changelog, commit the change on the changelog and tag the release.

Moreover we need to track what the current release number and to bump it accordingly.

I created a script that does all that for me, and I’m sharing it with you.

#!/usr/bin/env bash
# TYPE= argument to the script where 0 = MAJOR, 1 = MINOR, 2 = BUILD. Default to BUILD.
GIT_VERSION=$(git describe --tags)
CURRENT_VERSION=$(echo ${GIT_VERSION:1} | cut -d'-' -f1)
TYPE=${1:-2}

function increment_version() {
	local VERSION="$1"
	local PLACE="$2"

	IFS='.' read -r -a a <<<"$VERSION"
	((a[PLACE]++))
	echo "${a[0]}.${a[1]}.${a[2]}"
}

NEW_VERSION=$(increment_version $CURRENT_VERSION $TYPE)

dch -v $NEW_VERSION && git commit -p -m "Bump version $NEW_VERSION" && git tag v${NEW_VERSION}