From 0583f77432a9b52b07c8289f5afee1922c51eed6 Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario <653394+eapolinario@users.noreply.github.com> Date: Thu, 23 May 2024 11:22:00 -0700 Subject: [PATCH] [monorepo] Fix flytectl install script (#5405) --- .github/workflows/flytectl-install.yml | 33 ++++++++++++ flytectl/install.sh | 74 ++++++++++++++++++++------ 2 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/flytectl-install.yml diff --git a/.github/workflows/flytectl-install.yml b/.github/workflows/flytectl-install.yml new file mode 100644 index 0000000000..f2af37f99b --- /dev/null +++ b/.github/workflows/flytectl-install.yml @@ -0,0 +1,33 @@ +name: Flytectl-specific checks + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +on: + pull_request: + paths: + - flytectl/** + push: + branches: + - master + +jobs: + install-script: + name: Install script + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + version: + - v0.8.20 + - latest + # Test the case where no version is specified + - " " + steps: + - uses: actions/checkout@v4 + - run: | + chmod +x ./flytectl/install.sh + ./flytectl/install.sh ${{ matrix.version }} + ./bin/flytectl version + diff --git a/flytectl/install.sh b/flytectl/install.sh index 3b46741391..df8ae14203 100755 --- a/flytectl/install.sh +++ b/flytectl/install.sh @@ -1,6 +1,9 @@ #!/bin/sh set -e -# Code generated by godownloader on 2021-10-24T11:29:26Z. DO NOT EDIT. +# Code generated by godownloader on 2021-10-24T11:29:26Z. +# ### WARNING +# Since godownloader is deprecated, we had to manually update the script to download the flytectl binary from the flyteorg/flyte repository. +# ### WARNING # usage() { @@ -12,7 +15,7 @@ Usage: $this [-b] bindir [-d] [tag] -b sets bindir or installation directory, Defaults to ./bin -d turns on debug logging [tag] is a tag from - https://github.com/flyteorg/flyte/flytectl/releases + https://github.com/flyteorg/flyte/releases If tag is missing, then the latest will be used. Generated by godownloader @@ -23,7 +26,7 @@ EOF } parse_args() { - #BINDIR is ./bin unless set be ENV + #BINDIR is ./bin unless set by ENV # over-ridden by flag below BINDIR=${BINDIR:-./bin} @@ -38,6 +41,7 @@ parse_args() { shift $((OPTIND - 1)) TAG=$1 } + # this function wraps all the destructive operations # if a curl|bash cuts off the end of the script due to # network, either nothing will happen or will syntax error @@ -60,6 +64,7 @@ execute() { done rm -rf "${tmpdir}" } + get_binaries() { case "$PLATFORM" in darwin/amd64) BINARIES="flytectl" ;; @@ -75,6 +80,7 @@ get_binaries() { ;; esac } + tag_to_version() { if [ -z "${TAG}" ]; then log_info "checking GitHub for latest tag" @@ -90,6 +96,7 @@ tag_to_version() { TAG="$REALTAG" VERSION=${TAG#v} } + adjust_format() { # change format (tar.gz or zip) based on OS case ${OS} in @@ -97,6 +104,7 @@ adjust_format() { esac true } + adjust_os() { # adjust archive name based on OS case ${OS} in @@ -108,6 +116,7 @@ adjust_os() { esac true } + adjust_arch() { # adjust archive name based on ARCH case ${ARCH} in @@ -128,19 +137,24 @@ https://github.com/client9/shlib/blob/master/LICENSE.md but credit (and pull requests) appreciated. ------------------------------------------------------------------------ EOF + is_command() { command -v "$1" >/dev/null } + echoerr() { echo "$@" 1>&2 } + log_prefix() { echo "$0" } + _logp=6 log_set_priority() { _logp="$1" } + log_priority() { if test -z "$1"; then echo "$_logp" @@ -148,6 +162,7 @@ log_priority() { fi [ "$1" -le "$_logp" ] } + log_tag() { case $1 in 0) echo "emerg" ;; @@ -161,22 +176,27 @@ log_tag() { *) echo "$1" ;; esac } + log_debug() { log_priority 7 || return 0 echoerr "$(log_prefix)" "$(log_tag 7)" "$@" } + log_info() { log_priority 6 || return 0 echoerr "$(log_prefix)" "$(log_tag 6)" "$@" } + log_err() { log_priority 3 || return 0 echoerr "$(log_prefix)" "$(log_tag 3)" "$@" } + log_crit() { log_priority 2 || return 0 echoerr "$(log_prefix)" "$(log_tag 2)" "$@" } + uname_os() { os=$(uname -s | tr '[:upper:]' '[:lower:]') case "$os" in @@ -186,6 +206,7 @@ uname_os() { esac echo "$os" } + uname_arch() { arch=$(uname -m) case $arch in @@ -200,6 +221,7 @@ uname_arch() { esac echo ${arch} } + uname_os_check() { os=$(uname_os) case "$os" in @@ -218,6 +240,7 @@ uname_os_check() { log_crit "uname_os_check '$(uname -s)' got converted to '$os' which is not a GOOS value. Please file bug at https://github.com/client9/shlib" return 1 } + uname_arch_check() { arch=$(uname_arch) case "$arch" in @@ -239,6 +262,7 @@ uname_arch_check() { log_crit "uname_arch_check '$(uname -m)' got converted to '$arch' which is not a GOARCH value. Please file bug report at https://github.com/client9/shlib" return 1 } + untar() { tarball=$1 case "${tarball}" in @@ -251,61 +275,79 @@ untar() { ;; esac } + http_download_curl() { local_file=$1 source_url=$2 header=$3 - if [ -z "$header" ]; then + if [ -z "$header" ];then code=$(curl -w '%{http_code}' -sL -o "$local_file" "$source_url") else code=$(curl -w '%{http_code}' -sL -H "$header" -o "$local_file" "$source_url") fi - if [ "$code" != "200" ]; then + if [ "$code" != "200" ];then log_debug "http_download_curl received HTTP status $code" return 1 fi return 0 } + http_download_wget() { local_file=$1 source_url=$2 header=$3 - if [ -z "$header" ]; then + if [ -z "$header" ];then wget -q -O "$local_file" "$source_url" else wget -q --header "$header" -O "$local_file" "$source_url" fi } + http_download() { log_debug "http_download $2" - if is_command curl; then + if is_command curl;then http_download_curl "$@" return - elif is_command wget; then + elif is_command wget;then http_download_wget "$@" return fi log_crit "http_download unable to find wget or curl" return 1 } + http_copy() { tmp=$(mktemp) http_download "${tmp}" "$1" "$2" || return 1 - body=$(cat "$tmp") + # $tmp is an array of dicts where each dict contains a tag_name. + # Assume that we can pull the tag_name out of the json using `jq`. + # We want to filter out the elements that do not have a tag_name prefixed + # with `flytectl/`. + body=$(cat "$tmp" | jq 'map(select(.tag_name | startswith("flytectl/"))) | .[].tag_name') rm -f "${tmp}" echo "$body" } + github_release() { owner_repo=$1 version=$2 test -z "$version" && version="latest" - giturl="https://github.com/${owner_repo}/releases/${version}" + giturl="https://api.github.com/repos/${owner_repo}/releases" json=$(http_copy "$giturl" "Accept:application/json") test -z "$json" && return 1 - version=$(echo "$json" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//') + if [ "$version" = "latest" ]; then + # Get the first element of the filtered json array + version=$(echo "$json" | head -n 1 | sed 's/"flytectl\///' | sed 's/"//') + else + # Get the element of the filtered json array that matches the version + version=$(echo "$json" | grep -oE '"flytectl/'"$version"'"' | sed 's/"flytectl\///' | sed 's/"//') + fi test -z "$version" && return 1 - echo "$version" + # Notice that we're prepending "flytectl/" to the found version. That prefix is part of the asset used + # to download the flytectl binary. + echo "flytectl/$version" } + hash_sha256() { TARGET=${1:-/dev/stdin} if is_command gsha256sum; then @@ -325,6 +367,7 @@ hash_sha256() { return 1 fi } + hash_sha256_verify() { TARGET=$1 checksums=$2 @@ -344,6 +387,7 @@ hash_sha256_verify() { return 1 fi } + cat /dev/null <