-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
executable file
·464 lines (382 loc) · 9.78 KB
/
build.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
#!/bin/bash
trap ctrl_c INT
function ctrl_c() {
exit -2
}
if [[ ! -f /secure/config.env ]]
then
echo "Missing /secure/config.env"
exit -1
fi
source /secure/config.env
function run {
check_dryrun
read_version
read_date
read_committer
read_gpg
read_ssh_key
msg_success "Building Version: $VERSION"
set_committer "$COMMITTER_NAME" "$COMMITTER_EMAIL"
check_date "$DATE"
check_gpg "$GPG_KEY"
check_ssh_key "$SSH_KEY"
clone_php
find_branch "$VERSION"
# This function call creates VERSION_* variables
get_version "$VERSION"
create_release_branch "$VERSION"
update_version \
"$VERSION_MAJOR" "$VERSION_MINOR" "$VERSION_MICRO" \
"$VERSION_EXTRA" "$VERSION_EXTRA_VERSION" "$VERSION_ID"
update_news "$DATE"
verify_changes
commit_updates "$VERSION"
compile_php
run_tests
# We do this after the tests so it is more visible
compare_version "$VERSION"
tag_release "$GPG_KEY" "$VERSION"
make_dist "$VERSION"
gen_verify_stub "$VERSION"
gen_md5_stub "$VERSION"
move_files "$VERSION"
msg_success "Build completed for php-${VERSION}!"
read_next_ver
update_news_next_ver "$ROOT_BRANCH" "$DATE" "$NEXT_VERSION"
verify_changes
commit_news_next_ver "$NEXT_VERSION"
push_branches "$ROOT_BRANCH" "$RELEASE_BRANCH" "$TAG_NAME"
}
function read_with_default {
msg -n "$2"
if [[ ! -z "$3" ]]
then
msg -n " [$3]"
fi
msg -n ": "
read READ_VALUE
if [[ -z "$READ_VALUE" ]]
then
READ_VALUE="$3"
fi
local __RESULT_VAR=$1
eval $__RESULT_VAR="'$READ_VALUE'"
}
function read_yesno {
read_with_default READ_VALUE "$2 (y/n)" ${3:-no}
READ_VALUE=$(echo $READ_VALUE | tr "[:upper:]" "[:lower:]")
local __RESULT_VAR=$1
if [[ "$READ_VALUE" == n* ]]
then
eval $__RESULT_VAR="no"
elif [[ "$READ_VALUE" == y* ]]
then
eval $__RESULT_VAR="yes"
else
msg_error "Invalid response: $READ_VALUE"
exit -1
fi
}
function check_dryrun {
if [[ ! -z "$DRY_RUN" ]]
then
msg_warn "Performing a dry run, changes will not be pushed"
fi
}
function read_version {
msg -n "PHP Version to build (e.g. 7.1.0beta2): "
read VERSION
}
function read_date {
local DEFAULT_DATE=$(date -d "+2 days" "+%d %b")
read_with_default DATE "Release Date" "$DEFAULT_DATE"
}
function read_committer {
read_with_default COMMITTER_NAME "Name" "$COMMITTER_NAME"
read_with_default COMMITTER_EMAIL "Email Address" "$COMMITTER_EMAIL"
}
function read_gpg {
read_with_default GPG_KEY "GPG Key Fingerprint" "$GPG_KEY"
}
function read_ssh_key {
read_with_default SSH_KEY "SSH Key" ${SSH_KEY:-id_rsa}
}
function check_date {
DATE=${1:-$(date -d "+2 days" "+%d %b")}
msg_success "Using Date: $DATE"
}
function set_committer {
msg_info "Setting committer to: $1 <$2>"
git config --global user.name "$1"
git config --global user.email "$2"
}
function check_ssh_key {
if [[ -z $1 ]]
then
SSH_KEY=id_rsa
msg_warn "Using default SSH key: $SSH_KEY"
fi
if [ ! -f "/secure/.ssh/$SSH_KEY" ]
then
msg_error "SSH Key Not Found. Did you mount it?"
msg_info "Try running docker with:"
msg_info "-v\$HOME/.ssh:/secure/.ssh"
exit -1
fi
eval "$(ssh-agent -s)"
ssh-add "/secure/.ssh/$SSH_KEY"
if [[ $? -ne 0 ]]
then
msg_error "Failed to add SSH Key: $SSH_KEY"
exit -1
fi
msg_success "Using SSH Key: $SSH_KEY"
}
function check_gpg {
if [ ! -f "/secure/.gnupg/pubring.gpg" ]
then
if [ -f "/secure/.gnupg/pubring.kbx" ]
then
msg_error "GPGv2 pubring found, but not GPGv1"
msg_info "Debian 8 only support GPGv1 keys"
else
msg_error "GPG Keys Not Found. Did you mount it?"
msg_info "Try running docker with:"
msg_info "-v\$HOME/.gnupg:/secure/.gnupg"
fi
exit -1
fi
VERIFY_KEY=`gpg --list-keys $1 2>/dev/null`
if [[ $? -ne 0 ]]
then
msg_error "GPG Key \"$1\" Not Found"
exit -1
fi
msg_success "GPG Key: $1"
}
function clone_php {
if [[ -z $REPO_URL ]]
then
REPO_URL="[email protected]:php-src.git"
fi
msg_info "Using repo: $REPO_URL"
git clone "$REPO_URL"
cd php-src
}
function find_branch {
# Check if on release branch
git branch -a | grep -q "remotes/origin/PHP-$1$"
if [[ $? -eq 0 ]]
then
msg_warn "Found existing release branch: PHP-$1"
BRANCH_DEFAULT="PHP-$1"
else
local VERSION=$(echo $1 | cut -c 1-3)
BRANCH_DEFAULT="PHP-$VERSION"
fi
git branch -a | grep -q "remotes/origin/$BRANCH_DEFAULT$"
if [[ $? -ne 0 ]]
then
BRANCH_DEFAULT="master"
fi
read_with_default USE_BRANCH_DEFAULT "Which branch should be used to build from?" "$BRANCH_DEFAULT"
if [[ -z "$USE_BRANCH_DEFAULT" ]]
then
USE_BRANCH_DEFAULT=BRANCH_DEFAULT
fi
git branch -a | grep -q "remotes/origin/$USE_BRANCH_DEFAULT$"
if [[ $? -ne 0 ]]
then
msg_error "Branch \"$USE_BRANCH_DEFAULT\" not found."
msg_error "Bailing out..."
exit -1
fi
ROOT_BRANCH="$USE_BRANCH_DEFAULT"
msg_success "Switching to branch $ROOT_BRANCH: "
git checkout "$ROOT_BRANCH"
}
function get_version {
VERSION_MAJOR=$(echo $1 | cut -d "." -f 1)
VERSION_MINOR=$(echo $1 | cut -d "." -f 2)
VERSION_MICRO=$(echo $1 | cut -d "." -f 3 | egrep -o "[0-9]+" | head -n 1)
if [[ $VERSION_MICRO != $(echo $1 | cut -d "." -f 3) ]]
then
# This is an alpha/beta/RC
OFFSET=${#VERSION_MICRO}
OFFSET=$((OFFSET+1))
VERSION_EXTRA=$(echo $1 | cut -d "." -f 3 | cut -c $OFFSET-)
VERSION_EXTRA_VERSION=$(echo $VERSION_EXTRA | cut -d "." -f 3 | egrep -o "[0-9]+")
VERSION_EXTRA=$(echo $VERSION_EXTRA | sed s/$VERSION_EXTRA_VERSION//g)
fi
VERSION_ID=$(($((VERSION_MAJOR*10000))+$((VERSION_MINOR*100))+$((VERSION_MICRO+0))))
}
function create_release_branch {
RELEASE_BRANCH="PHP-$1"
local CURRENT_BRANCH=$(git symbolic-ref -q HEAD | grep $RELEASE_BRANCH$)
if [[ $? -ne 0 ]]
then
msg_info "Creating release branch PHP-$1"
git checkout -b "$RELEASE_BRANCH"
else
msg_info "Already on release branch PHP-$1"
fi
}
function update_version {
# PHP 7.2 moved to configure.ac instead of configure.in
CONFIGURE_AC="configure.ac"
if [[ ! -f "configure.ac" ]]
then
CONFIGURE_AC="configure.in"
fi
msg_info -n "Updating main/php_version.h: "
echo "/* automatically generated by configure */" > main/php_version.h
echo "/* edit $CONFIGURE_AC to change version number */" >> main/php_version.h
echo "#define PHP_MAJOR_VERSION $1" >> main/php_version.h
echo "#define PHP_MINOR_VERSION $2" >> main/php_version.h
echo "#define PHP_RELEASE_VERSION $3" >> main/php_version.h
echo "#define PHP_EXTRA_VERSION \"$4$5\"" >> main/php_version.h
echo "#define PHP_VERSION \"$1.$2.$3$4$5\"" >> main/php_version.h
echo "#define PHP_VERSION_ID $6" >> main/php_version.h
msg_success "done!"
msg_info -n "Updating ${CONFIGURE_AC}: "
sed -i "s/^PHP_MAJOR_VERSION=[0-9]\+$/PHP_MAJOR_VERSION=$1/g" "$CONFIGURE_AC"
sed -i "s/^PHP_MINOR_VERSION=[0-9]\+$/PHP_MINOR_VERSION=$2/g" "$CONFIGURE_AC"
sed -i "s/^PHP_RELEASE_VERSION=[0-9]\+$/PHP_RELEASE_VERSION=$3/g" "$CONFIGURE_AC"
sed -i "s/^PHP_EXTRA_VERSION=\".\+\"$/PHP_EXTRA_VERSION=\"$4$5\"/g" "$CONFIGURE_AC"
msg_success "done!"
}
function update_news {
msg_info -n "Updating NEWS: "
sed -i "s/^?? ???/$1/g" NEWS
msg_success "done!"
}
function verify_changes {
msg_info "Verify Changes"
git diff
read_yesno VERIFY_CHANGES "Does everything look good" "no"
if [[ "$VERIFY_CHANGES" = "no" ]]
then
msg_error "Bailing out..."
exit -1
fi
}
function commit_updates {
msg_info "Committing Changes"
git commit -a -m "Update versions/dates for PHP $1"
}
function compile_php {
msg_info "Compiling PHP: "
./travis/compile.sh > /dev/null
}
function run_tests {
msg_info "Running Tests"
sleep 3
./sapi/cli/php run-tests.php -p `pwd`/sapi/cli/php -g "FAIL,XFAIL,BORK,WARN,LEAK,SKIP" --offline --show-diff --set-timeout 120
read_yesno LOOKS_GOOD "Does the output look good" "no"
if [[ "$LOOKS_GOOD" = "no" ]]
then
msg_error "Bailing out..."
exit -1
fi
}
function compare_version {
BUILD_VERSION=$(./sapi/cli/php -n -v | head -n 1 | cut -d " " -f 2)
if [[ "$BUILD_VERSION" != "$1" ]]
then
msg_error "Build version \"$BUILD_VERSION\" doesn't match \"$1\""
exit 1
fi
msg_success "Build version \"$BUILD_VERSION\" matches \"$1\""
}
function tag_release {
TAG_NAME="php-$2"
git tag -u $1 $TAG_NAME -m "Tag for $TAG_NAME"
if [[ $? -ne 0 ]]
then
msg_error "Unable to tag!"
exit -1
fi
msg_success "Tagged $TAG_NAME with key \"$1\" successfully!"
}
function push_branches {
if [[ -z "$DRY_RUN" ]]
then
local UNIQUE_REFS=$(echo $@ | tr ' ' '\n' | sort -u | tr '\n' ' ')
msg_info -n "Pushing branches: "
git push origin $UNIQUE_REFS
else
msg_warn "Skipping push"
msg_info "Would push $UNIQUE_REFS"
fi
}
function make_dist {
msg_info -n "Creating packages: "
PHPROOT=. ./makedist "$1"
if [[ $? -ne 0 ]]
then
msg_error "failed!"
exit -1
fi
msg_success "done!"
}
function gen_verify_stub {
msg_info "Generating GPG Signatures:"
./scripts/dev/gen_verify_stub "$1"
}
function gen_md5_stub {
msg_info "Generating MD5 Signatures:"
md5sum "php-$1.tar"* | grep -v asc
}
function move_files {
msg_info -n "Copying packages and signatures: "
cp -R "php-$1.tar."* /php-build
msg_info "done"
}
function read_next_ver {
msg -n "Next PHP Version to build (e.g. 7.1.0beta2): "
read NEXT_VERSION
}
function update_news_next_ver {
local YEAR=$(date -d "+2 weeks" "+%Y")
git checkout $1
msg -n "Updating NEWS: "
sed -i "s/^?? ???/$2/" NEWS
awk "NR==3{print \"?? ??? $YEAR, PHP $3\n\n\n\"}7" NEWS > TMPNEWS
mv TMPNEWS NEWS
msg_success "done!"
}
function commit_news_next_ver {
msg "Committing:"
git add NEWS
git commit -a -m "Update NEWS for $1"
}
function msg_with_color {
local ESC_SEQ="\x1b["
local RESET=$ESC_SEQ"39;49;00m"
local COLOR="$ESC_SEQ$1"
shift
local ARGS=''
if [[ $# -gt 1 ]]
then
ARGS=" $1"
shift
fi
echo -e$ARGS "$COLOR$@$RESET"
}
function msg {
msg_with_color "39;49;00m" "$@"
}
function msg_success {
msg_with_color "32;01m" "$@"
}
function msg_info {
msg_with_color "34;01m" "$@"
}
function msg_warn {
msg_with_color "33;01m" "$@"
}
function msg_error {
msg_with_color "31;01m" "$@"
}
run