#!/usr/bin/env bash
#
# This script should be run from the root of the repository.
set -ex

# Zip up all the binaries to reduce the download size. DEBs and RPMs
# aren't included to be easier to work with.
find dist/ -type f \
  -name 'alloy*' -not -name '*.deb' -not -name '*.rpm' -not -name 'alloy-installer-windows-*.exe' \
  -exec zip -j -m "{}.zip" "{}" \;

# For the Windows installer only, we want to keep the original .exe file and create a zipped copy.
find dist/ -type f \
  -name 'alloy-installer-windows-*.exe' \
  -exec zip -j "{}.zip" "{}" \;

# Get the SHA256SUMS before continuing.
pushd dist && sha256sum -- * > SHA256SUMS && popd || exit

ghr \
  -t "${GITHUB_TOKEN}" \
  -u "grafana" \
  -r "alloy" \
  -b="$(envsubst < ./tools/release-note.md)" \
  -delete -draft \
  "${VERSION}" ./dist/
