hex/scripts/set-crate-version.sh
Dax Raad 34d6d89068 ci(macos): staging builds stamp and report their X.Y.Z-dev.N prerelease
release-app.sh stamps the published prerelease into the crate after its
clean-tree check, build numbers come from the X.Y.Z core, build-macos.yml
accepts a -dev.N/-beta.N prerelease of the Cargo version, and
set-crate-version.sh uses awk instead of GNU sed's 0,/re/ so it runs on the
macOS runner.
2026-10-24 12:06:18 -04:00

35 lines
1.4 KiB
Shell
Executable file

#!/bin/sh
# Stamps a prerelease of the checked-out version into Cargo.toml and
# Cargo.lock, so a staging build reports the version the release service
# publishes (X.Y.Z-dev.N or X.Y.Z-beta.N). Release builds only; the change is
# never committed.
#
# set-crate-version.sh <source root> <version>
set -eu
root=$1
version=$2
current=$(sed -n 's/^version = "\([^"]*\)"/\1/p' "$root/Cargo.toml" | head -1)
[ "$version" = "$current" ] && exit 0
case "$version" in
"$current"-dev.[0-9]* | "$current"-beta.[0-9]*) ;;
*)
echo "Can only stamp a prerelease of $current, not $version." >&2
exit 1
;;
esac
printf '%s\n' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+-(dev|beta)\.[0-9]+$'
# awk, not sed's GNU-only 0,/re/ address: this also runs on the macOS runner.
awk -v current="$current" -v version="$version" '
!done && $0 == "version = \"" current "\"" { $0 = "version = \"" version "\""; done = 1 }
{ print }
' "$root/Cargo.toml" > "$root/Cargo.toml.next"
mv "$root/Cargo.toml.next" "$root/Cargo.toml"
awk -v current="$current" -v version="$version" '
/^name = "voice-control"$/ { package = 1 }
package && $0 == "version = \"" current "\"" { $0 = "version = \"" version "\""; package = 0 }
{ print }
' "$root/Cargo.lock" > "$root/Cargo.lock.next"
mv "$root/Cargo.lock.next" "$root/Cargo.lock"
grep -q "^version = \"$version\"" "$root/Cargo.toml"
echo "Building Hex as $version." >&2