#!/bin/bash

if [ "${1}" == "" ]; then
	echo "Error: No version provided"
	echo "./makerelease 0.0.1"
	exit 1
fi

ssh -T git@github.com
if [ ! "${?}" = "1" ]; then
  echo "No Github ssh key loaded exiting..."
  exit 1
fi

clear
declare BRANCH=""
BRANCH=$(git rev-parse --abbrev-ref HEAD)
read -r -p "Current branch is ${BRANCH}. Continue ? (y/N)" choice
case "${choice}" in 
  n|N|'' )
    echo "Cancel !"
    exit 1
  ;;
  y|Y ) echo "Make release...";;
  * )
    echo "Cancel !"
    exit 1
  ;;
esac



# Ready to update :

declare VERSION
VERSION=${1}

sed -i 's/pkgver=.*/pkgver='"${VERSION}"'/' packaging/archlinux/dokytree/PKGBUILD

git commit -a -m "Version ${VERSION}"
git push

git checkout main
git merge dev
git push

git tag -a "v${VERSION}" -m "Version ${VERSION}"
git push --tags

git checkout "${BRANCH}"
