#!/bin/bash
set -euo pipefail

. $(dirname $0)/functions.sh

setup() {
    git checkout main
    git pull
    VERSION=$(get_version)
}

create_tag() {
    if ! confirm "Create tag $VERSION?" ; then
        exit 1
    fi
    git tag -a $VERSION -m "Releasing version $VERSION"
}

publish() {
    git push origin $VERSION:$VERSION
    cargo publish
    glab release create $VERSION -F .changes/$VERSION.md
    glab release upload $VERSION artifacts/*.gz
}

cd $(dirname "$0")/..

setup
create_tag
ci/build-app
ci/create-archive
publish
