#!/usr/bin/env bash -e usage() { cat <&2 } # shellcheck disable=2044 # Disable 'For loops over find output are fragile...' Cargo_tomls="$(find . -name Cargo.toml)" # Collect the name of all the internal crates crates=() for Cargo_toml in $Cargo_tomls; do crates+=("$(readCargoVariable name "$Cargo_toml")") done # Read the current version MAJOR=0 MINOR=0 PATCH=0 SPECIAL="" semverParseInto "$(readCargoVariable version ./Cargo.toml)" MAJOR MINOR PATCH SPECIAL [[ -n $MAJOR ]] || usage currentVersion="$MAJOR.$MINOR.$PATCH$SPECIAL" SPECIAL="" # Figure out what to increment case ${1:-minor} in patch) PATCH=$((PATCH + 1)) ;; major) MAJOR=$((MAJOR+ 1)) ;; minor) MINOR=$((MINOR+ 1)) ;; -*) if [[ $1 =~ ^-[A-Za-z0-9]*$ ]]; then SPECIAL="$1" else echo "Error: Unsupported characters found in $1" exit 1 fi ;; *) echo "Error: unknown argument: $1" usage ;; esac newVersion="$MAJOR.$MINOR.$PATCH$SPECIAL" # Update all the Cargo.toml files for Cargo_toml in $Cargo_tomls; do # Set new crate version ( set -x sed -i "$Cargo_toml" -e "s/^version = \"[^\"]*\"$/version = \"$newVersion\"/" ) # Fix up the version references to other internal crates for crate in "${crates[@]}"; do ( set -x sed -i "$Cargo_toml" -e " s/^$crate = .*path = \"\([^\"]*\)\".*\$/$crate = \{ path = \"\1\", version = \"$newVersion\" \}/ " ) done done echo "$currentVersion -> $newVersion" exit 0