2026-12-01 11:13:02 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# Computes and applies the next version according to the public API (see api-level.sh):
|
|
|
|
|
# break -> x.y+1.0 while x = 0, otherwise x+1.0.0
|
|
|
|
|
# additions -> x.y+1.0 once x >= 1 (SemVer: new feature), x.y.z+1 while x = 0
|
|
|
|
|
# otherwise -> x.y.z+1
|
2026-12-02 14:11:41 +01:00
|
|
|
# RELEASE=x.y.z forces the version. Updates Cargo.toml, version.txt and the dependency
|
|
|
|
|
# lines of README.md (`<crate> = "x.y"` or `<crate> = { version = "x.y", ... }`) when they exist.
|
2026-12-01 11:13:02 +01:00
|
|
|
set -euo pipefail
|
|
|
|
|
. "$(dirname "$0")/common.sh"
|
|
|
|
|
|
|
|
|
|
warn "→ Computing the next version..."
|
|
|
|
|
current=$(current_version)
|
|
|
|
|
name=$(crate_name)
|
|
|
|
|
info " Current version: $current"
|
|
|
|
|
IFS=. read -r major minor patch <<<"$current"
|
|
|
|
|
|
|
|
|
|
if [ -n "${RELEASE:-}" ]; then
|
|
|
|
|
new_version="$RELEASE"
|
|
|
|
|
else
|
|
|
|
|
level=$("$(dirname "$0")/api-level.sh")
|
|
|
|
|
case "$level" in
|
|
|
|
|
breaking)
|
|
|
|
|
if [ "$major" = "0" ]; then
|
|
|
|
|
new_version="0.$((minor + 1)).0"
|
|
|
|
|
else
|
|
|
|
|
new_version="$((major + 1)).0.0"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
additive)
|
|
|
|
|
if [ "$major" = "0" ]; then
|
|
|
|
|
new_version="0.$minor.$((patch + 1))"
|
|
|
|
|
else
|
|
|
|
|
new_version="$major.$((minor + 1)).0"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
initial | unchanged)
|
|
|
|
|
new_version="$major.$minor.$((patch + 1))"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
err "✗ unexpected API verdict: '$level'"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# No silent jump to another version: a break must never be downgraded.
|
|
|
|
|
rc=0
|
|
|
|
|
"$(dirname "$0")/tag-exists.sh" "$new_version" || rc=$?
|
|
|
|
|
case "$rc" in
|
|
|
|
|
0)
|
|
|
|
|
err "✗ The release version-$new_version already exists (locally or on the server)"
|
|
|
|
|
info " Use RELEASE=x.y.z to force another version"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
1) ;;
|
|
|
|
|
*) warn " (remote tags not checked: no jj repository or origin unreachable)" ;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
info " New version: $new_version"
|
|
|
|
|
sed -i.bak "s/^version = \"$current\"/version = \"$new_version\"/" "$CARGO_TOML"
|
|
|
|
|
rm "$CARGO_TOML.bak"
|
|
|
|
|
[ -f version.txt ] && echo "$new_version" >version.txt
|
|
|
|
|
if [ -f README.md ]; then
|
2026-12-02 14:11:41 +01:00
|
|
|
short=$(echo "$new_version" | cut -d. -f1,2)
|
|
|
|
|
sed -E -i.bak \
|
|
|
|
|
-e "s/^(${name}[[:space:]]*=[[:space:]]*\")[0-9][0-9.]*\"/\1$short\"/" \
|
|
|
|
|
-e "s/^(${name}[[:space:]]*=[[:space:]]*\{([^}]*[ ,])?version[[:space:]]*=[[:space:]]*\")[0-9][0-9.]*\"/\1$short\"/" \
|
|
|
|
|
README.md
|
2026-12-01 11:13:02 +01:00
|
|
|
rm README.md.bak
|
|
|
|
|
fi
|
|
|
|
|
ok "✓ Version $new_version written to $CARGO_TOML (and version.txt, README.md if they exist)"
|