if [[ -n $(git status --porcelain) ]]; then
echo "Error: Working tree is not clean. Please commit or stash your changes."
exit 1
fi
current_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "Current tag: $current_tag"
read -p "Enter the new tag (without the \"v\"): " new_tag
if [[ ! $new_tag =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Tag must be in the format x.y.z"
exit 1
fi
git cliff -c cliff.toml -u -t "v$new_tag" -p CHANGELOG.md
sed -i -E "s/^version = \"[0-9]+\.[0-9]+\.[0-9]+\"/version = \"$new_tag\"/" Cargo.toml
sed -i -E "s/^version = \"[0-9]+\.[0-9]+\.[0-9]+\"/version = \"$new_tag\"/" poke-engine-py/Cargo.toml
sed -i -E "s/^version = \"[0-9]+\.[0-9]+\.[0-9]+\"/version = \"$new_tag\"/" poke-engine-py/pyproject.toml
cargo update -w
new_tag="v$new_tag"
git add Cargo* poke-engine-py/Cargo.toml poke-engine-py/pyproject.toml CHANGELOG.md
git commit -m "$new_tag"
git show
git tag -a "$new_tag" -m "$new_tag"
echo "Done! Tagged $new_tag"
echo "Verify the commit and push (git push origin main --tags)"