#!/bin/sh
# release-dist.sh - thin wrapper around the shared multi-arch release tool.
#
# The real cross-target build + dist publish lives in scorpiox-cli-botplugin
# (it owns the musl / aarch64 / MinGW / macOS toolchains and the plugingit
# mirror). This script only exists so the repo can be released the same way
# every other oss plugin is, and so a stale release-dist keeps failing loudly
# instead of shipping a 3-target manifest that says "release complete".
#
#   ./release-dist.sh                 # build + publish version from plugin.json / 1.0.0
#   VERSION=1.0.1 ./release-dist.sh   # explicit version
#
# Run it on the build host that has musl-gcc, aarch64-linux-gnu-gcc,
# x86_64-w64-mingw32-gcc and ssh access to the macOS builder.

set -eu

SLUG=files
VERSION="${VERSION:-1.0.0}"
PLUGINGIT_TOKEN_FILE="${PLUGINGIT_TOKEN_FILE:-/etc/scorpiox-plugingit.token}"

ROOT=$(cd "$(dirname "$0")" && pwd)

if ! command -v scorpiox-cli-botplugin >/dev/null 2>&1; then
    echo "scorpiox-cli-botplugin not found on PATH" >&2
    exit 1
fi

echo "==> publish $SLUG $VERSION"
scorpiox-cli-botplugin publish "$ROOT" \
    --slug "$SLUG" \
    --version "$VERSION" \
    --macos-host "${MACOS_HOST:-yongchen@macos-builder}" \
    --json

echo "==> verify target count in the published manifest"
scorpiox-cli-botplugin reindex --json >/dev/null 2>&1 || true
echo "check dist/bot-plugins/$SLUG/$VERSION/manifest.json has 6 targets before calling it done"
