diff --git a/.ci/scripts/install-go.bat b/.ci/scripts/install-go.bat new file mode 100644 index 00000000000..29448bd4f63 --- /dev/null +++ b/.ci/scripts/install-go.bat @@ -0,0 +1,57 @@ +set GOPATH=%WORKSPACE% +set MAGEFILE_CACHE=%WORKSPACE%\.magefile + +set PATH=%WORKSPACE%\bin;C:\ProgramData\chocolatey\bin;%PATH% + +curl --version >nul 2>&1 && ( + echo found curl +) || ( + choco install curl -y --no-progress --skipdownloadcache +) + +mkdir %WORKSPACE%\bin + +IF EXIST "%PROGRAMFILES(X86)%" ( + REM Force the gvm installation. + SET GVM_BIN=gvm.exe + curl -L -o %WORKSPACE%\bin\gvm.exe https://github.com/andrewkroh/gvm/releases/download/v0.3.0/gvm-windows-amd64.exe + IF ERRORLEVEL 1 ( + REM gvm installation has failed. + del bin\gvm.exe /s /f /q + exit /b 1 + ) +) ELSE ( + REM Windows 7 workers got a broken gvm installation. + curl -L -o %WORKSPACE%\bin\gvm.exe https://github.com/andrewkroh/gvm/releases/download/v0.3.0/gvm-windows-386.exe + IF ERRORLEVEL 1 ( + REM gvm installation has failed. + del bin\gvm.exe /s /f /q + exit /b 1 + ) +) + +SET GVM_BIN=gvm.exe +WHERE /q %GVM_BIN% +%GVM_BIN% version + +REM Install the given go version +%GVM_BIN% --debug install %GO_VERSION% + +REM Configure the given go version +FOR /f "tokens=*" %%i IN ('"%GVM_BIN%" use %GO_VERSION% --format=batch') DO %%i + +go env +IF ERRORLEVEL 1 ( + REM go is not configured correctly. + rmdir %WORKSPACE%\.gvm /s /q + exit /b 1 +) + +where mage +mage -version +IF ERRORLEVEL 1 ( + go get github.com/magefile/mage + IF ERRORLEVEL 1 ( + exit /b 1 + ) +) diff --git a/.ci/scripts/install-go.sh b/.ci/scripts/install-go.sh new file mode 100644 index 00000000000..31566c08726 --- /dev/null +++ b/.ci/scripts/install-go.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +set -exuo pipefail + +MSG="environment variable missing" +GO_VERSION=${GO_VERSION:?$MSG} +PROPERTIES_FILE=${PROPERTIES_FILE:-"go_env.properties"} +HOME=${HOME:?$MSG} +OS=$(uname -s| tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m| tr '[:upper:]' '[:lower:]') +GVM_CMD="${HOME}/bin/gvm" + +if command -v go +then + set +e + echo "Found Go. Checking version.." + FOUND_GO_VERSION=$(go version|awk '{print $3}'|sed s/go//) + if [ "$FOUND_GO_VERSION" == "$GO_VERSION" ] + then + echo "Versions match. No need to install Go. Exiting." + exit 0 + fi + set -e +fi + +if [ "${ARCH}" == "aarch64" ] ; then + GVM_ARCH_SUFFIX=arm64 +elif [ "${ARCH}" == "x86_64" ] ; then + GVM_ARCH_SUFFIX=amd64 +elif [ "${ARCH}" == "i686" ] ; then + GVM_ARCH_SUFFIX=386 +else + GVM_ARCH_SUFFIX=arm +fi + +echo "UNMET DEP: Installing Go" +mkdir -p "${HOME}/bin" + +curl -sSLo "${GVM_CMD}" "https://github.com/andrewkroh/gvm/releases/download/v0.3.0/gvm-${OS}-${GVM_ARCH_SUFFIX}" +chmod +x "${GVM_CMD}" + +${GVM_CMD} "${GO_VERSION}" |cut -d ' ' -f 2|tr -d '\"' > ${PROPERTIES_FILE} + +eval "$("${GVM_CMD}" "${GO_VERSION}")"