forked from pulp/pulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.sh
260 lines (234 loc) · 4.05 KB
/
tag.sh
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/bash
#
# Tagging script
#
set -e # exit on failed
VERSION=
BUILD_TAG=
GIT="git"
TITO="tito"
TITO_TAG_FLAGS=
BRANCH=
PARENT='master'
GIT_ROOTS="pulp pulp_rpm pulp_puppet"
PACKAGES="
pulp/
pulp_rpm/
pulp_puppet/"
NEXT_VR_SCRIPT=\
$(cat << END
import sys
sys.path.insert(0, 'rel-eng/lib')
import tools
print tools.next()
END
)
set_version()
{
pushd pulp
VERSION=`python -c "$NEXT_VR_SCRIPT"`
popd
}
tito_tag()
{
# $1=<git-root>
pushd $1
$TITO tag $TITO_TAG_FLAGS && $GIT push origin HEAD && $GIT push --tags
popd
}
git_tag()
{
# $1=<git-root>
pushd $1
$GIT tag -m "Build Tag" $BUILD_TAG && $GIT push --tags
popd
}
git_prep()
{
verify_branch
for DIR in $GIT_ROOTS
do
pushd $DIR
echo "Preparing git in repository [$DIR] using [$BRANCH]"
if [ "$PARENT" != "$BRANCH" ]
then
$GIT checkout $BRANCH && $GIT pull --rebase
$GIT checkout $PARENT && $GIT pull --rebase
git_pre_tag_merge
$GIT checkout $BRANCH
else
$GIT checkout $BRANCH && $GIT pull --rebase
fi
popd
done
}
git_pre_tag_merge()
{
commits=(`$GIT log $PARENT..$BRANCH`)
if [ ${#commits[@]} -gt 0 ]
then
echo "(pre-tag) Merging $BRANCH => $PARENT"
echo ""
$GIT log $PARENT..$BRANCH
echo ""
read -p "Continue [y|n]: " ANS
if [ $ANS = "y" ]
then
MESSAGE="Merge $BRANCH => $PARENT, pre-build"
$GIT merge -m "$MESSAGE" $BRANCH
$GIT push origin HEAD
else
exit 0
fi
fi
}
git_post_tag_merge()
{
if [ "$PARENT" = "$BRANCH" ]
then
return
fi
for DIR in $GIT_ROOTS
do
echo "(post-tag) Merging (-s ours) $DIR $BRANCH => $PARENT"
pushd $DIR
$GIT checkout $PARENT
$GIT log $PARENT..$BRANCH
echo ""
read -p "Continue [y|n]: " ANS
if [ $ANS = "y" ]
then
MESSAGE="Merge (-s ours) $BRANCH => $PARENT, post-build"
$GIT merge -s ours -m "$MESSAGE" $BRANCH
$GIT push origin HEAD
fi
popd
done
}
verify_branch()
{
for DIR in $GIT_ROOTS
do
pushd $DIR
$GIT fetch --tags
set +e
$GIT tag -l $BRANCH | grep $BRANCH >& /dev/null
if [ $? = 0 ]; then
echo "[$BRANCH] must be a branch."
exit 1
fi
set -e
popd
done
}
verify_version()
{
set +e
echo $VERSION | grep -E "(alpha|beta)$"
if [ $? = 1 ]
then
echo ""
echo "WARNING: [$VERSION] does not contain (alpha|beta)."
read -p "Is this a STABLE build [y|n]: " ANS
if [ $ANS != "y" ]
then
exit 0
fi
fi
set -e
}
usage()
{
cat << EOF
usage: $0 options
This script tags all pulp projects
OPTIONS:
-h Show this message
-v The pulp version and release. Eg: 2.3.0-1
-a Auto accept the changelog
-b Checkout the specified branch
-p A parent branch. (default: master)
EOF
}
while getopts "hav:b:p:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
v)
VERSION=$OPTARG
;;
a)
TITO_TAG_FLAGS="$TITO_TAG_FLAGS --accept-auto-changelog"
;;
b)
BRANCH=$OPTARG
;;
p)
PARENT=$OPTARG
;;
?)
usage
exit
;;
esac
done
# git (pre-tag) preparation
if [[ -n $BRANCH ]]
then
if [ "$BRANCH" = "$PARENT" ]
then
BRANCHES=$BRANCH
else
BRANCHES="$PARENT/$BRANCH"
fi
echo "Prepare git repositories using: [$BRANCHES]"
read -p "Continue [y|n]: " ANS
if [ $ANS = "y" ]
then
git_prep
echo ""
echo ""
fi
fi
# version based on main pulp project
# unless specified using -v
if [[ -z $VERSION ]]
then
set_version
fi
# verify the version
verify_version
# confirmation
echo ""
echo ""
echo "Using:"
echo " version [$VERSION]"
echo " tito options: $TITO_TAG_FLAGS"
echo ""
read -p "Continue [y|n]: " ANS
if [ $ANS != "y" ]
then
exit 0
fi
# used by tagger
PULP_VERSION_AND_RELEASE=$VERSION
export PULP_VERSION_AND_RELEASE
BUILD_TAG="build-$VERSION"
# tito tagging
for PACKAGE in $PACKAGES
do
tito_tag $PACKAGE
done
# git (correlated build) tagging
for GIT_ROOT in $GIT_ROOTS
do
git_tag $GIT_ROOT
done
# git (post-tag) merging
if [[ -n $BRANCH ]]
then
git_post_tag_merge
fi