#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
	set -o xtrace
fi

if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
	echo 'Usage: hack/make/release tag

This script creates a release tag.

'
	exit
fi

cd "$(dirname "$0")"

main() {
	tag="$1"
	MESSAGE="New release ${tag}"
	if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then
		echo -e ' - Tag already exists...'
		git tag -d $tag
		git push origin :refs/tags/$tag
		git tag -a $tag -m "$MESSAGE"
		git push origin $tag
	else
		git tag -a $tag -m "$MESSAGE"
		git push origin $tag
	fi
}

main "$@"
