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

version=$(awk -F '"' '$1 ~ /^version = / { print $2; exit }' Cargo.toml)
tag="v${version}"
dist=dist
checksums="$dist/SHA256SUMS.txt"
notes=$(mktemp)
trap 'rm -f "$notes"' EXIT

[[ -f "$checksums" ]] || { echo "Missing $checksums; run scripts/package-release.sh first." >&2; exit 1; }

cat > "$notes" <<EOF
## Pre-release

First Linux and Windows pre-release of Mudmouth. It includes first-run
EverQuest log discovery, setup, and refreshed development documentation.

## SHA-256

\`\`\`
$(cat "$checksums")
\`\`\`
EOF

for asset in "$dist"/mudmouth-v"$version"-*.tar.gz "$dist"/mudmouth-v"$version"-*.zip "$checksums"; do
  "$HOME/.agents/skills/publish-gitea-release/scripts/gitea-publish-asset.sh" \
    --tag "$tag" \
    --asset "$asset" \
    --title "Mudmouth $tag (pre-release)" \
    --body-file "$notes"
done
