From 152709e27b563bc9318685cbd071a814f27e20d0 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Wed, 15 Jan 2025 18:23:38 +0100 Subject: [PATCH 1/4] WIP: refactor release script to gh CLI --- release.sh | 58 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/release.sh b/release.sh index a378a5f8..4e9fc54d 100755 --- a/release.sh +++ b/release.sh @@ -97,6 +97,12 @@ function hub_tool() { go_run github.com/github/hub/v2@363513a "$@" } +# Convenience function to run the GitHub CLI tool `gh`. +# Parameters: $1..$n - arguments to gh. +function gh_tool() { + go install github.com/cli/cli/v2/cmd/gh@v2.65.0 +} + # Shortcut to "git push" that handles authentication. # Parameters: $1..$n - arguments to "git push ". function git_push() { @@ -193,7 +199,8 @@ function prepare_dot_release() { # Support tags in two formats # - knative-v1.0.0 # - v1.0.0 - releases="$(hub_tool release | cut -d '-' -f2)" + #releases="$(hub_tool release | cut -d '-' -f2)" + releases="$(gh release list --json tagName --jq '.[].tagName' | cut -d '-' -f2)" echo "Current releases are: ${releases}" [[ $? -eq 0 ]] || abort "cannot list releases" # If --release-branch passed, restrict to that release @@ -218,7 +225,8 @@ function prepare_dot_release() { # Ensure there are new commits in the branch, otherwise we don't create a new release setup_branch # Use the original tag (ie. potentially with a knative- prefix) when determining the last version commit sha - local github_tag="$(hub_tool release | grep "${last_version}")" + #local github_tag="$(hub_tool release | grep "${last_version}")" + local github_tag="$(gh release list --json tagName --jq '.[].tagName' | grep "${last_version}")" local last_release_commit="$(git rev-list -n 1 "${github_tag}")" local last_release_commit_filtered="$(git rev-list --invert-grep --grep "\[skip-dot-release\]" -n 1 "${github_tag}")" local release_branch_commit="$(git rev-list -n 1 upstream/"${RELEASE_BRANCH}")" @@ -239,7 +247,8 @@ function prepare_dot_release() { # If --release-notes not used, copy from the latest release if [[ -z "${RELEASE_NOTES}" ]]; then RELEASE_NOTES="$(mktemp)" - hub_tool release show -f "%b" "${github_tag}" > "${RELEASE_NOTES}" + #hub_tool release show -f "%b" "${github_tag}" > "${RELEASE_NOTES}" + gh_tool release view "${github_tag}" --json "body" --jq '.body' > "${RELEASE_NOTES}" echo "Release notes from ${last_version} copied to ${RELEASE_NOTES}" fi } @@ -640,18 +649,21 @@ function set_latest_to_highest_semver() { local last_version release_id # don't combine with assignment else $? will be 0 - last_version="$(hub_tool -p release | cut -d'-' -f2 | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+$'| sort -r -V | head -1)" + #last_version="$(hub_tool -p release | cut -d'-' -f2 | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+$'| sort -r -V | head -1)" + last_version="$(gh_tool release list --json tagName --jq '.[].tagName' | cut -d'-' -f2 | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+$'| sort -r -V | head -1)" if ! [[ $? -eq 0 ]]; then abort "cannot list releases" fi - release_id="$(hub_tool api "/repos/${ORG_NAME}/${REPO_NAME}/releases/tags/knative-${last_version}" | jq .id)" - if [[ $? -ne 0 ]]; then - abort "cannot get relase id from github" - fi +# release_id="$( api "/repos/${ORG_NAME}/${REPO_NAME}/releases/tags/knative-${last_version}" | jq .id)" +# if [[ $? -ne 0 ]]; then +# abort "cannot get relase id from github" +# fi - hub_tool api --method PATCH "/repos/${ORG_NAME}/${REPO_NAME}/releases/$release_id" \ - -F make_latest=true > /dev/null || abort "error setting $last_version to 'latest'" +# hub_tool api --method PATCH "/repos/${ORG_NAME}/${REPO_NAME}/releases/$release_id" \ +# -F make_latest=true > /dev/null || abort "error setting $last_version to 'latest'" +# + gh_tool release edit "knative-${last_version}" --latest > /dev/null || abort "error setting $last_version to 'latest'" echo "Github release ${last_version} set as 'latest'" } @@ -742,12 +754,14 @@ function publish_to_github() { local description="$(mktemp)" local attachments_dir="$(mktemp -d)" local commitish="" + local target_branch="" local github_tag="knative-${TAG}" # Copy files to a separate dir + # shellcheck disable=SC2068 for artifact in $@; do cp ${artifact} "${attachments_dir}"/ - attachments+=("--attach=${artifact}#$(basename ${artifact})") + attachments+=("${artifact}#$(basename ${artifact})") done echo -e "${title}\n" > "${description}" if [[ -n "${RELEASE_NOTES}" ]]; then @@ -774,13 +788,23 @@ function publish_to_github() { git tag -a "${github_tag}" -m "${title}" git_push tag "${github_tag}" - [[ -n "${RELEASE_BRANCH}" ]] && commitish="--commitish=${RELEASE_BRANCH}" +# [[ -n "${RELEASE_BRANCH}" ]] && commitish="--commitish=${RELEASE_BRANCH}" + [[ -n "${RELEASE_BRANCH}" ]] && target_branch="--target=${RELEASE_BRANCH}" for i in {2..0}; do - hub_tool release create \ - ${attachments[@]} \ - --file="${description}" \ - "${commitish}" \ - "${github_tag}" && return 0 +# hub_tool release create \ +# ${attachments[@]} \ +# --file="${description}" \ +# "${commitish}" \ +# "${github_tag}" && return 0 + + # shellcheck disable=SC2068 + gh_tool release create \ + "${github_tag}" \ + --title "${title}" \ + --notes-file "${description}" \ + "${target_branch}" \ + ${attachments[@]} && return 0 + if [[ "${i}" -gt 0 ]]; then echo "Error publishing the release, retrying in 15s..." sleep 15 From b3a366639d985ec127112beb5aa4c8dd9fcaa710 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Wed, 15 Jan 2025 18:28:43 +0100 Subject: [PATCH 2/4] Fix gh use through common function --- release.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/release.sh b/release.sh index 4e9fc54d..167ac2f4 100755 --- a/release.sh +++ b/release.sh @@ -200,7 +200,7 @@ function prepare_dot_release() { # - knative-v1.0.0 # - v1.0.0 #releases="$(hub_tool release | cut -d '-' -f2)" - releases="$(gh release list --json tagName --jq '.[].tagName' | cut -d '-' -f2)" + releases="$(gh_tool release list --json tagName --jq '.[].tagName' | cut -d '-' -f2)" echo "Current releases are: ${releases}" [[ $? -eq 0 ]] || abort "cannot list releases" # If --release-branch passed, restrict to that release @@ -226,7 +226,7 @@ function prepare_dot_release() { setup_branch # Use the original tag (ie. potentially with a knative- prefix) when determining the last version commit sha #local github_tag="$(hub_tool release | grep "${last_version}")" - local github_tag="$(gh release list --json tagName --jq '.[].tagName' | grep "${last_version}")" + local github_tag="$(gh_tool release list --json tagName --jq '.[].tagName' | grep "${last_version}")" local last_release_commit="$(git rev-list -n 1 "${github_tag}")" local last_release_commit_filtered="$(git rev-list --invert-grep --grep "\[skip-dot-release\]" -n 1 "${github_tag}")" local release_branch_commit="$(git rev-list -n 1 upstream/"${RELEASE_BRANCH}")" From 7a82614869295b49b645f79eb1fef6d7f697c347 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Thu, 16 Jan 2025 14:42:35 +0100 Subject: [PATCH 3/4] Remove commented and unused code --- release.sh | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/release.sh b/release.sh index 167ac2f4..243ee96a 100755 --- a/release.sh +++ b/release.sh @@ -90,13 +90,6 @@ export GOFLAGS="-ldflags=-s -ldflags=-w" export GITHUB_TOKEN="" readonly IMAGES_REFS_FILE="${IMAGES_REFS_FILE:-$(mktemp -d)/images_refs.txt}" -# Convenience function to run the hub tool. -# Parameters: $1..$n - arguments to hub. -function hub_tool() { - # Pinned to SHA because of https://github.com/github/hub/issues/2517 - go_run github.com/github/hub/v2@363513a "$@" -} - # Convenience function to run the GitHub CLI tool `gh`. # Parameters: $1..$n - arguments to gh. function gh_tool() { @@ -199,7 +192,6 @@ function prepare_dot_release() { # Support tags in two formats # - knative-v1.0.0 # - v1.0.0 - #releases="$(hub_tool release | cut -d '-' -f2)" releases="$(gh_tool release list --json tagName --jq '.[].tagName' | cut -d '-' -f2)" echo "Current releases are: ${releases}" [[ $? -eq 0 ]] || abort "cannot list releases" @@ -225,7 +217,6 @@ function prepare_dot_release() { # Ensure there are new commits in the branch, otherwise we don't create a new release setup_branch # Use the original tag (ie. potentially with a knative- prefix) when determining the last version commit sha - #local github_tag="$(hub_tool release | grep "${last_version}")" local github_tag="$(gh_tool release list --json tagName --jq '.[].tagName' | grep "${last_version}")" local last_release_commit="$(git rev-list -n 1 "${github_tag}")" local last_release_commit_filtered="$(git rev-list --invert-grep --grep "\[skip-dot-release\]" -n 1 "${github_tag}")" @@ -247,7 +238,6 @@ function prepare_dot_release() { # If --release-notes not used, copy from the latest release if [[ -z "${RELEASE_NOTES}" ]]; then RELEASE_NOTES="$(mktemp)" - #hub_tool release show -f "%b" "${github_tag}" > "${RELEASE_NOTES}" gh_tool release view "${github_tag}" --json "body" --jq '.body' > "${RELEASE_NOTES}" echo "Release notes from ${last_version} copied to ${RELEASE_NOTES}" fi @@ -649,20 +639,11 @@ function set_latest_to_highest_semver() { local last_version release_id # don't combine with assignment else $? will be 0 - #last_version="$(hub_tool -p release | cut -d'-' -f2 | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+$'| sort -r -V | head -1)" last_version="$(gh_tool release list --json tagName --jq '.[].tagName' | cut -d'-' -f2 | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+$'| sort -r -V | head -1)" if ! [[ $? -eq 0 ]]; then abort "cannot list releases" fi - -# release_id="$( api "/repos/${ORG_NAME}/${REPO_NAME}/releases/tags/knative-${last_version}" | jq .id)" -# if [[ $? -ne 0 ]]; then -# abort "cannot get relase id from github" -# fi - -# hub_tool api --method PATCH "/repos/${ORG_NAME}/${REPO_NAME}/releases/$release_id" \ -# -F make_latest=true > /dev/null || abort "error setting $last_version to 'latest'" -# + gh_tool release edit "knative-${last_version}" --latest > /dev/null || abort "error setting $last_version to 'latest'" echo "Github release ${last_version} set as 'latest'" } @@ -788,15 +769,8 @@ function publish_to_github() { git tag -a "${github_tag}" -m "${title}" git_push tag "${github_tag}" -# [[ -n "${RELEASE_BRANCH}" ]] && commitish="--commitish=${RELEASE_BRANCH}" [[ -n "${RELEASE_BRANCH}" ]] && target_branch="--target=${RELEASE_BRANCH}" for i in {2..0}; do -# hub_tool release create \ -# ${attachments[@]} \ -# --file="${description}" \ -# "${commitish}" \ -# "${github_tag}" && return 0 - # shellcheck disable=SC2068 gh_tool release create \ "${github_tag}" \ From 2edc4a1698279e24bdd9c811f73f002e56626f28 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Thu, 16 Jan 2025 15:14:39 +0100 Subject: [PATCH 4/4] Update release.sh Co-authored-by: Chris Suszynski --- release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.sh b/release.sh index 243ee96a..a9901aa3 100755 --- a/release.sh +++ b/release.sh @@ -93,7 +93,7 @@ readonly IMAGES_REFS_FILE="${IMAGES_REFS_FILE:-$(mktemp -d)/images_refs.txt}" # Convenience function to run the GitHub CLI tool `gh`. # Parameters: $1..$n - arguments to gh. function gh_tool() { - go install github.com/cli/cli/v2/cmd/gh@v2.65.0 + go_run github.com/cli/cli/v2/cmd/gh@v2.65.0 "$@" } # Shortcut to "git push" that handles authentication.