@echo off
cls
setlocal

rem Name of git tag.
set TAG_NAME="v%DATE:-=.%"

rem Remove old local tag.
call git tag -d "%TAG_NAME%" 2>nul

rem Remove old remote tag.
call git push origin --delete "%TAG_NAME%" 2>nul

rem Prepare a release without push remote tag and changes.
call mvn release:prepare -DremoteTagging=false -DpushChanges=false
if "%ERRORLEVEL%" neq 0 goto ExitOnError

rem Push remote tag and changes.
call git commit -a -m "Prepare a release"
if "%ERRORLEVEL%" neq 0 goto ExitOnError

call git tag "%TAG_NAME%"
if "%ERRORLEVEL%" neq 0 goto ExitOnError

call git push
if "%ERRORLEVEL%" neq 0 goto ExitOnError

call git push --tags
if "%ERRORLEVEL%" neq 0 goto ExitOnError

call git push origin
if "%ERRORLEVEL%" neq 0 goto ExitOnError

rem Perform a release.
call mvn release:perform
if "%ERRORLEVEL%" neq 0 goto ExitOnError

endlocal

rem This is a label for GOTO.
:ExitOnError
echo "************************************ BEGIN RESTORE *************************************"
call mvn release:rollback
call mvn release:clean
echo "************************************* END RESTORE **************************************"
exit 1
rem end of file