#!/usr/bin/env bash
#
# This script is used to retag a failed build
#

version=$(head -1 Cargo.toml | awk '{ print $3 }')

git tag -d "release/v$version" || true
git tag -s -a "release/v$version" -m "Version $version" -m "See https://github.com/Liefland/overworld/blob/main/CHANGELOG.md for a list of all changes."

if [ "$1" == "--force" ]; then
    git push --tags --force
else
  read -r -p "The next step is to push, the CI will handle the rest. Continue? [y/N]" response

  if [[ "$response" =~ ^[yY] ]]; then
    git push --tags --force
    echo "Pushed tag v$version"
    echo "Please keep an eye on https://github.com/Liefland/overworld/actions to see if the build succeeds."
  else
    echo "Will not automatically push."
    echo "Please run 'git push --tags --force' to push the tag and continue the release"
    exit 0
  fi
fi
