#!/bin/bash

# Publishes treebeard to pypi, remember to bump the version number
# NOTE: Any dependencies listed in Pipfile other than this package will fail
# to install for users who do not have pipenv installed.
# For this reason, list all dependencies in setup.py

set -euo pipefail
set -x

clean_artifacts() {
  rm -rf build dist ./*.egg-info
}

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
pushd "$DIR"
pyright && black --check .

clean_artifacts
python setup.py sdist bdist_wheel
twine upload dist/*
clean_artifacts
pipenv install --pre # necessary after version changes

echo "Wait a couple of minutes before pushing for Pypi to serve the new version..."
echo
echo "While waiting, consider if you need to update the treebeard build image with \`gcloud builds submit\`"

sleep 120
echo "Done."
popd

