#!/bin/bash

VERSION="$(cat version/version)-dev"

pushd repo

for file in $(find . -name Cargo.toml); do
    sed -i'' "s/^version.*/version = \"${VERSION}\"/" ${file}
done

sed -i'' "s/sim-time\", version = .*/sim-time\", version = \"${VERSION}\" }/" ./Cargo.toml
sed -i'' "s/es-entity-macros\", version = .*/es-entity-macros\", version = \"${VERSION}\" }/" ./Cargo.toml

cargo update --workspace

if [[ -z $(git config --global user.email) ]]; then
  git config --global user.email "bot@galoy.io"
fi
if [[ -z $(git config --global user.name) ]]; then
  git config --global user.name "CI Bot"
fi

git status
git add -A

if [[ "$(git status -s -uno)" != ""  ]]; then
  git commit -m "ci(dev): set version to ${VERSION}"
fi
