diff --git a/.ci/lib.sh b/.ci/lib.sh deleted file mode 100644 index 1802c19536..0000000000 --- a/.ci/lib.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2018 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 - -# If we fail for any reason a message will be displayed -die() { - msg="$*" - echo "ERROR: $msg" >&2 - exit 1 -} - -export tests_repo="${tests_repo:-github.com/kata-containers/tests}" -export tests_repo_dir="$GOPATH/src/$tests_repo" - -clone_tests_repo() { - # KATA_CI_NO_NETWORK is (has to be) ignored if there is - # no existing clone. - if [ -d "${tests_repo_dir}" ] && [ -n "${KATA_CI_NO_NETWORK:-}" ]; then - return - fi - - go get -d -u "$tests_repo" || true -} - -install_yq() { - path=$1 - local yq_path=${path}/yq - local yq_pkg="github.com/mikefarah/yq" - [ -x "${yq_path}" ] && return - - case "$(uname -m)" in - "aarch64") - goarch=arm64 - ;; - - "x86_64") - goarch=amd64 - ;; - - "ppc64le") - goarch=ppc64le - ;; - - "s390x") - goarch=s390x - ;; - - "*") - echo "Arch $(uname -m) not supported" - exit - ;; - esac - - mkdir -p "${path}" - - # Workaround to get latest release from github (to not use github token). - # Get the redirection to latest release on github. - yq_latest_url=$(curl -Ls -o /dev/null -w %{url_effective} "https://${yq_pkg}/releases/latest") - # The redirected url should include the latest release version - # https://github.com/mikefarah/yq/releases/tag/ - yq_version=$(basename "${yq_latest_url}") - - local yq_url="https://${yq_pkg}/releases/download/${yq_version}/yq_linux_${goarch}" - curl -o "${yq_path}" -L ${yq_url} - chmod +x ${yq_path} -} diff --git a/.ci/run.sh b/.ci/run.sh index 14860612bb..8886fcdb6e 100755 --- a/.ci/run.sh +++ b/.ci/run.sh @@ -10,7 +10,7 @@ set -o nounset set -o pipefail cidir=$(dirname "$0") -source "${cidir}/lib.sh" +source "${cidir}/../scripts/lib.sh" source /etc/os-release pushd "${tests_repo_dir}" diff --git a/.ci/test.sh b/.ci/test.sh index 1ef22b3297..deccdc632f 100755 --- a/.ci/test.sh +++ b/.ci/test.sh @@ -11,7 +11,7 @@ set -o pipefail CI=${CI:-} script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly toplevel_mk="${script_dir}/../Makefile" -source "${script_dir}/lib.sh" +source "${script_dir}/../scripts/lib.sh" make_target() { target=$1 diff --git a/Makefile b/Makefile index 24e8a5e3fc..db05f6894e 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ test-packaging-tools: @$(MK_DIR)/obs-packaging/build_from_docker.sh $(YQ): - @bash -c "source .ci/lib.sh; install_yq $${MK_DIR}" + @bash -c "source scripts/lib.sh; install_yq $${MK_DIR}" $(VERSION_FILE): @curl -sO $(VERSION_FILE_URL) diff --git a/scripts/lib.sh b/scripts/lib.sh index 7797c2ddb7..847de76f35 100644 --- a/scripts/lib.sh +++ b/scripts/lib.sh @@ -1,33 +1,31 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2018-2020 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# + export GOPATH=${GOPATH:-${HOME}/go} -kata_arch_sh="${GOPATH}/src/github.com/kata-containers/tests/.ci/kata-arch.sh" +export tests_repo="${tests_repo:-github.com/kata-containers/tests}" +export tests_repo_dir="$GOPATH/src/$tests_repo" + hub_bin="hub-bin" -get_kata_arch() { - go get -u github.com/kata-containers/tests || true - [ -f "${kata_arch_sh}" ] || die "Not found $kata_arch_sh" +clone_tests_repo() { + # KATA_CI_NO_NETWORK is (has to be) ignored if there is + # no existing clone. + if [ -d "${tests_repo_dir}" ] && [ -n "${KATA_CI_NO_NETWORK:-}" ]; then + return + fi + + go get -d -u "$tests_repo" || true } install_yq() { - GOPATH=${GOPATH:-${HOME}/go} - local yq_path="${GOPATH}/bin/yq" - local yq_pkg="github.com/mikefarah/yq" - [ -x "${GOPATH}/bin/yq" ] && return - - get_kata_arch - goarch=$("${kata_arch_sh}" -g) - - mkdir -p "${GOPATH}/bin" - - # Workaround to get latest release from github (to not use github token). - # Get the redirection to latest release on github. - yq_latest_url=$(curl -Ls -o /dev/null -w %{url_effective} "https://${yq_pkg}/releases/latest") - # The redirected url should include the latest release version - # https://github.com/mikefarah/yq/releases/tag/ - yq_version=$(basename "${yq_latest_url}") - - local yq_url="https://${yq_pkg}/releases/download/${yq_version}/yq_linux_${goarch}" - curl -o "${yq_path}" -L "${yq_url}" - chmod +x "${yq_path}" + clone_tests_repo + pushd "$tests_repo_dir" + .ci/install_yq.sh + popd } get_from_kata_deps() {