-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.sh
executable file
·271 lines (244 loc) · 6.36 KB
/
submit.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
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/env bash
set -e
gawk --version &> /dev/null || {
echo "gawk is required to run this script."
exit 1
}
mode=
version=
force=
function usage() {
echo "usage: $0 <-p|-m> <version>"
echo " -p for patch release (x.y.Z)"
echo " -m for minor release (x.Y.0)"
echo " -r for release candidate (x.Y.0rcZ)"
echo "example: $0 -p 1.1.2"
}
while [ "$1" ]
do
case "$1" in
--help)
usage
exit 0
;;
-p)
mode=patch
;;
-r)
mode=rc
;;
-m)
mode=minor
;;
-f)
force=yes
;;
[0-9]*)
version=$1
;;
esac
shift
done
function red() {
echo -e "\033[1;31m$@\033[0m"
}
function die() {
red "*** $@"
echo "See also: $0 --help"
echo
exit 1
}
hub --version &> /dev/null || die "hub is not in PATH. Get it from https://github.com/github/hub"
if [ "$mode" = "" ]
then
die "Error: mode flag is mandatory"
fi
if ! [ "$version" ]
then
die "Error: missing version"
fi
git checkout master
git pull
if ! grep -q "$version" alpine/Dockerfile
then
if [[ "$force" = "yes" ]]
then
echo "Forcing to use the tag even though it is not in master."
git checkout "$version"
if ! grep -q "$version$" alpine/Dockerfile
then
die "Error: version in build script doesn't match required version."
fi
else
echo "****************************************"
echo "Error: this script should be run only after the"
echo "desired release is merged in master of docker-kong."
echo ""
echo "For making releases based on old versions,"
echo "Use -f to override and submit from the tag anyway."
echo "****************************************"
die "Failed."
fi
fi
xy=${version%.*}
z=${version#$xy.}
if [ "$mode" = "rc" ]
then
rc=${version#*rc}
z=${z%rc*}
fi
commit=$(git show "$version" | grep "^commit" | head -n 1 | cut -b8-48)
if [ "$mode" = "patch" ]
then
prev="$xy.$[z-1]"
prevcommit=$(git show "$prev" | grep "^commit" | head -n 1 | cut -b8-48)
elif [ "$mode" = "rc" -a "$rc" -gt 1 ]
then
prev="$xy.${z}rc$[rc-1]"
prevcommit=$(git show "$prev" | grep "^commit" | head -n 1 | cut -b8-48)
fi
rm -rf submit
mkdir submit
cd submit
git clone https://github.com/kong/official-images
cd official-images
git remote add upstream http://github.com/docker-library/official-images
git fetch upstream
git checkout master
git merge upstream/master
git checkout -b release/$version
if [ "$mode" = "patch" ]
then
sed "s|$prev-alpine|$version-alpine|;
s|$prev-centos|$version-centos|;
s|$prev-ubuntu|$version-ubuntu|;
s|$prev,|$version,|;
s|$prevcommit|$commit|;
s|refs/tags/$prev|refs/tags/$version|" library/kong > library/kong.new
mv library/kong.new library/kong
elif [ "$mode" = "rc" -a "$rc" -gt 1 ]
then
sed "s|$prev-alpine|$version-alpine|;
s|$prev-centos|$version-centos|;
s|$prev-ubuntu|$version-ubuntu|;
s|, ${xy}rc$[rc-1]|, ${xy}rc${rc}|;
s|$prev,|$version,|;
s|$prevcommit|$commit|;
s|refs/tags/$prev|refs/tags/$version|" library/kong > library/kong.new
mv library/kong.new library/kong
elif [ "$mode" = "rc" -a "$rc" -eq 1 ]
then
gawk '
BEGIN {
reset = 0
not_yet_first = 1
}
/^Tags/ {
if (not_yet_first == 1) {
not_yet_first = 0
before_first = 1
}
}
{
if (before_first == 1) {
v = "'$version'"
xy = "'$xy'"
commit = "'$commit'"
print "Tags: " v "-alpine, " v
print "GitCommit: " commit
print "GitFetch: refs/tags/" v
print "Directory: alpine"
print "Architectures: amd64"
print ""
print "Tags: " v "-ubuntu"
print "GitCommit: " commit
print "GitFetch: refs/tags/" v
print "Directory: ubuntu"
print "Architectures: amd64, arm64v8"
print ""
print "Tags: " v "-centos"
print "GitCommit: " commit
print "GitFetch: refs/tags/" v
print "Constraints: !aufs"
print "Directory: centos"
print "Architectures: amd64"
print ""
print
before_first = 0
} else {
print
}
}
' library/kong > library/kong.new
mv library/kong.new library/kong
elif [ "$mode" = "minor" ]
then
gawk '
BEGIN {
reset = 0
not_yet_first = 1
}
/^Tags/ {
if (not_yet_first == 1) {
not_yet_first = 0
before_first = 1
}
}
/Tags: .*[0-9]rc[0-9].*/ {
in_rc_tag = 1
}
/^ *$/ {
if (in_rc_tag == 1) {
reset = 1
}
}
{
if (before_first == 1) {
v = "'$version'"
xy = "'$xy'"
commit = "'$commit'"
print "Tags: " v "-alpine, " v ", " xy ", latest"
print "GitCommit: " commit
print "GitFetch: refs/tags/" v
print "Directory: alpine"
print "Architectures: amd64"
print ""
print "Tags: " v "-ubuntu, " xy "-ubuntu"
print "GitCommit: " commit
print "GitFetch: refs/tags/" v
print "Directory: ubuntu"
print "Architectures: amd64, arm64v8"
print ""
print "Tags: " v "-centos, " xy "-centos"
print "GitCommit: " commit
print "GitFetch: refs/tags/" v
print "Constraints: !aufs"
print "Directory: centos"
print "Architectures: amd64"
print ""
before_first = 0
} else if (!(in_rc_tag == 1)) {
gsub(", latest", "")
print
}
if (reset == 1) {
in_rc_tag = 0
reset = 0
}
}
' library/kong > library/kong.new
mv library/kong.new library/kong
fi
echo "****************************************"
git diff
echo "****************************************"
echo "Everything looks all right? (y/n)"
echo "(Answering y will commit, push the branch, and submit the PR)"
read
if ! [ "$REPLY" == "y" ]
then
exit 1
fi
git commit -av -m "kong $version"
git push --set-upstream origin release/$version
hub pull-request -b docker-library:master -h "release/$version" -m "bump Kong to $version"