#!/bin/bash
set -e

echo "🚀 Releasing hyperscan-tokio v0.1.0"

# Ensure we're on master/main
BRANCH=$(git branch --show-current)
if [[ "$BRANCH" != "master" && "$BRANCH" != "main" ]]; then
    echo "❌ Must be on master or main branch to release"
    exit 1
fi

# Ensure working directory is clean
if [[ -n $(git status -s) ]]; then
    echo "❌ Working directory has uncommitted changes"
    exit 1
fi

# Run tests
echo "📋 Running tests..."
cargo test --bin hyperscan-tokio
cargo check --all-features

# Build release
echo "🔨 Building release..."
cargo build --release

# Tag the release
echo "🏷️  Creating git tag v0.1.0..."
git tag -a v0.1.0 -m "Release v0.1.0

Initial release of hyperscan-tokio - High-performance async regex scanning for Rust

Features:
- Async-first API with Tokio integration
- 20+ GB/s throughput with SIMD optimizations
- Block, stream, and vectored scanning modes
- Chimera support (PCRE with capture groups)
- Memory-safe FFI wrappers
- Worker pools with CPU affinity
- Database caching and hot-reload
- Zero-copy operations with bytes integration

See CHANGELOG.md for details."

echo "📦 Ready to publish!"
echo ""
echo "Next steps:"
echo "1. Push tag: git push origin v0.1.0"
echo "2. Publish sys crate: cd hyperscan-tokio-sys && cargo publish"
echo "3. Wait 30 seconds for crates.io to update"
echo "4. Publish main crate: cargo publish"
echo "5. Create GitHub release at https://github.com/mikeyasaservice/hyperscan-tokio/releases/new"
echo ""
echo "Release announcement template:"
echo "---"
echo "🎉 hyperscan-tokio v0.1.0 is now available!"
echo ""
echo "High-performance async regex scanning for Rust, powered by VectorScan."
echo ""
echo "✨ Highlights:"
echo "• 20+ GB/s throughput"
echo "• Async-first with Tokio"
echo "• Memory-safe FFI"
echo "• PCRE support via Chimera"
echo ""
echo "📦 crates.io: https://crates.io/crates/hyperscan-tokio"
echo "📚 docs.rs: https://docs.rs/hyperscan-tokio"
echo "🐙 GitHub: https://github.com/mikeyasaservice/hyperscan-tokio"