#!/bin/bash

# [description]
#
#   Bump the version and create a PR.
#
# [usage]
#
#   bin/create-release-pr '4.0.0'
#

set -Eeuo pipefail

NEW_VERSION="${1}"

sed \
    -i=.bak \
    "/^__version/ s|.*|__version__ = \"${NEW_VERSION}\"|g" \
    ./src/pydistcheck/__init__.py

rm -f ./src/pydistcheck/*.bak

VERSION=$(
    cat ./src/pydistcheck/__init__.py |
        grep -E '^__version' |
        cut -d '=' -f2 |
        tr -d ' "'
)

git checkout -b "release/v${VERSION}"
git add ./src/pydistcheck/__init__.py

commit_msg="release v${VERSION}"
git commit -m "${commit_msg}"
git push origin "release/v${VERSION}"

gh pr create \
    --repo jameslamb/pydistcheck \
    --base 'main' \
    --label 'maintenance' \
    --title "${commit_msg}" \
    --body "${commit_msg}"
