forked from corimf/build-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
corimf-newver
executable file
·241 lines (221 loc) · 6.75 KB
/
corimf-newver
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
234
235
236
237
238
239
240
241
#!/bin/sh -e
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
###############################################################################
# Use the -e option so the script will fail on the first non-zero return code.
# This is a script to create a new ESR branch $BRANCH from the specified
# platform branch $BASE_BRANCH and from the latest production plugins and
# $OTHER_REPOS. It will also pull the latest content of $BASE_BRANCH from
# $REMOTE_MASTER.
if [ "$1" = "" ]
then
echo "Loading the settings from corimf-settings..."
source corimf-settings
else
echo "Loading the settings from $1"
source "$1"
fi
echo "MASTER_ORIGIN=$MASTER_ORIGIN"
echo "REMOTE_ORIGIN=$REMOTE_ORIGIN"
echo "BASE_BRANCH=$BASE_BRANCH"
echo "BRANCH=$BRANCH"
echo "NEW_TAG=$NEW_TAG"
/bin/echo -n "Hit ENTER to continue: "
read ANSWER
# Shouldn't need to change anything below here.
check_rc() {
SAVE_RC=$?
if [ $SAVE_RC != 0 ]
then
echo "Failed."
exit $RC
elif [ "$DONE" = 1 ]
then
echo "Success."
else
echo "Incomplete."
exit 1
fi
}
trap check_rc EXIT
# An idempotent wrapper around the "git tag" command.
# Usage: git_tag_unless MY_NEW_TAG [TARGET]
git_tag_unless() {
TAG_NAME=$1
test ! -z "$TAG_NAME"
# TARGET is optional
TARGET=$2
if [ -z "$TARGET" ]
then
TARGET="HEAD"
fi
HASH1=`git rev-parse $TAG_NAME || true`
HASH2=`git rev-parse $TARGET || true`
if [ "$HASH1" = "$TAG_NAME" ]
then
# doesn't exist
git tag $TAG_NAME
elif [ ! -z "$HASH1" -a "$HASH1" = "$HASH2" ]
then
# already exists like we want.
echo "Tag $TAG_NAME already exists at $TARGET, which is OK."
else
# at a different hash
echo "Existing tag $TAG_NAME does not reference the same hash as $TARGET."
fail
fi
}
echo "Checking that we are one dir above the git repo..."
test -d $PLATFORM_REPO
echo "Checking major version number..."
MAJOR=`echo $BRANCH | cut -f1 -d.`
test "$MAJOR" -ge 2 -a "$MAJOR" -le 3
if [ "$MAJOR" -ge 3 ]
then
echo "Checking that the plugin count is $PLUGIN_COUNT..."
COUNT=0
for PLUGIN in $PLUGINS
do
COUNT=`expr $COUNT + 1`
done
test "$COUNT" == "$PLUGIN_COUNT"
else
echo "Skipping all plugins since version is $MAJOR"
PLUGINS=
PLUGMAN_REPO=
fi
echo "Checking that each repo exists..."
for DIR in $PLATFORM_REPOS $PLUGINS $OTHER_REPOS
do
test -d $DIR
done
echo "Checking that $REMOTE_ORIGIN is a defined remote..."
for DIR in $PLATFORM_REPOS $PLUGINS $OTHER_REPOS
do
pushd $DIR
git remote | grep $REMOTE_ORIGIN
popd
done
echo "Checking that $MASTER_ORIGIN is a defined remote..."
for DIR in $PLATFORM_REPOS $PLUGINS $OTHER_REPOS
do
pushd $DIR
git remote | grep $MASTER_ORIGIN
popd
done
echo "Checking out $BASE_BRANCH for platforms..."
for DIR in $PLATFORM_REPOS
do
pushd $DIR
git fetch $MASTER_ORIGIN
git checkout $BASE_BRANCH || git checkout -b $BASE_BRANCH $MASTER_ORIGIN/$BASE_BRANCH
git pull $MASTER_ORIGIN $BASE_BRANCH
git fetch --tags $MASTER_ORIGIN
# get this much current in $REMOTE_ORIGIN
git push $REMOTE_ORIGIN $BASE_BRANCH
git push --tags $REMOTE_ORIGIN
popd
done
echo "Checking out master for plugins and other..."
# this does assume you want the latest release for the plugis and other
for DIR in $PLUGINS $OTHER_REPOS
do
pushd $DIR
git fetch $MASTER_ORIGIN
git checkout master || git checkout -b master $MASTER_ORIGIN/master
git pull $MASTER_ORIGIN master
git fetch --tags $MASTER_ORIGIN
# get this much current in $REMOTE_ORIGIN
git push $REMOTE_ORIGIN master
git push --tags $REMOTE_ORIGIN
popd
done
echo "Creating branch $BRANCH for platform repos..."
# master for platforms and other, dev for plugins
for DIR in $PLATFORM_REPOS
do
pushd $DIR
echo "Checking out $BRANCH in $DIR..."
git checkout $BRANCH || git checkout -b $BRANCH $MASTER_ORIGIN/$BASE_BRANCH
echo "Pushing $BRANCH to $REMOTE_ORIGIN..."
git push $REMOTE_ORIGIN $BRANCH
echo "Creating tag $NEW_TAG"
git_tag_unless $NEW_TAG
git push --tags $REMOTE_ORIGIN
popd
done
echo "Creating branch $BRANCH for plugin repos..."
for DIR in $PLUGINS
do
# get corresponding plugin tag from json file
PLUGIN_TAG=`node build-tools/get_repo_ver.js $BRANCH $DIR`
if [ -z "$PLUGIN_TAG" ]
then
echo "Could not get plugin tag for $DIR from config.json file. Could not create $BRANCH for $DIR"
fail
else
echo "Got plugin tag: $PLUGIN_TAG"
fi
pushd $DIR
git fetch $REMOTE_ORIGIN
if [ `git tag --list $PLUGIN_TAG` ]
then
echo "Checking out $BRANCH in $DIR..."
git checkout $BRANCH || git checkout -b $BRANCH $PLUGIN_TAG
echo "Pushing $BRANCH to $REMOTE_ORIGIN..."
git push $REMOTE_ORIGIN $BRANCH
echo "Creating tag $NEW_TAG"
git_tag_unless $NEW_TAG
git push --tags $REMOTE_ORIGIN
else
echo "Plugin tag: $PLUGIN_TAG does not exist. Could not create $BRANCH for $DIR"
fail
fi
popd
done
echo "Creating branch $BRANCH for other repos..."
for DIR in $OTHER_REPOS
do
# get corresponding plugin tag from json file
TOOL_TAG=`node build-tools/get_repo_ver.js $BRANCH $DIR`
if [ -z "$TOOL_TAG" ]
then
echo "Could not get plugin tag for $DIR from config.json file. Could not create $BRANCH for $DIR"
fail
else
echo "Got tool tag: $TOOL_TAG"
fi
pushd $DIR
# cordova-blackberry-plugins uses master which is not a tag
if [ ! -z "`git tag --list $TOOL_TAG`" -o "$TOOL_TAG" = "master" ]
then
echo "Checking out $BRANCH in $DIR..."
git checkout $BRANCH || git checkout -b $BRANCH $TOOL_TAG
echo "Pushing $BRANCH to $REMOTE_ORIGIN..."
git push $REMOTE_ORIGIN $BRANCH
echo "Creating tag $NEW_TAG"
git_tag_unless $NEW_TAG
git push --tags $REMOTE_ORIGIN
else
echo "Tool tag: $TOOL_TAG does not exist. Could not create $BRANCH for $DIR"
fail
fi
popd
done
DONE=1