forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-version-check.sh
executable file
·36 lines (30 loc) · 1.42 KB
/
go-version-check.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
#!/usr/bin/env bash
# Detect whether the installed version of Go can build this version of
# CockroachDB.
#
# To bump the required version of Go, edit the appropriate variables:
required_version_major=1
minimum_version_minor=17
go=${1-go}
if ! raw_version=$("$go" version 2>&1); then
echo "unable to detect go version: $raw_version" >&2
exit 1
fi
if ! version=$(grep -oE "[0-9]+(\.[0-9]+)+" <<< "$raw_version" | head -n1); then
echo "unable to parse go version '$raw_version'" >&2
exit 1
fi
version_major=$(cut -f1 -d. <<< "$version")
version_minor=$(cut -f2 -d. <<< "$version")
version_patch=$(cut -f3 -d. <<< "$version")
required_version_patch=$(eval echo \$minimum_version_${version_minor}_patch)
check_patch=$(if test -n "$version_patch"; then echo 1; else echo 0; fi)
if (( version_major != required_version_major )) || \
(( version_minor < minimum_version_minor )); then
echo "go$required_version_major.$minimum_version_minor+ required (detected go$version)" >&2
exit 1
elif (( check_patch == 1 && version_patch < required_version_patch )); then
minimum_version_patch=$(eval echo \$minimum_version_${minimum_version_minor}_patch)
echo "need Go patch $required_version_major.$version_minor.$required_version_patch+ when using go$required_version_major.$version_minor (detected go$version; minimum version for successful builds is go$required_version_major.$minimum_version_minor.$minimum_version_patch+)" >&2
exit 1
fi