Relax Go patch version check
Relax version checker to warnings for Go patch version.
# SPDX-License-Identifier: Apache-2.0
#
+PROJECT_NAME="hyperledger/fabric-sdk-go"
+MAX_RELEASE_VER_FATAL=0
+
echo "Checking Go version"
-go version
+GO_VER_FULL=`go version`
+echo ${GO_VER_FULL}
+GO_VER=`echo ${GO_VER_FULL} |awk '{print $3}'`
-GO_VER=`grep GO_VER ci.properties | awk -F "=" '{print $2}'`
+GO_CI_VER=`grep GO_VER ci.properties | awk -F "=" '{print $2}'`
GO_MIN_VER=`grep GO_MIN_VER ci.properties | awk -F "=" '{print $2}'`
GO_MAX_VER=`grep GO_MAX_VER ci.properties | awk -F "=" '{print $2}'`
+ENFORCE_GO_MAX_RELEASE_VER=`grep ENFORCE_GO_MAX_RELEASE_VER ci.properties | awk -F "=" '{print $2}'`
function isGoVersionValid {
# Check GO_MIN_VER, it must exist in ci.properties and be valid
@@ -66,12 +72,12 @@ function isGoVersionValid {
fi
fi
- GO_MAJOR_VERSION=`go version |awk '{print $3}' | awk -F "." '{print substr($1,3)}'`
+ GO_MAJOR_VERSION=`echo ${GO_VER} | awk -F "." '{print substr($1,3)}'`
if [ $GO_MAJOR_VERSION -lt $GO_MIN_VER_MAJOR ] || [ $GO_MAJOR_VERSION -gt $GO_MAX_VER_MAJOR ]; then
return 1
fi
- GO_MINOR_VERSION=`go version |awk '{print $3}' | awk -F "." '{print $2}'`
+ GO_MINOR_VERSION=`echo ${GO_VER} | awk -F "." '{print $2}'`
if [ $GO_MAJOR_VERSION -eq $GO_MIN_VER_MAJOR ] && [ $GO_MINOR_VERSION -lt $GO_MIN_VER_MINOR ]; then
return 1
fi
@@ -79,7 +85,11 @@ function isGoVersionValid {
return 1
fi
- GO_RELEASE_NO=`go version |awk '{print $3}' | awk -F "." '{print $3}'`
+ return 0
+}
+
+function isGoReleaseVersionValid {
+ GO_RELEASE_NO=`echo ${GO_VER} | awk -F "." '{print $3}'`
if [ -z $GO_RELEASE_NO ]; then
GO_RELEASE_NO=0
fi
@@ -97,7 +107,23 @@ function isGoVersionValid {
return 0
}
-if ! isGoVersionValid; then
- echo "You should install go ${GO_MIN_VER} to ${GO_MAX_VER} to run hyperledger fabric sdk tests"
+function versionMismatchWarning {
+ echo "Warning: ${PROJECT_NAME} tests are validated on Go ${GO_MIN_VER} to ${GO_MAX_VER}."
+}
+
+function versionMismatchFatal {
+ echo "You should install Go ${GO_MIN_VER} to ${GO_MAX_VER} to run ${PROJECT_NAME} tests"
exit 1
+}
+
+if ! isGoVersionValid; then
+ versionMismatchFatal
+fi
+
+if ! isGoReleaseVersionValid; then
+ if [ "${ENFORCE_GO_MAX_RELEASE_VER}" = "true" ]; then
+ versionMismatchFatal
+ else
+ versionMismatchWarning
+ fi
fi
