#!/bin/sh -e

# This script does all the steps necessary for doing a new upstream release. It
# should solely be used by upstream developers, distributors do not need to
# worry about it.

[ -z "`bzr status | grep -v shelve`" ] || {
    echo "Uncommitted changes, aborting" >&2
    exit 1
}

bzr clean-tree --ignored

version=$(grep '(UNRELEASED)' NEWS | cut -f1 -d' ')
[ -n "$version" ] || {
    echo "no UNRELEASED in NEWS" >&2
    exit 1
}

sed -i -r "s/__version__ = '[0-9.]*'/__version__ = '${version}'/" apport/ui.py
sed -i "s/(UNRELEASED)/$(date '+(%Y-%m-%d)')/" NEWS
bzr commit -m "release $version"
bzr tag "$version"

bzr log -v --log-format 'gnu' > ChangeLog

# temporarily add ChangeLog for export
bzr add ChangeLog
bzr commit -m 'temporarily add changelog'
bzr export ../apport-${version}.tar.gz
bzr uncommit --force
bzr revert --no-backup
rm ChangeLog
