Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate github cli from hub to gh (hub is deprecated)
Browse files Browse the repository at this point in the history
see annoncement actions/runner-images#8362

Signed-off-by: Vincent Gramer <[email protected]>
vgramer committed Feb 7, 2024
1 parent 2db8a03 commit 9b82213
Showing 5 changed files with 14 additions and 20 deletions.
2 changes: 0 additions & 2 deletions .github/release-notes-pr-description.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Update changelog

# Description
This PR is generated by the GitHub action and automatically updated when
Pr(s) are merged on master.
8 changes: 2 additions & 6 deletions .github/workflows/release_and_pulbish_plugin_on_tag.yml
Original file line number Diff line number Diff line change
@@ -58,15 +58,11 @@ jobs:

- name: create or update release note PR
env:
# Required for the `hub` CLI
# Required for the `gh` CLI
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${GITHUB_REF/refs\/tags\//}"
echo -e "${VERSION}\n" > gh_release_description.md
sed -e '0,/Release notes for v/d' -e '/Release notes for v/,$d' CHANGELOG.md >> gh_release_description.md
assets=''
for file in $(ls ./artifacts/); do assets="${assets} -a ./artifacts/${file}"; done
echo "assets=${assets}"
hub release create -F gh_release_description.md ${assets} "${VERSION}"
gh release create -F gh_release_description.md "${VERSION}" ./artifacts/*.zip
12 changes: 6 additions & 6 deletions hack/create_or_update_release_notes_pr.sh
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
# This script is intended to be run in github action but can run in local.
# The following requirements must be satisfied:
# * same requirement as hack/generate_release_notes.sh
# * the github cli: hub must be installed (https://hub.github.com/)
# * the github cli: gh must be installed (https://cli.github.com/)
########################################################################################################################

set -o errexit
@@ -18,20 +18,20 @@ set -o pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
source "${ROOT}/hack/util.sh"

util::require-hub
util::require-gh

release_note_branch='update-release-notes'
base_branch='master'
pr_number="$(hub pr list -h update-release-notes --format '%I')"
pr_number="$(gh pr list -H update-release-notes --limit 1 --json number --jq '.[].number')"

if [[ -z "${pr_number}" ]]; then
pr_exist=false
echo "release notes pr does note already exist"
git checkout -b "${release_note_branch}"
else
pr_exist=true
echo "release notes pr already exist (#pr_number)"
hub pr checkout "${pr_number}"
echo "release notes pr already exist (pr_number=${pr_number})"
gh pr checkout "${pr_number}"
git reset --hard "${base_branch}"
fi

@@ -68,5 +68,5 @@ git push origin "${release_note_branch}" -f

if [[ "${pr_exist}" == false ]]; then
echo "create release note PR"
hub pull-request --base master --head "${release_note_branch}" --file "${ROOT}/.github/release-notes-pr-description.md"
gh pr create --base master --head "${release_note_branch}" --title "Update changelog" --body-file "${ROOT}/.github/release-notes-pr-description.md"
fi
6 changes: 3 additions & 3 deletions hack/generate_release_notes.sh
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
# This script is intended to be run in github action but can run in local.
#
# The following tools must be installed and be in the PATH
# * hub: the github cli (https://hub.github.com/)
# * gh: the github cli (https://cli.github.com/)
# * release-notes: the k8s release-notes-generator tools (https://github.com/kubernetes/release#release-notes)
# can be install thanks to go get command:
# GO111MODULE=on go get k8s.io/release/cmd/release-notes@<version>
@@ -51,7 +51,7 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
source "${ROOT}/hack/util.sh"

function check_environment() {
util::require-hub
util::require-gh
util::command_exists "release-notes" || util::fatal 'release-notes not found in path. Please install it before running script. "GO111MODULE=on go get k8s.io/release/cmd/release-notes@<version>"'

set +o nounset
@@ -74,7 +74,7 @@ check_environment
echo "org=${org} repo=${repo}"

# format '%pI %T%n' -> "publish_date_ISO_8601 tag\n". eg:2 021-03-24T20:10:00Z v3.0.0
last_release_tag="$(hub release -f '%pI %T%n' | sort -nr | head -1 | cut -d ' ' -f 2)"
last_release_tag="$(gh api -t '{{.tag_name}}' -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "/repos/${org}/${repo}/releases/latest")"

if [[ -z "${last_release_tag}" ]]; then
echo "no release found on repository. fallback to first commit"
6 changes: 3 additions & 3 deletions hack/util.sh
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ function util::fatal() {
exit 1
}

# Check "hub" command exist and exit with error message if does not.
function util::require-hub() {
util::command_exists "hub" || util::fatal 'hub not found in path. please install it before running script. see instruction at https://hub.github.com/'
# Check "gh" command exist and exit with error message if does not.
function util::require-gh() {
util::command_exists "gh" || util::fatal 'gh not found in path. please install it before running script. see instruction at https://cli.github.com/'
}

0 comments on commit 9b82213

Please sign in to comment.