#!/bin/bash
set -e

cd "$(dirname "$0")"

if [ -z "$1" ]; then
  echo "Usage: ./release.sh <version>"
  echo "Example: ./release.sh 0.1.0"
  exit 1
fi

VERSION=$1

if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  echo "Error: Version must be in format 0.0.0"
  exit 1
fi

echo "Releasing squirreldb-sdk v${VERSION}..."

# Update version in Cargo.toml
sed -i '' "s/^version = \".*\"/version = \"${VERSION}\"/" Cargo.toml

echo "Running tests..."
cargo test

echo "Building..."
cargo build --release

echo "Publishing to crates.io..."
cargo publish --allow-dirty

echo "Released squirreldb-sdk@${VERSION}"
echo ""
echo "Users can install with:"
echo "  cargo add squirreldb-sdk"
