From cbf7fb2f75ad7be9d2d6a90eba245a35af0ff103 Mon Sep 17 00:00:00 2001 From: Graham Whaley Date: Tue, 30 Oct 2018 15:41:56 +0000 Subject: [PATCH 1/3] CI: travis: add yq installer script We need to have `yq` installed before we can 'make', as we now use it for a version check in the build. But, we may not have golang installed. Add a script that installs `yq` via curl'ing from the github releases. This was cloned from the function in the tests repo .ci scripts that perform the same action. Signed-off-by: Graham Whaley --- .ci/install-yq.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 .ci/install-yq.sh diff --git a/.ci/install-yq.sh b/.ci/install-yq.sh new file mode 100755 index 0000000000..12b7998bba --- /dev/null +++ b/.ci/install-yq.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env 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 +} + +# Install the yq yaml query package from the mikefarah github repo +# Install via binary download, as we may not have golang installed at this point +function install_yq() { + GOPATH=${GOPATH:-${HOME}/go} + local yq_path="${GOPATH}/bin/yq" + local yq_pkg="github.com/mikefarah/yq" + [ -x "${GOPATH}/bin/yq" ] && return + + read -r -a sysInfo <<< "$(uname -sm)" + + case "${sysInfo[0]}" in + "Linux" | "Darwin") + goos="${sysInfo[0],}" + ;; + "*") + die "OS ${sysInfo[0]} not supported" + ;; + esac + + case "${sysInfo[1]}" in + "aarch64") + goarch=arm64 + ;; + "ppc64le") + goarch=ppc64le + ;; + "x86_64") + goarch=amd64 + ;; + "s390x") + goarch=s390x + ;; + "*") + die "Arch ${sysInfo[1]} not supported" + ;; + esac + + 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_${goos}_${goarch}" + curl -o "${yq_path}" -L ${yq_url} + chmod +x ${yq_path} + + if ! command -v "${yq_path}" >/dev/null; then + die "Cannot not get ${yq_path} executable" + fi +} + +install_yq From eaa5c7a442f3bff7e7adcda1cc50e45bdae1ad27 Mon Sep 17 00:00:00 2001 From: Graham Whaley Date: Wed, 10 Oct 2018 10:30:47 +0100 Subject: [PATCH 2/3] CI: travis: call yq installer Install `yq` before running the tests. The Makefile now uses `yq` to check the golang version against the versions file. Signed-off-by: Graham Whaley --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index a6e0fd195c..c37d597889 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,10 +20,15 @@ go: env: - target_branch=$TRAVIS_BRANCH +before_install: + - sudo apt update -y -qq + - sudo apt install -y -qq curl # for yq installer + before_script: - ".ci/static-checks.sh" install: - cd ${TRAVIS_BUILD_DIR} + - ".ci/install-yq.sh" - make - sudo -E PATH=$PATH make install From 95f4fdb60352e3147a2edd11f2c1375b63d8d1c1 Mon Sep 17 00:00:00 2001 From: Graham Whaley Date: Tue, 2 Oct 2018 16:45:04 +0100 Subject: [PATCH 3/3] build: check golang version meets min req. Check that the system golang version is new enough to build with according to the data from the `versions.yaml` file. Update the verions in the versions.yaml accordingly, and add a note describing what the 'newest-version' item represents. Note, we only do a minimum requirement check, and are not checking against the 'newest-version' info from the yaml. Fixes: #148 Inspired-by: Wei Zhang Idea-by: James O. D. Hunt Signed-off-by: Graham Whaley --- Makefile | 2 ++ golang.mk | 46 ++++++++++++++++++++++++++++++++++++++++++++++ versions.yaml | 5 ++++- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 golang.mk diff --git a/Makefile b/Makefile index 4f419b9638..fa6daa757c 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,8 @@ done) GOARCH=$(shell go env GOARCH) HOST_ARCH=$(shell arch) +include golang.mk + ifeq ($(ARCH),) ARCH = $(GOARCH) endif diff --git a/golang.mk b/golang.mk new file mode 100644 index 0000000000..95259d1920 --- /dev/null +++ b/golang.mk @@ -0,0 +1,46 @@ +# +# Copyright (c) 2018 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# +# Check that the system golang version is within the required version range +# for this project. + +golang_version_min=$(shell yq r versions.yaml languages.golang.version) + +ifeq (,$(golang_version_min)) + $(error "ERROR: cannot determine minimum golang version") +endif + +golang_version_min_fields=$(subst ., ,$(golang_version_min)) + +golang_version_min_major=$(word 1,$(golang_version_min_fields)) +golang_version_min_minor=$(word 2,$(golang_version_min_fields)) + +# for error messages +golang_version_needed=$(golang_version_min_major).$(golang_version_min_minor) + +golang_version_raw=$(shell go version 2>/dev/null) + +ifeq (,$(golang_version_raw)) + $(error "ERROR: cannot determine golang version") +endif + +# determine actual version of golang +golang_version=$(subst go,,$(word 3,$(golang_version_raw))) + +golang_version_fields=$(subst ., ,$(golang_version)) + +golang_version_major=$(word 1,$(golang_version_fields)) +golang_version_minor=$(word 2,$(golang_version_fields)) + +golang_major_ok=$(shell test $(golang_version_major) -ge $(golang_version_min_major) && echo ok) +golang_minor_ok=$(shell test $(golang_version_major) -eq $(golang_version_min_major) -a $(golang_version_minor) -ge $(golang_version_min_minor) && echo ok) + +ifeq (,$(golang_major_ok)) + $(error "ERROR: golang major version too old: got $(golang_version), need atleast $(golang_version_needed)") +endif + +ifeq (,$(golang_minor_ok)) + $(error "ERROR: golang minor version too old: got $(golang_version), need atleast $(golang_version_needed)") +endif diff --git a/versions.yaml b/versions.yaml index cc26c01262..7df7144660 100644 --- a/versions.yaml +++ b/versions.yaml @@ -189,7 +189,10 @@ languages: issue: "https://github.com/golang/go/issues/20676" version: "1.10.4" meta: - newest-version: "1.11" + description: | + 'newest-version' is the latest version known to work when + building Kata + newest-version: "1.11.1" specs: description: "Details of important specifications"