Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[monorepo] Fix flytectl install script #5405

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/flytectl-install.yml
Original file line number Diff line number Diff line change
@@ -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
74 changes: 59 additions & 15 deletions flytectl/install.sh
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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
Expand All @@ -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}
Expand All @@ -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
Expand All @@ -60,6 +64,7 @@ execute() {
done
rm -rf "${tmpdir}"
}

get_binaries() {
case "$PLATFORM" in
darwin/amd64) BINARIES="flytectl" ;;
Expand All @@ -75,6 +80,7 @@ get_binaries() {
;;
esac
}

tag_to_version() {
if [ -z "${TAG}" ]; then
log_info "checking GitHub for latest tag"
Expand All @@ -90,13 +96,15 @@ tag_to_version() {
TAG="$REALTAG"
VERSION=${TAG#v}
}

adjust_format() {
# change format (tar.gz or zip) based on OS
case ${OS} in
windows) FORMAT=zip ;;
esac
true
}

adjust_os() {
# adjust archive name based on OS
case ${OS} in
Expand All @@ -108,6 +116,7 @@ adjust_os() {
esac
true
}

adjust_arch() {
# adjust archive name based on ARCH
case ${ARCH} in
Expand All @@ -128,26 +137,32 @@ 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"
return
fi
[ "$1" -le "$_logp" ]
}

log_tag() {
case $1 in
0) echo "emerg" ;;
Expand All @@ -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
Expand All @@ -186,6 +206,7 @@ uname_os() {
esac
echo "$os"
}

uname_arch() {
arch=$(uname -m)
case $arch in
Expand All @@ -200,6 +221,7 @@ uname_arch() {
esac
echo ${arch}
}

uname_os_check() {
os=$(uname_os)
case "$os" in
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -325,6 +367,7 @@ hash_sha256() {
return 1
fi
}

hash_sha256_verify() {
TARGET=$1
checksums=$2
Expand All @@ -344,6 +387,7 @@ hash_sha256_verify() {
return 1
fi
}

cat /dev/null <<EOF
------------------------------------------------------------------------
End of functions from https://github.com/client9/shlib
Expand All @@ -352,7 +396,7 @@ EOF

PROJECT_NAME="flytectl"
OWNER=flyteorg
REPO="flytectl"
REPO="flyte"
BINARY=flytectl
FORMAT=tar.gz
OS=$(uname_os)
Expand All @@ -361,8 +405,9 @@ PREFIX="$OWNER/$REPO"

# use in logging routines
log_prefix() {
echo "$PREFIX"
echo "$PREFIX"
}

PLATFORM="${OS}/${ARCH}"
GITHUB_DOWNLOAD=https://github.com/${OWNER}/${REPO}/releases/download

Expand All @@ -389,5 +434,4 @@ TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL}
CHECKSUM=checksums.txt
CHECKSUM_URL=${GITHUB_DOWNLOAD}/${TAG}/${CHECKSUM}


execute
Loading