-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FABG-765] Fail the build if Go version is not correct
- Added new variables in ci.properties to keep eligible MIN/MAX version of go - Added new script check_version.sh to check existing go version against ci.properties - Used check_version.sh in Makefile. It stops the build if go version is not valid and prints appropriate message. Change-Id: I3843110038005175eba466cefa29e73e5e90c26a Signed-off-by: Reza Mirzeinolabedin <[email protected]>
- Loading branch information
Reza Mirzeinolabedin
committed
Sep 28, 2018
1 parent
1eb1d28
commit 0c73d46
Showing
3 changed files
with
117 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
GO_VER=1.10 | ||
GO_MIN_VER=1.10 | ||
GO_MAX_VER=1.10.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright IBM Corp, SecureKey Technologies Inc. All Rights Reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
echo "Checking Go version" | ||
go version | ||
|
||
GO_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}'` | ||
|
||
function isGoVersionValid { | ||
# Check GO_MIN_VER, it must exist in ci.properties and be valid | ||
# GO_VER must be >= GO_MIN_VER | ||
# GO_MAX_VER must be >= GO_MIN_VER | ||
GO_MIN_VER_MAJOR=`echo $GO_MIN_VER | awk -F "." '{print $1}'` | ||
if [ -z $GO_MIN_VER_MAJOR ] || [ $GO_MIN_VER_MAJOR = "" ]; then | ||
echo "ERROR: GO_MIN_VER is not specified in ci.properties properly" | ||
exit 1 | ||
fi | ||
|
||
GO_MIN_VER_MINOR=`echo $GO_MIN_VER | awk -F "." '{print $2}'` | ||
if [ -z $GO_MIN_VER_MINOR ] || [ $GO_MIN_VER_MINOR = "" ]; then | ||
echo "ERROR: GO_MIN_VER is not specified in ci.properties properly" | ||
exit 1 | ||
fi | ||
GO_MIN_VER_RELEASE=`echo $GO_MIN_VER | awk -F "." '{print $3}'` | ||
if [ -z $GO_MIN_VER_RELEASE ]; then | ||
GO_MIN_VER_RELEASE=0 | ||
fi | ||
|
||
# Check GO_MAX_VER, it must exist in ci.properties and be valid | ||
# GO_VER must be <= GO_MAX_VER | ||
# GO_MAX_VER must be >= GO_MIN_VER | ||
GO_MAX_VER_MAJOR=`echo $GO_MAX_VER | awk -F "." '{print $1}'` | ||
if [ -z $GO_MAX_VER_MAJOR ] || [ $GO_MAX_VER_MAJOR = "" ]; then | ||
echo "ERROR: GO_MAX_VER is not specified in ci.properties properly" | ||
exit 1 | ||
fi | ||
if [ $GO_MAX_VER_MAJOR -lt $GO_MIN_VER_MAJOR ]; then | ||
echo "ERROR: GO_MAX_VER (${GO_MAX_VER}) is smaller then GO_MIN_VER (${GO_MIN_VER}) in ci.properties" | ||
exit 1 | ||
fi | ||
|
||
GO_MAX_VER_MINOR=`echo $GO_MAX_VER | awk -F "." '{print $2}'` | ||
if [ -z $GO_MAX_VER_MINOR ] || [ $GO_MAX_VER_MINOR = "" ]; then | ||
echo "ERROR: GO_MAX_VER is not specified in ci.properties properly" | ||
exit 1 | ||
fi | ||
if [ $GO_MAX_VER_MAJOR -eq $GO_MIN_VER_MAJOR ] && [ $GO_MAX_VER_MINOR -lt $GO_MIN_VER_MINOR ]; then | ||
echo "ERROR: GO_MAX_VER (${GO_MAX_VER}) is smaller then GO_MIN_VER (${GO_MIN_VER}) in ci.properties" | ||
exit 1 | ||
fi | ||
|
||
GO_MAX_VER_RELEASE=`echo $GO_MAX_VER | awk -F "." '{print $3}'` | ||
if [ -z $GO_MAX_VER_RELEASE ]; then | ||
GO_MAX_VER_RELEASE=0 | ||
fi | ||
if [ $GO_MAX_VER_MAJOR -eq $GO_MIN_VER_MAJOR ] && [ $GO_MAX_VER_MINOR -eq $GO_MIN_VER_MINOR ]; then | ||
if [ $GO_MAX_VER_RELEASE -lt $GO_MIN_VER_RELEASE ]; then | ||
echo "ERROR: GO_MAX_VER (${GO_MAX_VER}) is smaller then GO_MIN_VER (${GO_MIN_VER}) in ci.properties" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
GO_MAJOR_VERSION=`go version |awk '{print $3}' | 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}'` | ||
if [ $GO_MAJOR_VERSION -eq $GO_MIN_VER_MAJOR ] && [ $GO_MINOR_VERSION -lt $GO_MIN_VER_MINOR ]; then | ||
return 1 | ||
fi | ||
if [ $GO_MAJOR_VERSION -eq $GO_MAX_VER_MAJOR ] && [ $GO_MINOR_VERSION -gt $GO_MAX_VER_MINOR ]; then | ||
return 1 | ||
fi | ||
|
||
GO_RELEASE_NO=`go version |awk '{print $3}' | awk -F "." '{print $3}'` | ||
if [ -z $GO_RELEASE_NO ]; then | ||
GO_RELEASE_NO=0 | ||
fi | ||
if [ $GO_MAJOR_VERSION -eq $GO_MIN_VER_MAJOR ] && [ $GO_MINOR_VERSION -eq $GO_MIN_VER_MINOR ]; then | ||
if [ $GO_RELEASE_NO -lt $GO_MIN_VER_RELEASE ]; then | ||
return 1 | ||
fi | ||
fi | ||
if [ $GO_MAJOR_VERSION -eq $GO_MAX_VER_MAJOR ] && [ $GO_MINOR_VERSION -eq $GO_MAX_VER_MINOR ]; then | ||
if [ $GO_RELEASE_NO -gt $GO_MAX_VER_RELEASE ]; then | ||
return 1 | ||
fi | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
if ! isGoVersionValid; then | ||
echo "You should install go ${GO_MIN_VER} to ${GO_MAX_VER} to build and run hyperledger fabric sdk/tools" | ||
exit 1 | ||
fi |