#!/usr/bin/env bash

set -eu -o pipefail

# ./check

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

CURRENT_VERSION=($(cat ./cloud_savegame/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

# echo new version: $VERSION
# exit 0
printf "%s" "$VERSION" > ./cloud_savegame/VERSION

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

