#!/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 PDIR=$(dirname "$scripts_folder") if ! (docker build -t kong/update-copyright ${scripts_folder} && docker run -v ${PDIR}:/workspace --rm kong/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 < 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 < /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