-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushschema
204 lines (181 loc) · 7.3 KB
/
pushschema
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
#!/bin/bash
HERE=$(dirname ${BASH_SOURCE[0]})
. ${HERE}/fixpath
if ! checkDANKEY ; then
exit 1
fi
if [ $# = 0 ] ; then
echo Usage: $0 targetbranch
exit 1
fi
runsdu=$( arg after -runsdu $@ )
subfolder=dev
prunedargs=()
prev_runsdu=false
lastarg=
for arg ; do
if [ "$lastarg" = "--evalschemasubfolder" ] ; then
subfolder=$arg
elif [ "$arg" != "--evalschemasubfolder" ] ; then
if [ "$arg" == "-runsdu" ]; then
prev_runsdu=true
elif [ "$prev_runsdu" == true ]; then
prev_runsdu=false
else
prunedargs+=($arg)
fi
fi
lastarg="$arg"
done
aborted=notaborted
viewer=$(logviewer)
preparebranchforpullrequestlogfile=/tmp/preparebranchesforpullrequest$$.txt
preparebranchforpullrequestlogfilefolder=$(dirname $preparebranchforpullrequestlogfile)
preparebranchforpullrequestlogfileleaf=$(basename $preparebranchforpullrequestlogfile)
if [ $aborted != aborted ] ; then
# For each schema repo,
# Generate a safe branch off the target and merge into it, only to test the merge will have no conflicts
echo "Testing for conflicts and pushing local branches to origin ... "
evalschema.sh --evalschemasubfolder $subfolder 'yes | preparebranchforpullrequest.sh '"${prunedargs[@]}" > ${preparebranchforpullrequestlogfile} 2>&1
needcapitalY=dontNeedCaptialY
if grep CONFLICT ${preparebranchforpullrequestlogfile} ; then
echo '**** ' "Warning: suspected conflict: piping yes will no longer work. Must use Y below to proceed."
echo
echo '*********************************************************'
echo "Before typing Y, you should "
echo " 1. Resolve your conflicts"
echo " 2. Commit your changes to the current temporary branches "
echo '*********************************************************'
echo
needcapitalY=needcapitalY
else
echo "No conflicts found."
fi
yes=y
if [ "$needcapitalY" = needcapitalY ] ; then
yes=Y
fi
okay=nothingyet
while [ $okay = nothingyet ] ; do
echo
echo "Please check ${preparebranchforpullrequestlogfile} and let me know if okay to createpullrequest (create pull requests) ..."
echo "(Provide the name of a viewer here if you want me to view logs with that in future. Default viewer is ${viewer})"
echo
echo -n "[ ${yes} (yes) / n (abort) / v (view using ${viewer}) ] "
read okay
if [ "$okay" = "v" -o "$okay" = "V" ] ; then
okay=nothingyet
( cd $preparebranchforpullrequestlogfilefolder ; $viewer $preparebranchforpullrequestlogfileleaf )
elif [ "$okay" != 'y' -a "$okay" != 'Y' -a "$okay" != 'n' -a "$okay" != 'N' ] ; then
setlogviewer $okay
okay=nothingyet
viewer=$(logviewer)
( cd $preparebranchforpullrequestlogfilefolder ; $viewer $preparebranchforpullrequestlogfileleaf )
fi
done
if [ "$needcapitalY" = needcapitalY -a "$okay" != "Y" ] ; then
echo "Aborting."
aborted=aborted
elif [ "$okay" != "y" -a "$okay" != "Y" ] ; then
echo "Aborting."
aborted=aborted
fi
fi
prlogfile=/tmp/createpullrequest$$.txt
prlogfilefolder=$(dirname $prlogfile)
prlogfileleaf=$(basename $prlogfile)
if [ $aborted != aborted ] ; then
# For each schema repo,
# Create a pull request on bitbucket from the current safe branch to the target
evalschema.sh --evalschemasubfolder $subfolder 'yes | createpullrequest '"${prunedargs[@]}" > ${prlogfile} 2>&1
if [ "$runsdu" != "Y" -a "$runsdu" != "y" ] ; then
okay=nothingyet
while [ $okay = nothingyet ] ; do
echo "Please check ${prlogfile} and let me know if okay to mergepullrequest (merge pull requests) ..."
echo "(Provide the name of a viewer here if you want me to view logs with that in future.)"
echo
echo -n "[ y (yes) / n (abort) / v (view using ${viewer}) ] "
read okay
if [ "$okay" = "v" -o "$okay" = "V" ] ; then
okay=nothingyet
( cd $prlogfilefolder ; $viewer $prlogfileleaf )
elif [ "$okay" != 'y' -a "$okay" != 'Y' -a "$okay" != 'n' -a "$okay" != 'N' ] ; then
setlogviewer $okay
okay=nothingyet
viewer=$(logviewer)
( cd $prlogfilefolder ; $viewer $prlogfileleaf )
fi
done
if [ "$okay" != "y" -a "$okay" != "Y" ] ; then
echo "Aborting."
aborted=aborted
fi
else
echo
echo '----------------------------------------------------------------------'
echo
echo Please review and merge pull requests on BitBucket. Press ${yes} once you have reviewed and merged all your Pull Requests.
echo 'Alternatively, press n to exit. When merging your pull requests, please ensure you delete the source branch'
echo -n "[ ${yes} (yes) / n (exit) ] "
read okay
if [ "$okay" != "y" -a "$okay" != "Y" ] ; then
echo "Aborting."
aborted=aborted
fi
fi
fi
mprfflogfile=/tmp/mprffeparebranchforpullrequest$$.txt
mprfflogfilefolder=$(dirname $mprfflogfile)
mprfflogfileleaf=$(basename $mprfflogfile)
if [ $aborted != aborted ] ; then
if [ "$runsdu" != "Y" -a "$runsdu" != "y" ] ; then
# For each schema repo,
# Merge that pull request ff
evalschema.sh --evalschemasubfolder $subfolder 'yes | mergepullrequest '"${prunedargs[@]}"' --strategyId=ff' > ${mprfflogfile} 2>&1
fi
okay=nothingyet
while [ $okay = nothingyet ] ; do
echo "Please check ${mprfflogfile} and let me know if okay to runCleanup.sh ..."
echo "(Provide the name of a viewer here if you want me to view logs with that in future.)"
echo
echo -n "[ y (yes) / n (abort) / v (view using ${viewer}) ] "
read okay
if [ "$okay" = "v" -o "$okay" = "V" ] ; then
okay=nothingyet
( cd $mprfflogfilefolder ; $viewer $mprfflogfileleaf )
elif [ "$okay" != 'y' -a "$okay" != 'Y' -a "$okay" != 'n' -a "$okay" != 'N' ] ; then
setlogviewer $okay
okay=nothingyet
viewer=$(logviewer)
( cd $mprfflogfilefolder ; $viewer $mprfflogfileleaf )
fi
done
if [ "$okay" != "y" -a "$okay" != "Y" ] ; then
echo "Aborting."
aborted=aborted
fi
fi
# For each schema repo,
# maybe add the delete of the current branch upstream
echo -n "Should cleanup delete the origin copy of local branch ... [y/n] "
read okay
if [ "$okay" = "y" -o "$okay" = "Y" ] ; then
evalschema.sh --evalschemasubfolder $subfolder 'echo including in cleanup: git push origin --delete \"$(branch)\"'
evalschema.sh --evalschemasubfolder $subfolder 'registerCleanup.sh git push origin --delete \"$(branch)\"'
fi
if [ $aborted = aborted ] ; then
echo -n "Process has been aborted. Run runCleanup.sh anyway ... [y/n] "
read okay
if [ "$okay" != "y" -a "$okay" != "Y" ] ; then
echo "Aborting."
exit 1
fi
fi
# For each schema repo,
# delete staging branches
evalschema.sh --evalschemasubfolder $subfolder 'yes | runCleanup.sh'
\rm ${preparebranchforpullrequestlogfile}
\rm ${prlogfile}
if [ ! -f "${mprfflogfile}" ]; then
\rm ${mprfflogfile}
fi