Skip to content

Commit

Permalink
[FABG-765] Fail the build if Go version is not correct
Browse files Browse the repository at this point in the history
- 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 <reza.mirzeinolabedin@securekey.com>
  • Loading branch information
Reza Mirzeinolabedin committed Sep 28, 2018
1 parent 1eb1d28 commit 0c73d46
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Makefile
Expand Up @@ -235,35 +235,39 @@ export DOCKER_COMPOSE_CMD
export FABRIC_SDKGO_TESTRUN_ID

.PHONY: all
all: depend-noforce license unit-test integration-test
all: version depend-noforce license unit-test integration-test

.PHONY: version
version:
@$(TEST_SCRIPTS_PATH)/check_version.sh

.PHONY: depend
depend:
depend: version
@$(TEST_SCRIPTS_PATH)/dependencies.sh -f

.PHONY: depend-noforce
depend-noforce:
depend-noforce: version
ifeq ($(FABRIC_SDKGO_DEPEND_INSTALL),true)
@$(TEST_SCRIPTS_PATH)/dependencies.sh
endif

.PHONY: checks
checks: depend-noforce license check-dep lint
checks: version depend-noforce license check-dep lint

.PHONY: license
license:
license: version
@$(TEST_SCRIPTS_PATH)/check_license.sh

.PHONY: lint
lint: populate-noforce
lint: version populate-noforce
@LINT_CHANGED_ONLY=true $(TEST_SCRIPTS_PATH)/check_lint.sh

.PHONY: lint-all
lint-all: populate-noforce
lint-all: version populate-noforce
@$(TEST_SCRIPTS_PATH)/check_lint.sh

.PHONY: check-dep
check-dep:
check-dep: version
@dep check -skip-vendor

.PHONY: build-softhsm2-image
Expand Down
2 changes: 2 additions & 0 deletions ci.properties
@@ -1 +1,3 @@
GO_VER=1.10
GO_MIN_VER=1.10
GO_MAX_VER=1.10.4
103 changes: 103 additions & 0 deletions test/scripts/check_version.sh
@@ -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

0 comments on commit 0c73d46

Please sign in to comment.