From 87fdac67c2b43dcbab10f6c463fc375e5c705a77 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Thu, 25 Oct 2018 14:13:37 +0100 Subject: [PATCH] CI: Support tests repo versions database query Refactor `get_version()` into `get_dep_from_yaml_db()` and provide a new `get_test_version()` to allow querying the versions database in the tests repo rather than the runtime one. Signed-off-by: James O. D. Hunt --- .ci/lib.sh | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/.ci/lib.sh b/.ci/lib.sh index f80d60cdac..e176b3947e 100755 --- a/.ci/lib.sh +++ b/.ci/lib.sh @@ -123,20 +123,43 @@ function install_yq() { fi } +function get_dep_from_yaml_db(){ + local versions_file="$1" + local dependency="$2" + + [ ! -f "$versions_file" ] && die "cannot find $versions_file" + + install_yq >&2 + + result=$("${GOPATH}/bin/yq" read "$versions_file" "$dependency") + [ "$result" = "null" ] && result="" + echo "$result" +} + function get_version(){ dependency="$1" GOPATH=${GOPATH:-${HOME}/go} - # This is needed in order to retrieve the version for qemu-lite - install_yq >&2 runtime_repo="github.com/kata-containers/runtime" runtime_repo_dir="$GOPATH/src/${runtime_repo}" versions_file="${runtime_repo_dir}/versions.yaml" mkdir -p "$(dirname ${runtime_repo_dir})" [ -d "${runtime_repo_dir}" ] || git clone --quiet https://${runtime_repo}.git "${runtime_repo_dir}" - [ ! -f "$versions_file" ] && { echo >&2 "ERROR: cannot find $versions_file"; exit 1; } - result=$("${GOPATH}/bin/yq" read "$versions_file" "$dependency") - [ "$result" = "null" ] && result="" - echo "$result" + + get_dep_from_yaml_db "${versions_file}" "${dependency}" +} + +function get_test_version(){ + local dependency="$1" + + local db + local cidir + + # directory of this script, not the caller + local cidir=$(dirname "${BASH_SOURCE[0]}") + + db="${cidir}/../versions.yaml" + + get_dep_from_yaml_db "${db}" "${dependency}" } function check_gopath() {