Skip to content

Commit

Permalink
ci: use gh in install.sh for artifacts download
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Feb 2, 2023
1 parent f41d719 commit 78e8ebe
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 25 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ on:
workflow_dispatch: {}

jobs:
installer-tests:
runs-on: ubuntu-latest
steps:

- name: checkout repository
uses: actions/checkout@v3

- name: run installer script
env:
GITHUB_TOKEN: ${{ github.token }}
run: ./docs/install.sh

unit-tests:
runs-on: ubuntu-latest
steps:
Expand Down
73 changes: 48 additions & 25 deletions docs/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ BASE="kong/kubernetes-testing-framework"

echo "INFO: verifying operating system compatibility"

OSTYPE=$(uname -s)
OSTYPE=$(echo "${OSTYPE,,}") # convert to lower case
OSTYPE=$(uname -s | tr '[:upper:]' '[:lower:]')

if [ "$OSTYPE" != "linux" ]; then
if [ "$OSTYPE" != "darwin" ]; then
Expand All @@ -26,44 +25,67 @@ fi

echo "INFO: verifying cpu architecture compatibility"

ARCH=$(uname -m)
ARCH=$(echo "${ARCH,,}") # convert to lower case
ARCH=$(uname -m | tr '[:upper:]' '[:lower:]')

if [ "$ARCH" = x86_64 ]; then
ARCH="amd64"
fi
if [ "$ARCH" = aarch64 ]; then
ARCH="arm64"
fi

if [ "$ARCH" != "amd64" ]; then
if [[ "$ARCH" != "amd64" && "$ARCH" != "arm64" ]]; then
echo "Error: ${ARCH} is not a supported architecture at this time."
exit 1
fi

# ------------------------------------------------------------------------------
# Determine Latest Release
# ------------------------------------------------------------------------------
TEMPDIR=$(mktemp -d)

LATEST_RELEASE=$(curl -s https://api.github.com/repos/${BASE}/releases/latest | perl -ne 'print $1 if m{"name": "(v[0-9]+\.[0-9]+\.[0-9]+.*)"}')
function download_with_curl()
{
echo "INFO: downloading ktf via curl"

if [ "$LATEST_RELEASE" = "" ]; then
echo "Error: could not find latest release for ${BASE}!${LATEST_RELEASE}"
exit 1
fi
# ------------------------------------------------------------------------------
# Determine Latest Release
# ------------------------------------------------------------------------------

echo "INFO: the latest release of ${BASE} was determined to be ${LATEST_RELEASE}"
LATEST_RELEASE=$(curl -s https://api.github.com/repos/${BASE}/releases/latest | perl -ne 'print $1 if m{"name": "(v[0-9]+\.[0-9]+\.[0-9]+.*)"}')

# ------------------------------------------------------------------------------
# Downloading Binary & Checksums
# ------------------------------------------------------------------------------
if [ "$LATEST_RELEASE" = "" ]; then
echo "Error: could not find latest release for ${BASE}!${LATEST_RELEASE}"
exit 1
fi

DOWNLOAD_URL="https://github.com/${BASE}/releases/download/${LATEST_RELEASE}/ktf.${OSTYPE}.${ARCH}"
DOWNLOAD_CHECKSUMS_URL="https://github.com/${BASE}/releases/download/${LATEST_RELEASE}/CHECKSUMS"
TEMPDIR=$(mktemp -d)
echo "INFO: the latest release of ${BASE} was determined to be ${LATEST_RELEASE}"

# ------------------------------------------------------------------------------
# Downloading Binary & Checksums
# ------------------------------------------------------------------------------

echo "INFO: downloading ktf cli for ${OSTYPE}/${ARCH}"
curl -L --proto '=https' --tlsv1.2 -sSf ${DOWNLOAD_URL} > ${TEMPDIR}/ktf.${OSTYPE}.${ARCH}
DOWNLOAD_URL="https://github.com/${BASE}/releases/download/${LATEST_RELEASE}/ktf.${OSTYPE}.${ARCH}"
DOWNLOAD_CHECKSUMS_URL="https://github.com/${BASE}/releases/download/${LATEST_RELEASE}/CHECKSUMS"

echo "INFO: downloading checksums for release ${LATEST_RELEASE}"
curl -L --proto '=https' --tlsv1.2 -sSf ${DOWNLOAD_CHECKSUMS_URL} > ${TEMPDIR}/CHECKSUMS
echo "INFO: downloading ktf cli for ${OSTYPE}/${ARCH}"
curl -L --proto '=https' --tlsv1.2 -sSf ${DOWNLOAD_URL} > ${TEMPDIR}/ktf.${OSTYPE}.${ARCH}

echo "INFO: downloading checksums for release ${LATEST_RELEASE}"
curl -L --proto '=https' --tlsv1.2 -sSf ${DOWNLOAD_CHECKSUMS_URL} > ${TEMPDIR}/CHECKSUMS
}

function download_with_gh()
{
echo "INFO: Downloading ktf via gh"
gh release download --dir ${TEMPDIR} --pattern "ktf.${OSTYPE}.${ARCH}" --repo "${BASE}"
gh release download --dir ${TEMPDIR} --pattern "CHECKSUMS" --repo "${BASE}"
LATEST_RELEASE=$(gh release view --repo "${BASE}" --json tagName --template {{.tagName}})
}

if gh --version 2>/dev/null 1>/dev/null; then
download_with_gh
else
echo "INFO: gh not available on the system, falling back to download via curl"
download_with_curl
fi

# ------------------------------------------------------------------------------
# Checksum Verification
Expand All @@ -77,7 +99,8 @@ popd 1>/dev/null
# Installation
# ------------------------------------------------------------------------------

INSTALL_DIRECTORY="${HOME}/.local/bin/" # TODO: will make this dynamic in a later iteration
INSTALL_DIRECTORY="${HOME}/.local/bin" # TODO: will make this dynamic in a later iteration
[[ -d "${INSTALL_DIRECTORY}" ]] || mkdir -p "${INSTALL_DIRECTORY}"
INSTALL_LOCATION="${INSTALL_DIRECTORY}/ktf"

install ${TEMPDIR}/ktf.${OSTYPE}.${ARCH} ${INSTALL_LOCATION}
Expand Down

0 comments on commit 78e8ebe

Please sign in to comment.