#!/bin/sh

set -e

if [ "x$1" = "x--help" -o "x$1" = "x-h" ] ; then
    echo "Usage: ./scripts/create-release [--tag]"
    exit 1
fi

if ! git diff --exit-code --quiet ; then
    echo "There are not committed changes!"
    exit 1
fi

# Grab version
version=`python3 -c 'import translation_finder ; print(translation_finder.__version__)'`

# What are we going to build?
if [ "x$1" = "x--tag" ] ; then
    git tag -s $version -m "Version $version"
fi

# PyPi archive
rm -f dist/translation-finder-$version*
fakeroot python3 ./setup.py sdist
fakeroot python3 ./setup.py bdist_wheel --universal

if [ "x$1" = "x--tag" ] ; then
    twine upload --sign --identity 63CB1DF1EF12CF2AC0EE5A329C27B31342B7511D dist/translation-finder-$version*
    twine upload --sign --identity 63CB1DF1EF12CF2AC0EE5A329C27B31342B7511D dist/translation_finder-$version*
fi
