@ECHO OFF

DEL Twilight.jar

CALL gradlew buildFatJar
Robocopy build\libs . Twilight.jar

CHOICE /M TEST
SET TEST=%ERRORLEVEL%
IF %TEST% == 1 (
	CALL gradlew test
)
IF %TEST% == 1 (
	IF NOT %ERRORLEVEL% == 0  (
		PAUSE
	)
)
IF %TEST% == 1 (
	wsl java -jar Twilight.jar --test
)

CHOICE /M PATCH
IF %ERRORLEVEL% == 1 (
	Robocopy . \\taehui\taehui Twilight.jar

	wsl ssh taehui@taehui sudo service twilight stop
	timeout 5
	wsl ssh taehui@taehui sudo cp Twilight.jar /var/twilight/Twilight.jar
	wsl ssh taehui@taehui sudo service twilight start
	
	wsl ssh taehui@taehui rm -r Twilight.jar
)

CHOICE /M VCS
IF %ERRORLEVEL% == 1 (
	git add *
	git commit -m v1.0-SNAPSHOT
	git checkout master
	git merge develop
	git push
	git checkout develop
	git push
)