#!/bin/bash -eu

set -o pipefail

readonly VERSION=${1:-$(date +%Y.%m.%-d.0)}


cd "$(git rev-parse --show-toplevel)"

# update yt-dlp dependency
ydl_version=$(LANG=C pacman -Qi yt-dlp | grep ^Version | cut -d ':' -f 2 | cut -d '-' -f 1)
sed -i "s/\"yt-dlp>=.*\"/\"yt-dlp>=$ydl_version\"/" pyproject.toml
git add pyproject.toml

# update version
sed -i "s/^\(__version__ = \"\).*\(\"\)/\1$VERSION\2/w /dev/stdout" amg/__init__.py
git add amg/__init__.py

# commit
git commit -m "Version ${VERSION}"

# tag
git tag -m "Version ${VERSION}" "${VERSION}"

# release
rm -Rf dist
uv build
uv publish --username __token__
