#!/bin/sh

set -eu

cd "$(dirname "$0")/.."

v="$(git describe --tag | sed -e 's/-/+/')"
if [ -f dist/LASTBUILD ]; then
    v0="$(cat dist/LASTBUILD)"
else
    v0=
fi

if [ "$v" = "$v0" ]; then
    exit 1
fi

echo "__version__ = '$v'" > squad/version.py
trap 'git checkout -- squad/version.py' INT TERM EXIT
rm -rf dist/squad*.whl
SQUAD_GIT_BUILD=yes python3 -m squad.frontend
for po in $(find squad/*/locale -name \*.po); do
    chronic msgfmt -o ${po%.po}.mo ${po}
done

SQUAD_RELEASE=1 chronic python3 setup.py bdist_wheel

echo "$v" > dist/LASTBUILD
