#!/usr/bin/env sh
set -e

# Format Rust code
cargo fmt --all

# Stage any formatting changes
git diff --name-only | grep '\.rs$' | xargs -r git add

# Clippy lint check
cargo clippy --all-targets --all-features -- -D warnings

# Check GitHub workflows if changed
if git diff --cached --name-only | grep -q '^\.github/workflows/'; then
  if ! command -v actionlint &> /dev/null; then
    echo "actionlint not found. Install: brew install actionlint (macOS) or go install github.com/rhysd/actionlint/cmd/actionlint@latest"
    exit 1
  fi
  actionlint
fi
