1#!/bin/bash
2
3set -eu
4
5if [[ $# < 3 ]]; then
6 echo "Missing version increment (major, minor, or patch)" >&2
7 exit 1
8fi
9
10package=$1
11tag_prefix=$2
12version_increment=$3
13
14if [[ -n $(git status --short --untracked-files=no) ]]; then
15 echo "Can't push a new version with uncommitted changes"
16 exit 1
17fi
18
19which cargo-set-version > /dev/null || cargo install cargo-edit
20cargo set-version --package $package --bump $version_increment
21cargo check --quiet
22
23new_version=$(cargo metadata --no-deps --format-version=1 | jq --raw-output ".packages[] | select(.name == \"${package}\") | .version")
24branch_name=$(git rev-parse --abbrev-ref HEAD)
25old_sha=$(git rev-parse HEAD)
26tag_name=${tag_prefix}${new_version}
27
28git commit --quiet --all --message "${package} ${new_version}"
29git tag ${tag_name}
30
31cat <<MESSAGE
32Committed and tagged ${package} version ${new_version}
33
34To push this:
35 git push origin ${tag_name} ${branch_name}
36
37To undo this:
38 git tag -d ${tag_name} && git reset --hard $old_sha
39MESSAGE