-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease-lib.sh
687 lines (570 loc) · 19.9 KB
/
release-lib.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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
#!/bin/bash
red="\033[0;31m"
green="\033[0;32m"
cyan="\033[0;36m"
bold="\033[1m"
nocolor="\033[0m"
GITHUB_ORG=${GITHUB_ORG:-Kong}
scripts_folder=$(dirname "$0")
browser="echo"
if command -v firefox > /dev/null 2>&1
then
browser=firefox
elif which xdg-open > /dev/null 2>&1
then
browser=xdg-open
elif which open > /dev/null 2>&1
then
browser=open
fi
EDITOR="${EDITOR-$VISUAL}"
#-------------------------------------------------------------------------------
function need() {
req="$1"
if ! type -t "$req" &>/dev/null; then
echo "Required command $req not found."
exit 1
fi
}
#-------------------------------------------------------------------------------
function check_requirements() {
need git
need hub
need sed
}
#-------------------------------------------------------------------------------
function yesno() {
echo "$1"
read -r
if [[ "$REPLY" =~ ^[yY] ]]; then
return 0
fi
return 1
}
#-------------------------------------------------------------------------------
function check_milestone() {
if yesno "Visit the milestones page (https://github.com/$GITHUB_ORG/kong/milestone) and ensure PRs are merged. Press 'y' to open it or Ctrl-C to quit"; then
$browser https://github.com/$GITHUB_ORG/kong/milestones
fi
CONFIRM "If everything looks all right, press Enter to continue"
SUCCESS "All PRs are merged. Proceeding!"
}
#-------------------------------------------------------------------------------
function check_dependencies() {
if yesno "Ensure Kong dependencies in the rockspec are bumped to their latest patch version. Press 'y' to open Kong's rockspec or Ctrl+C to quit"; then
$EDITOR ./*.rockspec
fi
CONFIRM "If everything looks all right, press Enter to continue"
SUCCESS "All dependencies are bumped. Proceeding!"
}
#-------------------------------------------------------------------------------
function write_changelog() {
version=$1
if ! grep -q "\[$version\]" CHANGELOG.md
then
prepare_changelog
fi
CONFIRM "Press Enter to open your text editor ($EDITOR) to edit CHANGELOG.md" \
"or Ctrl-C to cancel."
$EDITOR CHANGELOG.md
SUCCESS "If you need to further edit the changelog," \
"you can run this step again."
"If it is ready, you can proceed to the next step" \
"which will commit it:" \
" $0 $version commit_changelog"
}
#-------------------------------------------------------------------------------
function commit_changelog() {
version=$1
if ! git status CHANGELOG.md | grep -q "modified:"
then
die "No changes in CHANGELOG.md to commit. Did you write the changelog?"
fi
git diff CHANGELOG.md
CONFIRM "If everything looks all right, press Enter to commit" \
"or Ctrl-C to cancel."
set -e
git add CHANGELOG.md
git commit -m "docs(changelog): add $version changes"
git log -n 1
SUCCESS "The changelog is now committed locally." \
"You are ready to run the next step:" \
" $0 $version update_copyright"
}
#-------------------------------------------------------------------------------
function update_copyright() {
version=$1
if ! "$scripts_folder/update-copyright"
then
die "Could not update copyright file. Check logs for missing licenses, add hardcoded ones if needed"
fi
git add COPYRIGHT
git commit -m "docs(COPYRIGHT): update copyright for $version"
git log -n 1
SUCCESS "The COPYRIGHT file is updated locally." \
"You are ready to run the next step:" \
" $0 $version update_admin_api_def"
}
#-------------------------------------------------------------------------------
function update_admin_api_def() {
version=$1
if ! "$scripts_folder/gen-admin-api-def.sh"
then
die "Could not update kong-admin-api.yml file. Check script output for any error messages."
fi
git add kong-admin-api.yml
git commit -m "docs(kong-admin-api.yml): update Admin API definition for $1"
git log -n 1
SUCCESS "The kong-admin-api.yml file is updated locally." \
"You are ready to run the next step:" \
" $0 $version version_bump"
}
#-------------------------------------------------------------------------------
function bump_homebrew() {
curl -L -o "kong-$version.tar.gz" "https://download.konghq.com/gateway-src/kong-$version.tar.gz"
sum=$(sha256sum "kong-$version.tar.gz" | awk '{print $1}')
sed -i.bak 's/KONG_VERSION = "[0-9.]*"/KONG_VERSION = "'$version'"/' Formula/kong.rb
sed -i.bak 's/sha256 ".*"/sha256 "'$sum'"/' Formula/kong.rb
}
#-------------------------------------------------------------------------------
function bump_vagrant() {
sed -i.bak 's/version = "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"/version = "'$version'"/' Vagrantfile
sed -i.bak 's/`[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*`/`'$version'`/' README.md
}
#-------------------------------------------------------------------------------
function ensure_recent_luarocks() {
if ! ( luarocks upload --help | grep -q temp-key )
then
if [ `uname -s` = "Linux" ]
then
set -e
source .requirements
lv=3.2.1
pushd /tmp
rm -rf luarocks-$lv
mkdir -p luarocks-$lv
cd luarocks-$lv
curl -L -o "luarocks-$lv-linux-x86_64.zip" https://luarocks.github.io/luarocks/releases/luarocks-$lv-linux-x86_64.zip
unzip luarocks-$lv-linux-x86_64.zip
export PATH=/tmp/luarocks-$lv/luarocks-$lv-linux-x86_64:$PATH
popd
else
die "Your LuaRocks version is too old. Please upgrade LuaRocks."
fi
fi
}
#-------------------------------------------------------------------------------
function make_github_release_file() {
versionlink=$(echo $version | tr -d .)
cat <<EOF > release-$version.txt
$version
**Download Kong $version and run it now:**
- https://konghq.com/install/
- [Docker Image](https://hub.docker.com/_/kong/)
Links:
- [$version Changelog](https://github.com/$GITHUB_ORG/kong/blob/$version/CHANGELOG.md#$versionlink)
EOF
}
#-------------------------------------------------------------------------------
function bump_docs_kong_versions() {
$LUA -e '
local fd_in = io.open("app/_data/kong_versions.yml", "r")
local fd_out = io.open("app/_data/kong_versions.yml.new", "w")
local version = "'$version'"
local state = "start"
local version_line
for line in fd_in:lines() do
if state == "start" then
if line:match("^ release: \"'$major'.'$minor'.x\"") then
state = "version"
end
fd_out:write(line .. "\n")
elseif state == "version" then
if line:match("^ version: \"") then
version_line = line
state = "edition"
end
elseif state == "edition" then
if line:match("^ edition.*gateway%-oss.*") then
fd_out:write(" version: \"'$version'\"\n")
state = "wait_for_luarocks_version"
else
fd_out:write(version_line .. "\n")
state = "start"
end
fd_out:write(line .. "\n")
elseif state == "wait_for_luarocks_version" then
if line:match("^ luarocks_version: \"") then
fd_out:write(" luarocks_version: \"'$version'-0\"\n")
state = "last"
else
fd_out:write(line .. "\n")
end
elseif state == "last" then
fd_out:write(line .. "\n")
end
end
fd_in:close()
fd_out:close()
'
mv app/_data/kong_versions.yml.new app/_data/kong_versions.yml
}
#-------------------------------------------------------------------------------
function prepare_changelog() {
$LUA -e '
local fd_in = io.open("CHANGELOG.md", "r")
local fd_out = io.open("CHANGELOG.md.new", "w")
local version = "'$version'"
local state = "start"
for line in fd_in:lines() do
if state == "start" then
if line:match("^%- %[") then
fd_out:write("- [" .. version .. "](#" .. version:gsub("%.", "") .. ")\n")
state = "toc"
end
elseif state == "toc" then
if not line:match("^%- %[") then
state = "start_log"
end
elseif state == "start_log" then
fd_out:write("\n")
fd_out:write("## [" .. version .. "]\n")
fd_out:write("\n")
local today = os.date("*t")
fd_out:write(("> Released %04d/%02d/%02d\n"):format(today.year, today.month, today.day))
fd_out:write("\n")
fd_out:write("<<< TODO Introduction, plus any sections below >>>\n")
fd_out:write("\n")
fd_out:write("### Fixes\n")
fd_out:write("\n")
fd_out:write("##### Core\n")
fd_out:write("\n")
fd_out:write("##### CLI\n")
fd_out:write("\n")
fd_out:write("##### Configuration\n")
fd_out:write("\n")
fd_out:write("##### Admin API\n")
fd_out:write("\n")
fd_out:write("##### PDK\n")
fd_out:write("\n")
fd_out:write("##### Plugins\n")
fd_out:write("\n")
fd_out:write("\n")
fd_out:write("[Back to TOC](#table-of-contents)\n")
fd_out:write("\n")
state = "log"
elseif state == "log" then
local prev_version = line:match("^%[(%d+%.%d+%.%d+)%]: ")
if prev_version then
fd_out:write("[" .. version .. "]: https://github.com/Kong/kong/compare/" .. prev_version .."..." .. version .. "\n")
state = "last"
end
end
fd_out:write(line .. "\n")
end
fd_in:close()
fd_out:close()
'
mv CHANGELOG.md.new CHANGELOG.md
}
#-------------------------------------------------------------------------------
function announce() {
local version="$1.$2.$3"
if [ "$3" != "0" ]
then
patch_release_disclaimer="As a patch release, it only contains bug fixes; no new features and no breaking changes."
fi
cat <<EOF
============= USE BELOW ON KONG NATION ANNOUNCEMENT ==============
TITLE: Kong $version available!
BODY:
We’re happy to announce **Kong $version**. $patch_release_disclaimer
:package: Download [Kong $version](https://download.konghq.com) and [upgrade your cluster](https://github.com/$GITHUB_ORG/kong/blob/master/UPGRADE.md#upgrade-to-$1$2x)!
:spiral_notepad: More info and PR links are available at the [$version Changelog](https://github.com/$GITHUB_ORG/kong/blob/master/CHANGELOG.md#$1$2$3).
:whale: The updated official Docker image is available on [Docker Hub ](https://hub.docker.com/_/kong).
As always, Happy Konging! :gorilla:
============= USE BELOW ON KONG NATION ANNOUNCEMENT ==============
We’re happy to announce *Kong $version*. $patch_release_disclaimer
:package: Download Kong $version: https://download.konghq.com
:spiral_note_pad: More info and PR links are available at the $version Changelog: https://github.com/$GITHUB_ORG/kong/blob/master/CHANGELOG.md#$1$2$3
:whale: the updated official docker image is available on Docker Hub: https://hub.docker.com/_/kong
As always, happy Konging! :gorilla:
==================================================================
EOF
SUCCESS "Copy and paste this announcement in Kong Nation and Slack #general"
}
#-------------------------------------------------------------------------------
current_step=1
function step() {
box=" "
color="$nocolor"
if [ "$version" != "<x.y.z>" ]
then
if [ -e "/tmp/.step-$1-$version" ]
then
color="$green"
box="[x]"
else
color="$bold"
box="[ ]"
fi
fi
echo -e "$color $box Step $current_step) $2"
echo " $0 $version $1 $3"
echo -e "$nocolor"
current_step="$[current_step+1]"
}
#-------------------------------------------------------------------------------
function die() {
echo
echo -e "$red$bold*** $@$nocolor"
echo "See also: $0 --help"
echo
exit 1
}
#-------------------------------------------------------------------------------
function SUCCESS() {
echo
echo -e "$green$bold****************************************$nocolor$bold"
for line in "$@"
do
echo "$line"
done
echo -e "$green$bold****************************************$nocolor"
echo
touch /tmp/.step-$step-$version
exit 0
}
#-------------------------------------------------------------------------------
function CONFIRM() {
echo
echo -e "$cyan$bold----------------------------------------$nocolor$bold"
for line in "$@"
do
echo "$line"
done
echo -e "$cyan$bold----------------------------------------$nocolor"
read
}
#-------------------------------------------------------------------------------
function merge_homebrew() {
CONFIRM "The deploy robot should have sent a pull request to https://github.com/kong/homebrew-kong/pulls . " \
"Make sure it gets approved and merged. Press Enter when done"
SUCCESS "Homebrew PR merged. Proceeding!"
}
#-------------------------------------------------------------------------------
function merge_pongo() {
CONFIRM "The deploy robot should have sent a pull request to https://github.com/kong/kong-pongo/pulls . " \
"Make sure it gets approved and merged."
SUCCESS "Pongo PR merged. Proceeding!"
}
#-------------------------------------------------------------------------------
function merge_vagrant() {
CONFIRM "The release robot should have sent a PR to the kong-vagrant repo: https://github.com/$GITHUB_ORG/kong-vagrant . " \
"Make sure it gets approved and merged. Press Enter when done"
SUCCESS "Vagrant PR merged. Proceeding!"
}
#-------------------------------------------------------------------------------
function docs_pr() {
branch=$1
if [ -d ../docs.konghq.com ]
then
cd ../docs.konghq.com
else
cd ..
git clone [email protected]:$GITHUB_ORG/docs.konghq.com.git
cd docs.konghq.com
fi
git checkout main
git pull
git checkout -B "$branch"
bump_docs_kong_versions
git diff
CONFIRM "If everything looks all right, press Enter to commit and send a PR to [email protected]:$GITHUB_ORG/docs.konghq.com.git" \
"or Ctrl-C to cancel."
set -e
git add app/_data/kong_versions.yml
git commit --allow-empty -m "chore(*): update release metadata for $version"
git push --set-upstream origin "$branch"
hub pull-request -b main -h "$branch" -m "Release: $version" -l "pr/please review,pr/do not merge"
SUCCESS "Make sure you give Team Docs a heads-up" \
"once the release is pushed to the main repo." \
"When the main release PR is approved, you can proceed to:" \
" $0 $version merge"
}
#-------------------------------------------------------------------------------
function submit_release_pr() {
base=$1
branch=$2
version=$3
prerelease=$4
if ! git log -n 1 | grep -q "release: $version"
then
die "Release commit is not at the top of the current branch. Did you commit the version bump?"
fi
git log
CONFIRM "Press Enter to push the branch and open the release PR" \
"or Ctrl-C to cancel."
set -e
git push --set-upstream origin "$branch"
hub pull-request -b "$base" -h "$branch" -m "Release: $version" -l "pr/please review,pr/do not merge"
if [ "$prerelease" != "" ]
then
docs_pr_note="In the mean time, you can run the 'docs_pr' step: $0 $version docs_pr"
fi
SUCCESS "Now get the above PR reviewed and approved." \
"Once it is approved, you can continue to the 'merge' step." \
"$docs_pr_note"
}
#-------------------------------------------------------------------------------
function approve_docker() {
CONFIRM "The internal build system should have created a pull request in the docker-kong repo: " \
"https://github.com/$GITHUB_ORG/docker-kong/pulls . Make sure it gets approved before continuing " \
"to the step 'merge_docker'. Press Enter when done."
SUCCESS "Docker PR approved. Proceeding!"
}
#-------------------------------------------------------------------------------
function merge_docker() {
branch=$1
version=$2
if [ -d ../docker-kong ]
then
cd ../docker-kong
else
cd ..
git clone [email protected]:$GITHUB_ORG/docker-kong.git
cd docker-kong
fi
set -e
git checkout "$branch"
git pull
git checkout master
git pull
git merge "$branch"
git push
git tag -s "$version" -m "$version"
git push origin "$version"
make_github_release_file
hub release create -F "release-$version.txt" "$version"
rm -f release-$version.txt
SUCCESS "Now you can run the next step:" \
" $0 $version submit_docker"
}
#-------------------------------------------------------------------------------
function submit_docker() {
version=$1
if [ -d ../docker-kong ]
then
cd ../docker-kong
else
cd ..
git clone [email protected]:$GITHUB_ORG/docker-kong.git
cd docker-kong
fi
set -e
./submit.sh -m "$version"
SUCCESS "Once this is approved in the main repo," \
"run the procedure for generating the RedHat container."
}
#-------------------------------------------------------------------------------
function upload_luarock() {
rockspec=$1
luarocks_api_key=$2
if ! [ "$luarocks_api_key" ]
then
die "Kong API key for LuaRocks is required as an argument."
fi
set -e
ensure_recent_luarocks
luarocks --version
luarocks upload --temp-key="$luarocks_api_key" "$rockspec" --force
SUCCESS "The LuaRocks entry is now up!"
}
#-------------------------------------------------------------------------------
function approve_docker() {
CONFIRM "The internal build system should have created a pull request in the docker-kong repo: " \
"https://github.com/$GITHUB_ORG/docker-kong/pulls . Make sure it gets approved before continuing " \
"to the step 'merge_docker'. Press Enter when done."
SUCCESS "Docker PR approved. Proceeding!"
}
#-------------------------------------------------------------------------------
function merge_docker() {
branch=$1
version=$2
if [ -d ../docker-kong ]
then
cd ../docker-kong
else
cd ..
git clone [email protected]:$GITHUB_ORG/docker-kong.git
cd docker-kong
fi
set -e
git checkout "$branch"
git pull
git checkout master
git pull
git merge "$branch"
git push
git tag -s "$version" -m "$version"
git push origin "$version"
make_github_release_file
hub release create -F "release-$version.txt" "$version"
rm -f release-$version.txt
SUCCESS "Now you can run the next step:" \
" $0 $version submit_docker"
}
#-------------------------------------------------------------------------------
function update_docker {
if [ -d ../docker-kong ]
then
cd ../docker-kong
else
cd ..
git clone https://github.com/kong/docker-kong
cd docker-kong
fi
git pull
git checkout -B "release/$1"
set -e
./update.sh "$1"
}
#-------------------------------------------------------------------------------
function submit_docker() {
version=$1
if [ -d ../docker-kong ]
then
cd ../docker-kong
else
cd ..
git clone [email protected]:$GITHUB_ORG/docker-kong.git
cd docker-kong
fi
set -e
./submit.sh -m "$version"
SUCCESS "Once this is approved in the main repo," \
"run the procedure for generating the RedHat container."
}
#-------------------------------------------------------------------------------
function upload_luarock() {
rockspec=$1
luarocks_api_key=$2
if ! [ "$luarocks_api_key" ]
then
die "Kong API key for LuaRocks is required as an argument."
fi
set -e
ensure_recent_luarocks
luarocks --version
luarocks upload --temp-key="$luarocks_api_key" "$rockspec" --force
SUCCESS "The LuaRocks entry is now up!"
}
if resty -v &> /dev/null
then
LUA=resty
elif lua -v &> /dev/null
then
LUA=lua
else
die "Lua interpreter is not in PATH. Install any Lua or OpenResty to run this script."
fi