bump-version.sh

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