#!/bin/sh

set -e

usage() { echo "usage: `basename $0` oldversion version" ; }

[ $# -eq 2 ] || { usage >&2 ; exit 1 ; }

OLDVERSION="$1"
VERSION="$2"

git clean -f -d -x

MESON=meson.build

grep $OLDVERSION "$MESON" > /dev/null || { echo "Couldn't find OLDVERSION ($OLDVERSION) in $MESON" >&2 ; exit 1 ; }
sed -i -e "s/$OLDVERSION/$VERSION/" $MESON

git commit -a -m v$VERSION
git push
git pull
git tag -a v$VERSION -m$VERSION -s
git push origin --tags
git pull

TARBALL=v$VERSION.tar.gz
wget https://github.com/libsixel/libsixel/archive/$TARBALL
gpg --sign --armor --detach-sign $TARBALL
rm $TARBALL

echo "Cut $VERSION, signed to $TARBALL.asc"
# requires token in ~/.netrc
github-release libsixel/libsixel create v$VERSION \
  --name "libsixel v$VERSION" --publish $TARBALL.asc
rm $TARBALL.asc
