RELEASE_BRANCH_PREFIX="release/"
get_base() {
source="$0"
while [ -h "${source}" ]; do
dir="$( cd -P "$( dirname "${source}" )" && pwd )"
source="$(readlink "${source}")"
done
directory="$( cd "$( dirname "${source}" )/.." && pwd )"
echo "${directory}"
}
BASE="$( get_base )"
build_packages() {
tag="$( git describe --abbrev=0 )"
"${BASE}/tools/build-release-packages.sh" "${tag}"
}
upload_to_crates() {
git -c commit.gpgsign=false stash save --include-untracked
cargo publish
git stash pop
}
upload_releases() {
short_version="$(git describe --abbrev=0 | awk '{split(substr($0,2),s,".");print s[1] "." s[2]}')"
branch="${RELEASE_BRANCH_PREFIX}${short_version}"
old_branch="$(git rev-parse --abbrev-ref HEAD)"
git checkout $(git show-ref --verify --quiet "refs/heads/${branch}" || echo '-b') "${branch}"
git merge master
git push origin "${branch}"
git checkout "${old_branch}"
}
main() {
cd "${base}"
tag="$( git describe --abbrev=0 )"
echo "Please be sure:"
echo "- The changelog has been updated"
echo "- The version bump has been committed to master"
echo "- The release tag (starting with a v) has been created"
echo
read -p "Are you sure do you want to publish tag ${tag}? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
build_packages
upload_to_crates
upload_releases
echo
echo "Remaining manual steps:"
echo " - Draft a new release on GitHub"
else
echo "Aborted."
fi
}
main