#!/bin/sh

if [ "$(git branch --show-current)" = master ]; then
  MAIN=cmake-init/cmake_init.py
  VERSION="v$(grep -oP '^__version__ = "\K\d(\.\d+){2}' "${MAIN}")"
  if [ -n "$(git ls-remote --tags origin "${VERSION}")" ]; then
    echo "${VERSION} already exists remotely, bump the version" >&2
    exit 1
  fi
  if [ -z "$(git tag -l "${VERSION}")" ]; then
    echo "Missing tag ${VERSION}" >&2
    git tag "${VERSION}"
    exit 1
  fi
fi

exit 0
