release: Migrate update-repository-version.sh to GitHub CLI

The hub tool is deprecated. Convert this script to use the
official GitHub CLI gh instead of hub.

A couple of adjustments had to be made :
- the notes.md temporary file is moved to ${tmp_dir} in order to silent gh,
  otherwise it complains about an untracked file,
- title of a PR no longer goes to the notes.md file since gh requires the
  title to be passed with a dedicated --title option.

Fixes #8303

Signed-off-by: Greg Kurz <groug@kaod.org>
This commit is contained in:
Greg Kurz
2023-10-24 17:38:07 +02:00
parent b83a7149ee
commit e331102ba3
2 changed files with 16 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ See [the release documentation](../../../docs/Release-Process.md).
### `update-repository-version.sh` ### `update-repository-version.sh`
This script creates a GitHub pull request (a.k.a PR) to change the version in This script creates a GitHub pull request (a.k.a PR) to change the version in
all the Kata repositories. the Kata repository.
For more information on using the script, run the following: For more information on using the script, run the following:

View File

@@ -109,7 +109,8 @@ bump_repo() {
[ -n "${repo}" ] || die "repository not provided" [ -n "${repo}" ] || die "repository not provided"
[ -n "${new_version}" ] || die "no new version" [ -n "${new_version}" ] || die "no new version"
[ -n "${target_branch}" ] || die "no target branch" [ -n "${target_branch}" ] || die "no target branch"
local remote_github="https://github.com/${organization}/${repo}.git" local remote_repo="${organization}/${repo}"
local remote_github="https://github.com/${remote_repo}.git"
info "Update $repo to version $new_version" info "Update $repo to version $new_version"
info "remote: ${remote_github}" info "remote: ${remote_github}"
@@ -230,13 +231,13 @@ bump_repo() {
fi fi
info "Creating PR message" info "Creating PR message"
notes_file=notes.md local pr_title="# Kata Containers ${new_version}"
local notes_file="${tmp_dir}/notes.md"
cat <<EOF >"${notes_file}" cat <<EOF >"${notes_file}"
# Kata Containers ${new_version}
$(get_changes "$current_version") $(get_changes "$current_version")
EOF EOF
printf "%s\n\n" "${pr_title}"
cat "${notes_file}" cat "${notes_file}"
if (echo "${current_version}" | grep "alpha") && (echo "${new_version}" | grep -v "alpha");then if (echo "${current_version}" | grep "alpha") && (echo "${new_version}" | grep -v "alpha");then
@@ -253,14 +254,16 @@ EOF
git commit -s -m "${commit_msg}" git commit -s -m "${commit_msg}"
if [[ ${PUSH} == "true" ]]; then if [[ ${PUSH} == "true" ]]; then
build_hub get_gh
gh_id=$(${gh_cli} auth status --hostname github.com | awk 'match($0, /Logged in to github.com as ([^ ]+)/, line) { print substr($0, line[1, "start"], line[1, "length"]) }')
info "Forking remote" info "Forking remote"
${hub_bin} fork --remote-name=fork ${gh_cli} repo set-default "${remote_repo}"
${gh_cli} repo fork --remote --remote-name=fork
info "Push to fork" info "Push to fork"
${hub_bin} push fork -f "${branch}" git push fork -f "${branch}"
info "Create PR" info "Create PR"
out="" out=""
out=$(LC_ALL=C LANG=C "${hub_bin}" pull-request -b "${target_branch}" -F "${notes_file}" 2>&1) || echo "$out" | grep "A pull request already exists" out=$(LC_ALL=C LANG=C "${gh_cli}" pr create --base "${target_branch}" --title "${pr_title}" --body-file "${notes_file}" --head "${gh_id}:${branch}" 2>&1) || echo "$out" | grep "already exists"
fi fi
if [ "${repo}" == "kata-containers" ] && [ "${target_branch}" == "main" ] && [[ "${new_version}" =~ "rc" ]]; then if [ "${repo}" == "kata-containers" ] && [ "${target_branch}" == "main" ] && [[ "${new_version}" =~ "rc" ]]; then
@@ -272,16 +275,17 @@ EOF
info "Creating the commit message reverting the kata-deploy changes" info "Creating the commit message reverting the kata-deploy changes"
git commit --amend -s -m "${commit_msg}" git commit --amend -s -m "${commit_msg}"
echo "${commit_msg}" >"${notes_file}" pr_title=$(echo "${commit_msg}" | head -1)
echo "${commit_msg}" | tail -n +3 >"${notes_file}"
echo "" >>"${notes_file}" echo "" >>"${notes_file}"
echo "Only merge this commit after ${new_version} release is successfully tagged!" >>"${notes_file}" echo "Only merge this commit after ${new_version} release is successfully tagged!" >>"${notes_file}"
if [[ ${PUSH} == "true" ]]; then if [[ ${PUSH} == "true" ]]; then
info "Push \"${reverting_kata_deploy_changes_branch}\" to fork" info "Push \"${reverting_kata_deploy_changes_branch}\" to fork"
${hub_bin} push fork -f "${reverting_kata_deploy_changes_branch}" git push fork -f "${reverting_kata_deploy_changes_branch}"
info "Create \"${reverting_kata_deploy_changes_branch}\" PR" info "Create \"${reverting_kata_deploy_changes_branch}\" PR"
out="" out=""
out=$(LC_ALL=C LANG=C "${hub_bin}" pull-request -b "${target_branch}" -F "${notes_file}" 2>&1) || echo "$out" | grep "A pull request already exists" out=$(LC_ALL=C LANG=C "${gh_cli}" pr create --base "${target_branch}" --title "${pr_title}" --body-file "${notes_file}" --head "${gh_id}:${reverting_kata_deploy_changes_branch}" 2>&1) || echo "$out" | grep "already exists"
fi fi
fi fi