diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 44a875eb2b..b45cc6dadb 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -167,9 +167,6 @@ jobs: asc="${tarball}.asc" curl -sSLO "${download_url}/${tarball}" curl -sSLO "${download_url}/${asc}" - # "-m" option should be empty to re-use the existing release title - # without opening a text editor. - # For the details, check https://hub.github.com/hub-release.1.html. gh release upload "${tag}" "${tarball}" gh release upload "${tag}" "${asc}" popd diff --git a/tools/packaging/release/README.md b/tools/packaging/release/README.md index 3f17f238d6..f564bd6d38 100644 --- a/tools/packaging/release/README.md +++ b/tools/packaging/release/README.md @@ -14,7 +14,7 @@ See [the release documentation](../../../docs/Release-Process.md). ### `update-repository-version.sh` 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: @@ -43,7 +43,4 @@ After Kata Containers repository is updated with a new version, it needs to be tagged. The `tag_repos.sh` script is used to create tags for the Kata Containers repository. -The script creates an **annotated tag** for the new release version for the -following repositories: - -- kata-containers +The script creates an **annotated tag** for the new release version. diff --git a/tools/packaging/release/tag_repos.sh b/tools/packaging/release/tag_repos.sh index e2e104a65b..ece0cd561d 100755 --- a/tools/packaging/release/tag_repos.sh +++ b/tools/packaging/release/tag_repos.sh @@ -115,7 +115,6 @@ tag_repos() { for repo in "${repos[@]}"; do git clone --quiet "https://github.com/${OWNER}/${repo}.git" pushd "${repo}" >>/dev/null - git remote set-url --push origin "git@github.com:${OWNER}/${repo}.git" git fetch origin git checkout "${branch}" version_from_file=$(cat ./VERSION) @@ -150,9 +149,13 @@ tag_repos() { push_tags() { info "Pushing tags to repos" - build_hub + get_gh for repo in "${repos[@]}"; do pushd "${repo}" >>/dev/null + ${gh_cli} repo set-default "${OWNER}/${repo}" + if [ $(${gh_cli} config get git_protocol) = ssh ]; then + git remote set-url --push origin "git@github.com:${OWNER}/${repo}.git" + fi tag="$kata_version" if [[ "packaging" == "${repo}" ]];then ktag="${tag}-kernel-config" @@ -175,13 +178,15 @@ create_github_release() { tag=${2:-} [ -d "${repo_dir}" ] || die "No repository directory" [ -n "${tag}" ] || die "No tag specified" - if ! "${hub_bin}" release show "${tag}"; then + if ! "${gh_cli}" release view "${tag}"; then info "Creating Github release" if [[ "$tag" =~ "-rc" ]]; then rc_args="-p" fi rc_args=${rc_args:-} - "${hub_bin}" -C "${repo_dir}" release create ${rc_args} -m "${PROJECT} ${tag}" "${tag}" + pushd "${repo_dir}" + "${gh_cli}" release create ${rc_args} --title "${PROJECT} ${tag}" "${tag}" --notes "" + popd else info "Github release already created" fi diff --git a/tools/packaging/release/update-repository-version.sh b/tools/packaging/release/update-repository-version.sh index e9aa29fa73..d9509dca1a 100755 --- a/tools/packaging/release/update-repository-version.sh +++ b/tools/packaging/release/update-repository-version.sh @@ -13,7 +13,8 @@ readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly script_name="$(basename "${BASH_SOURCE[0]}")" readonly tmp_dir=$(mktemp -t -d pr-bump.XXXX) -readonly organization="kata-containers" +OWNER="${OWNER:-kata-containers}" +readonly organization="$OWNER" PUSH="false" GOPATH=${GOPATH:-${HOME}/go} @@ -108,7 +109,8 @@ bump_repo() { [ -n "${repo}" ] || die "repository not provided" [ -n "${new_version}" ] || die "no new version" [ -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 "remote: ${remote_github}" @@ -229,13 +231,13 @@ bump_repo() { fi info "Creating PR message" - notes_file=notes.md + local pr_title="# Kata Containers ${new_version}" + local notes_file="${tmp_dir}/notes.md" cat <"${notes_file}" -# Kata Containers ${new_version} - $(get_changes "$current_version") EOF + printf "%s\n\n" "${pr_title}" cat "${notes_file}" if (echo "${current_version}" | grep "alpha") && (echo "${new_version}" | grep -v "alpha");then @@ -252,14 +254,16 @@ EOF git commit -s -m "${commit_msg}" 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" - ${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" - ${hub_bin} push fork -f "${branch}" + git push fork -f "${branch}" info "Create PR" 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 if [ "${repo}" == "kata-containers" ] && [ "${target_branch}" == "main" ] && [[ "${new_version}" =~ "rc" ]]; then @@ -271,16 +275,17 @@ EOF info "Creating the commit message reverting the kata-deploy changes" 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 "Only merge this commit after ${new_version} release is successfully tagged!" >>"${notes_file}" if [[ ${PUSH} == "true" ]]; then 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" 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 diff --git a/tools/packaging/scripts/lib.sh b/tools/packaging/scripts/lib.sh index 0bd873721f..7e8fe05275 100644 --- a/tools/packaging/scripts/lib.sh +++ b/tools/packaging/scripts/lib.sh @@ -15,7 +15,7 @@ export repo_root_dir="$(cd "${this_script_dir}/../../../" && pwd)" short_commit_length=10 -hub_bin="hub-bin" +gh_cli="gh-cli" #for cross build CROSS_BUILD=${CROSS_BUILD-:} @@ -60,26 +60,6 @@ get_repo_hash() { popd >>/dev/null } -build_hub() { - info "Get hub" - - if cmd=$(command -v hub); then - hub_bin="${cmd}" - return - else - hub_bin="${tmp_dir:-/tmp}/hub-bin" - fi - - local hub_repo="github.com/github/hub" - local hub_repo_dir="${GOPATH}/src/${hub_repo}" - [ -d "${hub_repo_dir}" ] || git clone --quiet --depth 1 "https://${hub_repo}.git" "${hub_repo_dir}" - pushd "${hub_repo_dir}" >>/dev/null - git checkout master - git pull - ./script/build -o "${hub_bin}" - popd >>/dev/null -} - arch_to_golang() { local -r arch="$1" @@ -93,6 +73,22 @@ arch_to_golang() esac } +get_gh() { + info "Get gh" + + if cmd=$(command -v gh); then + gh_cli="${cmd}" + return + else + gh_cli="${tmp_dir:-/tmp}/gh-cli" + fi + + local goarch=$(arch_to_golang $(uname -m)) + curl -sSL https://github.com/cli/cli/releases/download/v2.37.0/gh_2.37.0_linux_${goarch}.tar.gz | tar -xz + mv gh_2.37.0_linux_${goarch}/bin/gh "${gh_cli}" + rm -rf gh_2.37.0_linux_amd64 +} + get_kata_hash() { repo=$1 ref=$2