1
1
#! /bin/bash
2
2
3
3
# WordPress SSH Git CI Script
4
- # v1.1.0
4
+ # v1.0.2
5
5
6
6
# Set argument parameters on start
7
7
BRANCH=live
8
8
DEVBRANCH=dev
9
9
STAGEBRANCH=stage
10
10
PROJDIR=wordpress
11
- SOFTERROR=0
12
11
ERRORMESSAGES=" "
12
+ TRACKEDONLY=" false"
13
+ COMMIT=" true"
13
14
while : ; do
14
15
case " $1 " in
15
16
@@ -22,11 +23,11 @@ while :; do
22
23
fi
23
24
;;
24
25
-c|--commit) # optional -- default value is true
25
- if [[ $2 ]] && [[ $2 = " no" || $2 = " n" ]] ; then
26
- COMMIT=0
26
+ if [[ $2 = " no" || $2 = " n" ]] ; then
27
+ COMMIT=" false "
27
28
shift
28
29
else
29
- COMMIT=1
30
+ COMMIT=" true "
30
31
shift
31
32
fi
32
33
;;
@@ -87,7 +88,7 @@ while :; do
87
88
fi
88
89
;;
89
90
-se|--softerror) # optional
90
- SOFTERROR=1
91
+ SOFTERROR=" true "
91
92
shift
92
93
;;
93
94
-t|--token) # semi-optional -- if empty ORIGIN string is required
@@ -98,6 +99,10 @@ while :; do
98
99
ERRORMESSAGES=" ERROR: '-t | --token' requires a non-empty option argument."
99
100
fi
100
101
;;
102
+ -tr|--tracked) # optional
103
+ TRACKEDONLY=" true"
104
+ shift
105
+ ;;
101
106
-u|--tokenuser) # semi-optional -- if empty ORIGIN string is required
102
107
if [[ $2 ]]; then
103
108
TOKENUSER=$2
@@ -135,17 +140,17 @@ add_or_remove_devops() {
135
140
output=$( git remote )
136
141
case $output in
137
142
* +devops* )
138
- remoteAdded=1 ;;
143
+ remoteAdded=" true " ;;
139
144
* )
140
- remoteAdded=0 ;;
145
+ remoteAdded=" false " ;;
141
146
esac
142
147
case $1 in
143
148
add)
144
- if [ $remoteAdded -eq 0 ] ; then
149
+ if [ $remoteAdded == " false " ] ; then
145
150
add_devops_remote
146
151
fi ;;
147
152
rm)
148
- if [ $remoteAdded -eq 0 ] ; then
153
+ if [ $remoteAdded == " true " ] ; then
149
154
rm_devops_remote
150
155
fi ;;
151
156
esac
@@ -182,7 +187,7 @@ is_stashes() {
182
187
183
188
git_stash () {
184
189
is_stashes " check"
185
- if [[ $stashes -eq 1 ]] ; then
190
+ if [[ $stashes == " true " ]] ; then
186
191
case $1 in
187
192
clear)
188
193
git stash clear 2>&1 ;;
@@ -200,7 +205,7 @@ git_stash() {
200
205
# # Committing changes
201
206
202
207
commit_git () {
203
- if [[ $COMMIT -eq 1 ]] ; then
208
+ if [[ $COMMIT == " commit " ]] ; then
204
209
git add -A . 2>&1
205
210
git commit -m " $MESSAGE " 2>&1
206
211
print_status_msg " Commited on $BRANCH with message:
@@ -212,9 +217,22 @@ commit_git() {
212
217
213
218
# # Pull branch from remote
214
219
220
+ create_or_rm_branch () {
221
+ case $1 in
222
+ add)
223
+ if [[ $remoteAdded == " true" ]] ; then
224
+ add_devops_remote
225
+ fi ;;
226
+ rm)
227
+ if [[ $remoteAdded == " true" ]] ; then
228
+ rm_devops_remote
229
+ fi ;;
230
+ esac
231
+ }
232
+
215
233
pull_branch () {
216
234
msg=" Pull branch "
217
- if [ -z " $2 " ] ; then
235
+ if [[ -z $2 ] ] ; then
218
236
git pull " $1 " 2>&1
219
237
msg=$msg $1
220
238
else
@@ -260,7 +278,7 @@ set_defaults() {
260
278
throw_errors
261
279
262
280
# Set origin url to use
263
- if [ -z " $ORIGIN " ] ; then
281
+ if [[ -z $ORIGIN ] ] ; then
264
282
# if origin isn't set and the other arguments needed to make an origin aren't set, throw an error!
265
283
if [[ -z $TOKENUSER || -z $TOKEN || -z $GITREPO ]] ; then
266
284
error3
@@ -276,8 +294,14 @@ set_defaults() {
276
294
fi
277
295
278
296
# Set if branch has changes; and if so, how to handle those changes
279
- if output=$( git status --untracked-files=no --porcelain) && [ -z " $output " ] ; then
280
- DIRTYBRANCH=0
297
+ if [[ $TRACKEDONLY == " true" ]] ; then
298
+ output=$( git status --untracked-files=no --porcelain)
299
+ else
300
+ output=$( git status --porcelain)
301
+ fi
302
+
303
+ if [ -z " $output " ] ; then
304
+ DIRTYBRANCH=" false"
281
305
else
282
306
if [[ $ONCHANGE = " Stop" || $ONCHANGE = " stop" ]] ; then
283
307
error3
@@ -287,7 +311,7 @@ set_defaults() {
287
311
error3
288
312
else
289
313
ONCHANGE=" commit"
290
- DIRTYBRANCH=1
314
+ DIRTYBRANCH=" true "
291
315
fi
292
316
fi
293
317
fi
@@ -296,6 +320,7 @@ set_defaults() {
296
320
# Method models
297
321
298
322
get_new_release () {
323
+ print_status_msg " Getting latest release now"
299
324
# Checkout staging release branch
300
325
checkout_branch " $STAGEBRANCH "
301
326
@@ -314,25 +339,27 @@ get_new_release() {
314
339
315
340
clean_repository () {
316
341
# Stash changes
342
+ print_status_msg " Stashing changes"
317
343
git_stash " clear"
318
344
git_stash " u"
319
345
320
346
# Get latest release from Azure DevOps
321
347
get_new_release
322
348
323
349
# Add changes back
350
+ print_status_msg " Finished updating, adding changes back"
324
351
git_stash " pop"
325
352
326
353
# If soft error isn't enabled, add files and commit them
327
- if [ $SOFTERROR -eq 0 ] ; then
354
+ if [ $SOFTERROR == " false " ] ; then
328
355
commit_git
356
+ # Push changes back to dev branch
357
+ push_branch " devops" " $DEVBRANCH "
329
358
else
330
359
print_error_msg " Changes on server, soft error selected. Release is pulled, changes are popped back, branch is waiting user intervention."
331
360
error3
332
361
fi
333
362
334
- # Push changes back to dev branch
335
- push_branch " devops" " $DEVBRANCH "
336
363
337
364
print_status_msg " Changes on the WordPress site have been commited, and were pushed to $DEVBRANCH branch"
338
365
}
@@ -363,7 +390,7 @@ add_or_remove_devops "add"
363
390
364
391
# Option selected to just query for changes
365
392
366
- if [ $DIRTYBRANCH -eq 0 ] ; then
393
+ if [[ $DIRTYBRANCH == " true " ] ] ; then
367
394
# Working directory clean
368
395
print_status_msg " Working directory clean"
369
396
get_new_release
0 commit comments