#!/bin/bash

git config user.email "jonathan.franco.2103@gmail.com"
git config user.name "CI"
git remote remove ci
git remote add ci https://oauth2:"${PUBLISH_TOKEN}"@gitlab.com/rglw/public/database/rglw_orm.git
git checkout main
git reset --hard origin/main

cargo install toml-cli

ROOT=$(pwd)

DEPENDENCIES_VERSION=$(toml get Cargo.toml workspace.package.version --raw)

ROOT=$(pwd)
CODEGEN=${ROOT}/rglw_orm_codegen
CORE=${ROOT}/rglw_orm_core

cd "${CODEGEN}" || exit 1
cargo publish
cd "${CORE}" || exit 1
toml set Cargo.toml dependencies.rglw_orm_codegen.version "${DEPENDENCIES_VERSION}" > Cargo.toml.modified
mv Cargo.toml.modified Cargo.toml
cargo publish --allow-dirty
cd "${ROOT}" || exit 1
toml set Cargo.toml dependencies.rglw_orm_codegen.version "${DEPENDENCIES_VERSION}" > Cargo.toml.modified
mv Cargo.toml.modified Cargo.toml
toml set Cargo.toml dependencies.rglw_orm_core.version "${DEPENDENCIES_VERSION}" > Cargo.toml.modified
mv Cargo.toml.modified Cargo.toml
cargo publish --allow-dirty