-
Notifications
You must be signed in to change notification settings - Fork 0
/
goaleaf-releaser-2.2.cmd
233 lines (175 loc) · 6.37 KB
/
goaleaf-releaser-2.2.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
@ECHO OFF
set RELEASER_VERSION=2.2
rem ==================================== Configuration ==================================================
set GIT="C:\Program Files\Git\bin\git.exe"
set MVN="C:\opt\apache-maven-3.6.1\bin\mvn.cmd"
set JAVA="C:\Program Files\Java\jdk1.8.0_192"
set MAIN_DIRECTORY=%CD%
set WORKSPACE_DIRECTORY=%MAIN_DIRECTORY%\workspace
set RELEASE_DIRECTORY=%MAIN_DIRECTORY%\distribution
rem ===================================== Check these variables before releasing ========================
rem Repository link
set REPOSITORY=https://github.com/Pplociennik/GoaLeaf.git
rem glf-api repository link
set API_REPOSITORY=https://github.com/Pplociennik/glf-api.git
rem Repository name
set REPOSITORY_NAME=GoaLeaf
rem API Repository name
set API_REPOSITORY_NAME=glf-api
rem This is the branch we are working on
set DEVELOP_BRANCH=develop
rem This is the branch where releases are stored
set RELEASE_BRANCH=develop
rem ------------------------------------------------------------------------------------------------------
rem This is last stable released version
set LAST_STABLE_VERSION=0.8.0
rem This is the version that will be released
set RELEASED_VERSION=0.8.2
rem This is the version that will be pushed on develop branch
set NEXT_VERSION=0.9.0
rem =============================================== PHASE 1 ========================================================
call :log Starting Goaleaf Releaser v.%RELEASER_VERSION%
echo You are going to release Goaleaf server version:
echo last : %LAST_STABLE_VERSION%
echo released : %RELEASED_VERSION%
echo next : %NEXT_VERSION%
set /p VERSIONS_CONFIRM="Would you like to begin release process? y/n : "
IF "%VERSIONS_CONFIRM%" EQU "y" (
ECHO Starting...
) ELSE (
goto :eof
)
call :prepareWorkspace
call :changeDirectory %WORKSPACE_DIRECTORY% || goto :error
call :log Starting executing phase 1
call :clone
call :changeDirectory "%WORKSPACE_DIRECTORY%\%REPOSITORY_NAME%\Server"
call :build
call :buildPackage
call :log Finished executing phase 1
set /p DEPLOY_CONFIRM="Distribution package built. Are you sure you want to make a release? y/n : "
IF "%DEPLOY_CONFIRM%" EQU "n" (
call :log Release process aborted...
call :error GOALEAF RELEASE FAILURE
exit /b 1
)
rem =============================================== PHASE 2 ========================================================
call :log Starting executing phase 2
call :prepareReleaseRepository
call :deploy
call :log Finished executing phase 2
set /p PUSH_CONFIRM="[GSA Deploy Success] Goaleaf Server Application deployed! Would you like to push release and snapshot versions to github? y/n : "
IF "%PUSH_CONFIRM%" EQU "n" (
call :log Release process aborted...
call :error GOALEAF RELEASE FAILURE
exit /b 1
)
rem =============================================== PHASE 3 =========================================================
call :log Starting executing phase 3
call :pushRelease
call :pushDevelop
call :log Finished executing phase 3
call :log GOALEAF RELEASE SUCCESS
exit /b 0
rem ========================================================================================================
:prepareWorkspace
IF EXIST %WORKSPACE_DIRECTORY% (
call :cleanWorkspace
)
call :log Creating workspace directory
mkdir workspace || goto :error
goto :eof
:prepareReleaseRepository
IF EXIST %RELEASE_DIRECTORY% (
rmdir /s /q %RELEASE_DIRECTORY% || goto :error
call :log Removed repository directory
)
mkdir %RELEASE_DIRECTORY% || goto :error
call :log Created release directory
call :changeDirectory %RELEASE_DIRECTORY%
%GIT% clone %API_REPOSITORY% || goto :error
call :changeDirectory "%RELEASE_DIRECTORY%\%API_REPOSITORY_NAME%"
del /S /Q *.* || goto :error
%GIT% init || goto :error
%GIT% remote add origin %API_REPOSITORY% || goto :error
%GIT% pull origin master || goto :error
call :changeDirectory "%WORKSPACE_DIRECTORY%\%REPOSITORY_NAME%\Server"
xcopy /S /Y *.* "%RELEASE_DIRECTORY%\%API_REPOSITORY_NAME%"
call :log Release directory prepared!
goto :eof
:cleanWorkspace
call :log Cleaning workspace directory
rmdir /s /q workspace || goto :error
goto :eof
:clone
call :log Cloning repository %REPOSITORY%
%GIT% clone %REPOSITORY% || goto :error
call :log Finished cloning repository %REPOSITORY%
call :changeDirectory "%WORKSPACE_DIRECTORY%\%REPOSITORY_NAME%"
call :log Checking out branch %DEVELOP_BRANCH%...
%GIT% checkout %DEVELOP_BRANCH% || goto :error
call :log Updating repository
%GIT% pull || goto :error
goto :eof
:build
call :log Building goaleaf server project
call :changeVersion %RELEASED_VERSION%
%MVN% clean install || goto :error
call :log Finished building goaleaf server project
goto :eof
:buildPackage
call :log Building goaleaf server distribution package
%MVN% clean package || goto :error
call :log Finished building server distribution package
goto :eof
:deploy
call :log Starting goaleaf server deploy.
call :changeDirectory "%RELEASE_DIRECTORY%\%API_REPOSITORY_NAME%"
%GIT% add . || goto :error
%GIT% commit -m "Release %RELEASED_VERSION%" || goto :error
%GIT% push origin master || goto :error
call :log Goaleaf API v.%RELEASED_VERSION% release success!
call :createTag %RELEASED_VERSION%
goto :eof
:createTag
call :log Creating tag %1...
%GIT% tag -a %1 -m "%1" || goto :error
%GIT% push origin %1 || goto :error
call :log Finished creating tags
goto :eof
:pushRelease
call :changeDirectory "%WORKSPACE_DIRECTORY%\%REPOSITORY_NAME%\Server"
call :log Pushing goaleaf server release version to repository.
%GIT% add . || goto :error
%GIT% commit -a -m "Release %RELEASED_VERSION%" || goto :error
%GIT% push || goto :error
call :log Pushed goaleaf server release version to repository
goto :eof
:pushDevelop
call :changeDirectory "%WORKSPACE_DIRECTORY%\%REPOSITORY_NAME%\Server"
call :log Pushing development version to repository.
call :changeVersion %NEXT_VERSION%-SNAPSHOT
%GIT% add . || goto :error
%GIT% commit -a -m "Next version is %NEXT_VERSION%"
%GIT% push || goto :error
call :log Pushed development version to repository
goto :eof
:changeVersion
call :log Changing project version to %1
%MVN% versions:set -DnewVersion=%1 -DgenerateBackupPoms=false || goto :error
call :log Changed project version to %1
goto :eof
:changeDirectory
popd
call :log Changing directory to %1
pushd "%1" || goto :error
call :log Changed directory to %CD%
goto :eof
:error
IF %ERRORLEVEL% NEQ 0 (
echo [ERROR] Goaleaf Releaser failed with error #%ERRORLEVEL%
)
exit /b 1
:log
echo [RELEASER] %* || goto :error
goto :eof