# Set the Cargo.toml version, commit it, and tag the commit with that version.
# Usage: just tag 1.2.3
tag ver:
    #!/usr/bin/env bash
    set -euo pipefail

    # Validate the version argument.
    if [[ ! "{{ver}}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
        echo "error: version must be in the form X.Y.Z (got '{{ver}}')" >&2
        exit 1
    fi

    # Bump the version in Cargo.toml.
    sed -i -E "s/^version = \".*\"/version = \"{{ver}}\"/" Cargo.toml

    # Regenerate Cargo.lock so it reflects the new version.
    cargo build

    # Stage, commit, and tag.
    git add Cargo.toml Cargo.lock
    git commit -m "version {{ver}} [skip ci]"
    git tag "{{ver}}"
    git push
    git push --tags

# Run the Rust unit tests.
# Usage: just test
test:
    cargo test --all

# Format the Rust code.
# Usage: just fmt
fmt:
    cargo fmt --all

# Run the end-to-end Playwright tests.
# Usage: just e2e
e2e:
    cd e2e && npm test
