#!/usr/bin/bash -x
# SPDX-FileCopyrightText: 2022 Maxwell G <gotmax@e.email>
# SPDX-License-Identifier: GPL-2.0-or-later

set -euo pipefail

oldversion="${1}"
newversion="${2}"

sed "s|^\(Version: *\)[^ ]*$|\1${newversion}|" -i fedrq.spec

# This is what I came up with at midnight.
python3 /dev/stdin << EOF
import fileinput
import re
import sys

with fileinput.input(["pyproject.toml"], inplace=True) as fi:
    for line in fi:
        sys.stdout.write(
            re.sub(r'^version ?= ?"${oldversion}"', 'version = "${newversion}"', line)
        )
EOF


rpmautospec generate-changelog | vipe > changelog

git add changelog pyproject.toml fedrq.spec
git commit -S -m "Release ${newversion}"
