publish:
    #!/usr/bin/env bash
    set -euo pipefail

    macro_pkg='betex-macros'
    root_pkg='betex'
    macro_version="$(cargo pkgid -p "${macro_pkg}" | sed -E 's/.*#//')"

    cargo publish --locked -p "${macro_pkg}"

    echo "Waiting for ${macro_pkg} ${macro_version} to become available in the registry..."
    for attempt in {1..60}; do
      if cargo info "${macro_pkg}@${macro_version}" >/dev/null 2>&1; then
        cargo publish --locked -p "${root_pkg}"
        exit 0
      fi

      sleep 5
    done

    echo "Timed out waiting for ${macro_pkg} ${macro_version} to appear in the registry." >&2
    exit 1
