#!/usr/bin/env bash
#MISE description="Build, publish to PyPI, tag and release the current version"
#MISE hide=true

set -euo pipefail

version=$(uv version --short)
tag="v${version}"

if git ls-remote --exit-code --tags origin "refs/tags/${tag}" >/dev/null 2>&1; then
  echo "Tag ${tag} already exists. Skipping publish."
  exit 0
fi

uv build

if [[ "${DRY_RUN:-true}" != "false" ]]; then
  echo "Dry run: built ${tag}; skipping PyPI upload, tag and release."
  ls -l dist/
  exit 0
fi

uv publish
git tag "${tag}"
git push origin "${tag}"
gh release create "${tag}" --title "${tag}" --generate-notes dist/*
