#!/usr/bin/env bash

set -eu -o pipefail

if [ $# == 1 ]; then
	VERSION="$1"; shift
else
	echo ./make_release versao_nova >&2
	exit 1
fi

CURRENT_VERSION=($(cat ./VERSION | sed 's;\.; ;g'))

case "$VERSION" in
	patch)
		VERSION="${CURRENT_VERSION[0]}.${CURRENT_VERSION[1]}.$((${CURRENT_VERSION[2]}+1))"
	;;
	minor)
		VERSION="${CURRENT_VERSION[0]}.$((${CURRENT_VERSION[1]}+1)).0"
	;;
	major)
		VERSION="$((${CURRENT_VERSION[0]}+1)).0.0"
	;;
esac

printf "%s" "$VERSION" > ./VERSION

git add -A
git commit -sm "bump to $VERSION"
if [[ ! -v NO_TAG ]]; then
	git tag "$VERSION"
	git push --tag
fi
git push
