#!/usr/bin/env bash

set -e

VERSION=$(node -p -e "require('./package.json').version")
CURRENT_BRANCH="$(git symbolic-ref --short -q HEAD)"

success() {
  echo -e "\033[32;1m$1"
}

error() {
  echo -e "\033[31;1m$1"
}

if [ -z "$CURRENT_BRANCH" ]; then
  error "Not in a branch."
  exit 1
fi

if [ -z "$VERSION" ]; then
  error "Unable to get current npm version of this package."
  exit 1
fi

git config user.name "Github Actions"
git config user.email "reactstrap@github.io"
git tag -a "v$VERSION" -m "release $VERSION"
git push --set-upstream origin $CURRENT_BRANCH > /dev/null 2>&1
git push --tags > /dev/null 2>&1

success "pushed $VERSION tag to $CURRENT_BRANCH."
