From ac19e296b66284ec6ee386ffb13e0082dcda44db Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Wed, 24 Feb 2021 13:41:56 -0800 Subject: [PATCH] switch from curl to gh --- hack/jenkins/installers/check_install_gh.sh | 27 +++++++++++++++++++++ hack/jenkins/kicbase_auto_build.sh | 22 ++++++++--------- 2 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 hack/jenkins/installers/check_install_gh.sh diff --git a/hack/jenkins/installers/check_install_gh.sh b/hack/jenkins/installers/check_install_gh.sh new file mode 100644 index 0000000000..654a416421 --- /dev/null +++ b/hack/jenkins/installers/check_install_gh.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Copyright 2021 The Kubernetes Authors All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eux -o pipefail + +echo "Installing latest version of gh" +sudo apt update +yes|sudo apt install software-properties-common +sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 +sudo apt-add-repository https://cli.github.com/packages +yes|sudo apt install gh + +echo "Authorizing bot with gh" +echo "${access_token}" | gh auth login --with-token diff --git a/hack/jenkins/kicbase_auto_build.sh b/hack/jenkins/kicbase_auto_build.sh index 1474a4fc19..97ab58ca8d 100755 --- a/hack/jenkins/kicbase_auto_build.sh +++ b/hack/jenkins/kicbase_auto_build.sh @@ -21,6 +21,9 @@ set -x yes|gcloud auth configure-docker docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PASS} +# Make sure gh is installed and configured +./hack/jenkins/installers/check_install_gh.sh + # Let's make sure we have the newest kicbase reference curl -L https://github.com/kubernetes/minikube/raw/master/pkg/drivers/kic/types.go --output types-head.go # kicbase tags are of the form VERSION-TIMESTAMP-PR, so this grep finds that TIMESTAMP in the middle @@ -30,9 +33,7 @@ CURRENT_KIC_TS=$(egrep "Version =" pkg/drivers/kic/types.go | cut -d \" -f 2 | c if [[ $HEAD_KIC_TIMESTAMP != v* ]]; then diff=$((CURRENT_KIC_TS-HEAD_KIC_TIMESTAMP)) if [[ $CURRENT_KIC_TS == v* ]] || [ $diff -lt 0 ]; then - curl -s -H "Authorization: token ${access_token}" \ - -H "Accept: application/vnd.github.v3+json" \ - -X POST -d "{\"body\": \"Hi ${ghprbPullAuthorLoginMention}, your kicbase info is out of date. Please rebase.\"}" "https://api.github.com/repos/kubernetes/minikube/issues/$ghprbPullId/comments" + gh pr comment ${ghprbPullId} --body "Hi ${ghprbPullAuthorLoginMention}, your kicbase info is out of date. Please rebase." exit 1 fi fi @@ -66,9 +67,7 @@ yes|make push-kic-base-image ec=$? if [ $ec -gt 0 ]; then if [ "$release" = false ]; then - curl -s -H "Authorization: token ${access_token}" \ - -H "Accept: application/vnd.github.v3+json" \ - -X POST -d "{\"body\": \"Hi ${ghprbPullAuthorLoginMention}, building a new kicbase image failed, please try again.\"}" "https://api.github.com/repos/kubernetes/minikube/issues/$ghprbPullId/comments" + gh pr comment ${ghprbPullId} --body "Hi ${ghprbPullAuthorLoginMention}, building a new kicbase image failed, please try again." fi exit $ec fi @@ -87,22 +86,21 @@ if [ "$release" = false ]; then # Display the message to the user message="Hi ${ghprbPullAuthorLoginMention},\\n\\nA new kicbase image is available, please update your PR with the new tag and SHA.\\nIn pkg/drivers/kic/types.go:\\n${codeblock}\\nThen run \`make generate-docs\` to update our documentation to reference the new image.\n\nAlternatively, run the following command and commit the changes:${sed_cmd}\\n" - curl -s -H "Authorization: token ${access_token}" \ - -H "Accept: application/vnd.github.v3+json" \ - -X POST -d "{\"body\": \"${message}\"}" "https://api.github.com/repos/kubernetes/minikube/issues/$ghprbPullId/comments" + gh pr comment ${ghprbPullId} --body "${message}" else # We're releasing, so open a new PR with the newly released kicbase git config user.name "minikube-bot" git config user.email "minikube-bot@google.com" - git checkout -b kicbase-release-${KIC_VERSION} + branch=kicbase-release-${KIC_VERSION} + git checkout -b ${branch} sed -i "s|Version = .*|Version = \"${KIC_VERSION}\"|;s|baseImageSHA = .*|baseImageSHA = \"${sha}\"|;s|gcrRepo = .*|gcrRepo = \"${GCR_REPO}\"|;s|dockerhubRepo = .*|dockerhubRepo = \"${DH_REPO}\"|" pkg/drivers/kic/types.go git add -A git commit -m "Update kicbase to ${KIC_VERSION}" git remote add minikube-bot git@github.com:minikube-bot/minikube.git - git push -f minikube-bot kicbase-release-${KIC_VERSION} + git push -f minikube-bot ${branch} - curl -X POST -u minikube-bot:${BOT_PASSWORD} -k -d "{\"title\": \"update kicbase to ${KIC_VERSION}\",\"head\": \"minikube-bot:kicbase-release-${KIC_VERSION}\",\"base\": \"master\"}" https://api.github.com/repos/kubernetes/minikube/pulls + gh pr create --title "Update kicbase to ${KIC_VERSION}" --base kubernetes:master --head minikube-bot:${branch} fi