#!/usr/bin/env bash
#MISE description="Bump the version in moon.mod to match the computed release version"
#MISE depends=["release:version"]
set -euo pipefail

VERSION=$(mise run release:version 2>/dev/null | tail -1)

# Update the `version = "..."` field in moon.mod. `sed -i.bak` works with both
# GNU sed and BSD sed; the backup file is removed afterwards.
sed -i.bak -E "s/^version = \"[^\"]*\"/version = \"${VERSION}\"/" moon.mod
rm -f moon.mod.bak

if ! grep -q "^version = \"${VERSION}\"$" moon.mod; then
  echo "Error: could not set version ${VERSION} in moon.mod" >&2
  exit 1
fi

echo "Bumped moon.mod version to $VERSION"
