#!/bin/bash
#
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# Copyright (C) 2024 Guillaume Tucker

set -e

major="$1"
minor="$2"
patch="$3"

[ -n "$major" ] && [ -n "$minor" ] && [ -n "$patch" ] || {
    echo "Missing arguments: release-tag MAJOR MINOR PATCH" >&2
    exit 1
}

# 1. Update the version numbers in the code and project.toml
version=$(scripts/upver $@ y)
echo "Version: ${version}"

# 2. Add the new OpenAPI json file
jsonfile=$(openapi/download-json $@)
echo "OpenAPI JSON: ${jsonfile}"

# 3. Generate the Python bindings and frontend client from OpenAPI
openapi/generate-python-bindings "${jsonfile}"
openapi/generate-frontend-client "${jsonfile}"

# 4. Commit
git diff --cached --stat
read -p "Accept? (y/N) " -n1 -r
[[ $REPLY =~ ^[yY]$ ]] || {
    echo "Aborting" >& 2
    exit 1
}
git commit -sm "${version}"
git show --stat

exit 0
