#!/bin/bash

python3 -m unittest discover tests/
RESULT=$?

BRANCH=$(git branch --show-current)
if [ $RESULT -ne 0 ]; then
	if [[ "$BRANCH" == "main" ]] && git describe --tags --exact-match >/dev/null 2>&1; then
		echo "Per poter inviare la versione al remote devi passare tutti i test"
		exit 1
	else
		echo "I test sono falliti ma rilevo che questa non è una versione di release. Vuoi procedere comunque col push su main? [y/N]"
		read -r response < /dev/tty
		if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
			echo "Push annullato dall'utente."
			exit 1
		fi
    fi
fi