forked from Kyligence/calcite-avatica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.sh
executable file
·314 lines (235 loc) · 9.42 KB
/
docker.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash
#
# 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.
#
set -e
function terminate() {
printf "\n\nUser terminated build. Exiting...\n"
exit 1
}
trap terminate SIGINT
PRODUCT=apache-calcite-avatica
RELEASE_REPO=https://dist.apache.org/repos/dist/release/calcite/
DEV_REPO=https://dist.apache.org/repos/dist/dev/calcite/
KEYS=()
GPG_COMMAND="gpg"
install_gnupg2(){
apt update
apt install gnupg2 -y
}
get_gpg_keys(){
GPG_KEYS=$($GPG_COMMAND --list-keys --with-colons --keyid-format LONG)
KEY_NUM=1
KEY_DETAILS=""
while read -r line; do
IFS=':' read -ra PART <<< "$line"
if [[ ${PART[0]} == "pub" ]]; then
if [ -n "$KEY_DETAILS" ]; then
KEYS[$KEY_NUM]=$KEY_DETAILS
KEY_DETAILS=""
((KEY_NUM++))
fi
KEY_DETAILS=${PART[4]}
fi
if [[ ${PART[0]} == "uid" ]]; then
KEY_DETAILS="$KEY_DETAILS - ${PART[9]}"
fi
done <<< "$GPG_KEYS"
if [[ -n "$KEY_DETAILS" ]]; then
KEYS[$KEY_NUM]=$KEY_DETAILS
fi
}
mount_gpg_keys(){
mkdir -p /.gnupg
if [[ -z "$(ls -A /.gnupg)" ]]; then
echo "Please mount the contents of your .gnupg folder into /.gnupg. Exiting..."
exit 1
fi
mkdir -p /root/.gnupg
cp -r /.gnupg/ /root/
chmod -R 700 /root/.gnupg/
rm -rf /root/.gnupg/*.lock
}
SELECTED_GPG_KEY=""
select_gpg_key(){
get_gpg_keys
export GPG_TTY=/dev/console
touch /root/.gnupg/gpg-agent.conf
echo 'default-cache-ttl 10000' >> /root/.gnupg/gpg-agent.conf
echo 'max-cache-ttl 10000' >> /root/.gnupg/gpg-agent.conf
echo "Starting GPG agent..."
gpg-agent --daemon
while $INVALID_KEY_SELECTED; do
if [[ "${#KEYS[@]}" -le 0 ]]; then
echo "You do not have any GPG keys available. Exiting..."
exit 1
fi
echo "You have the following GPG keys:"
for i in "${!KEYS[@]}"; do
echo "$i) ${KEYS[$i]}"
done
read -p "Select your GPG key for signing: " KEY_INDEX
SELECTED_GPG_KEY=$(sed 's/ -.*//' <<< ${KEYS[$KEY_INDEX]})
if [[ -z $SELECTED_GPG_KEY ]]; then
echo "Selected key is invalid, please try again."
continue
fi
echo "Authenticating your GPG key..."
echo "test" | $GPG_COMMAND --local-user $SELECTED_GPG_KEY --output /dev/null --sign -
if [[ $? != 0 ]]; then
echo "Invalid GPG passphrase or GPG error. Please try again."
continue
fi
echo "You have selected the following GPG key to sign the release:"
echo "${KEYS[$KEY_INDEX]}"
INVALID_CONFIRMATION=true
while $INVALID_CONFIRMATION; do
read -p "Is this correct? (y/n) " CONFIRM
if [[ ($CONFIRM == "Y") || ($CONFIRM == "y") ]]; then
INVALID_KEY_SELECTED=false
INVALID_CONFIRMATION=false
elif [[ ($CONFIRM == "N") || ($CONFIRM == "n") ]]; then
INVALID_CONFIRMATION=false
fi
done
done
}
RC_NUMBER=""
ASF_USERNAME=""
ASF_PASSWORD=""
NAME=""
get_dry_run_build_configuration(){
while $DRY_RUN_NOT_CONFIRMED; do
read -p "Enter the release candidate number (example: if you are releasing rc0, enter 0): " RC_NUMBER
read -p "Enter your ASF username: " ASF_USERNAME
read -p "Enter your name (this will be used for git commits): " NAME
echo "Build configured as follows:"
echo "RC: $RC_NUMBER"
echo "ASF Username: $ASF_USERNAME"
echo "Name: $NAME"
INVALID_CONFIRMATION=true
while $INVALID_CONFIRMATION; do
read -p "Is this correct? (y/n) " CONFIRM
if [[ ($CONFIRM == "Y") || ($CONFIRM == "y") ]]; then
DRY_RUN_NOT_CONFIRMED=false
INVALID_CONFIRMATION=false
elif [[ ($CONFIRM == "N") || ($CONFIRM == "n") ]]; then
INVALID_CONFIRMATION=false
fi
done
done
}
get_build_configuration(){
while $BUILD_NOT_CONFIRMED; do
read -p "Enter the release candidate number (example: if you are releasing rc0, enter 0): " RC_NUMBER
read -p "Enter your name (this will be used for git commits): " NAME
echo "Build configured as follows:"
echo "RC: $RC_NUMBER"
echo "Name: $NAME"
INVALID_CONFIRMATION=true
while $INVALID_CONFIRMATION; do
read -p "Is this correct? (y/n) " CONFIRM
if [[ ($CONFIRM == "Y") || ($CONFIRM == "y") ]]; then
BUILD_NOT_CONFIRMED=false
INVALID_CONFIRMATION=false
elif [[ ($CONFIRM == "N") || ($CONFIRM == "n") ]]; then
INVALID_CONFIRMATION=false
fi
done
done
}
get_asf_credentials(){
while $ASF_CREDS_NOT_CONFIRMED; do
read -p "Enter your ASF username: " ASF_USERNAME
read -s -p "Enter your ASF password: " ASF_PASSWORD
printf "\n"
echo "Your ASF Username is:" $ASF_USERNAME
INVALID_CONFIRMATION=true
while $INVALID_CONFIRMATION; do
read -p "Is this correct? (y/n) " CONFIRM
if [[ ($CONFIRM == "Y") || ($CONFIRM == "y") ]]; then
ASF_CREDS_NOT_CONFIRMED=false
INVALID_CONFIRMATION=false
elif [[ ($CONFIRM == "N") || ($CONFIRM == "n") ]]; then
INVALID_CONFIRMATION=false
fi
done
done
}
promote_release(){
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
if [[ ! $LATEST_TAG =~ .+-rc[[:digit:]]+$ ]]; then
echo "The latest tag ($LATEST_TAG) is not a RC release and should not be re-released."
exit 1
fi
TAG_WITHOUT_PRODUCT=$(echo $LATEST_TAG | sed -e 's/avatica-//')
TAG_WITHOUT_RC=$(echo $TAG_WITHOUT_PRODUCT | sed -e 's/-rc[0-9][0-9]*//')
RC_NUMBER=$(echo $TAG_WITHOUT_PRODUCT | sed -e 's/^[0-9\.]*-rc//')
if ! svn ls $DEV_REPO/$PRODUCT-$TAG_WITHOUT_PRODUCT; then
echo "The release $PRODUCT-$TAG_WITHOUT_PRODUCT was not found in the dev repository. Was it uploaded for voting?"
exit 1
fi
get_asf_credentials
gradle publishDist -Pasf -PasfSvnUsername=$ASF_USERNAME -PasfSvnPassword=$ASF_PASSWORD -PasfNexusUsername=$ASF_USERNAME -PasfNexusPassword=$ASF_PASSWORD -PasfGitSourceUsername=$ASF_USERNAME -PasfGitSourcePassword=$ASF_PASSWORD -Prc=$RC_NUMBER -Pasf.git.pushRepositoryProvider=GITBOX
# If there is more than 1 release, delete all of them, except for the newest one
# To do this, we do the following:
# 1. Get the list of releases with verbose information from svn
# 2. Sort by the first field (revision number) in descending order
# 3. Select apache-calcite-avatica releases
# 4. Exclude the release we're trying to promote, in case it was from a failed promotion.
# 5. Trim all whitespace down to 1 empty space.
# 6. Select field 7, which is each release's folder
CURRENT_RELEASES=$(svn ls -v $RELEASE_REPO | sort -k1 -r | grep $PRODUCT-[[:digit:]] | grep -v $PRODUCT-$TAG_WITHOUT_RC | tr -s ' ' | cut -d ' ' -f 7)
RELEASE_COUNT=0
while read -r RELEASE; do
if [[ $RELEASE_COUNT -ne 0 ]]; then
svn rm $RELEASE
echo "Removing release $RELEASE"
fi
RELEASE_COUNT=$((RELEASE_COUNT+1))
done <<< "$CURRENT_RELEASES"
svn commit -m "Release $PRODUCT-$TAG_WITHOUT_RC" --force-log --username $ASF_USERNAME --password $ASF_PASSWORD
echo "Release $PRODUCT-$LATEST_TAG successfully promoted to $PRODUCT-$TAG_WITHOUT_RC"
}
case $1 in
dry-run)
install_gnupg2
mount_gpg_keys
select_gpg_key
get_dry_run_build_configuration
gradle prepareVote -PasfTestSvnUsername=test -PasfTestSvnPassword=test -PasfTestNexusUsername=test -PasfTestNexusPassword=test -PasfTestGitSourceUsername=test -PasfTestGitSourcePassword=test -Prc=$RC_NUMBER -PuseGpgCmd -Psigning.gnupg.keyName=$SELECTED_GPG_KEY
;;
publish-release-for-voting)
install_gnupg2
mount_gpg_keys
select_gpg_key
get_build_configuration
get_asf_credentials
gradle prepareVote -Pasf -PasfCommitterId=$ASF_USERNAME -PasfSvnUsername=$ASF_USERNAME -PasfSvnPassword=$ASF_PASSWORD -PasfNexusUsername=$ASF_USERNAME -PasfNexusPassword=$ASF_PASSWORD -PasfGitSourceUsername=$ASF_USERNAME -PasfGitSourcePassword=$ASF_PASSWORD -Prc=$RC_NUMBER -PuseGpgCmd -Psigning.gnupg.keyName=$SELECTED_GPG_KEY -Pasf.git.pushRepositoryProvider=GITBOX
;;
clean)
gradle clean
;;
promote-release)
promote_release
;;
test)
gradle test
;;
*)
echo $"Usage: $0 {dry-run|publish-release-for-voting|clean|promote-release|test}"
;;
esac