forked from trustbloc/fabric-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_go_version.sh
executable file
·42 lines (34 loc) · 1017 Bytes
/
check_go_version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
#
# SPDX-License-Identifier: Apache-2.0
set -e
CI_VERSION="$(grep "GO_VER" ci.properties | cut -f2- -d'=')"
GO_VERSION="$(go version | cut -f3 -d' ' | sed -E 's/^go//')"
fail() {
>&2 echo "ERROR: ${CI_VERSION} is required to build Fabric and you are using ${GO_VERSION}. Please update go."
exit 2
}
vpos () {
local v
v="$(echo "$1" | sed -E 's/([[:digit:]]+)\.([[:digit:]]+)(\.([[:digit:]]+))?/'"\\$2"'/g')"
echo "${v:-0}"
}
version() {
vpos "$1" 1
}
release() {
vpos "$1" 2
}
patch () {
vpos "$1" 4
}
# major versions must match
[ "$(version "$GO_VERSION")" -eq "$(version "$CI_VERSION")" ] || fail
# go release must be >= ci release
[ "$(release "$GO_VERSION")" -ge "$(release "$CI_VERSION")" ] || fail
# if releases are equal, patch must be >= ci patch
if [ "$(release "$GO_VERSION")" -eq "$(release "$CI_VERSION")" ]; then
[ "$(patch "$GO_VERSION")" -ge "$(patch "$CI_VERSION")" ] || fail
fi
# versions are equal and go release > required ci release
exit 0