github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/build/go-version-check.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Detect whether the installed version of Go can build this version of
     4  # CockroachDB.
     5  #
     6  # To bump the required version of Go, edit the appropriate variables:
     7  
     8  required_version_major=1
     9  minimum_version_minor=13
    10  minimum_version_13_patch=4
    11  
    12  go=${1-go}
    13  
    14  if ! raw_version=$("$go" version 2>&1); then
    15    echo "unable to detect go version: $raw_version" >&2
    16    exit 1
    17  fi
    18  
    19  if ! version=$(grep -oE "[0-9]+(\.[0-9]+)+" <<< "$raw_version" | head -n1); then
    20    echo "unable to parse go version '$raw_version'" >&2
    21    exit 1
    22  fi
    23  
    24  version_major=$(cut -f1 -d. <<< "$version")
    25  version_minor=$(cut -f2 -d. <<< "$version")
    26  version_patch=$(cut -f3 -d. <<< "$version")
    27  required_version_patch=$(eval echo \$minimum_version_${version_minor}_patch)
    28  check_patch=$(if test -n "$version_patch"; then echo 1; else echo 0; fi)
    29  if (( version_major != required_version_major )) || \
    30       (( version_minor < minimum_version_minor )); then
    31    echo "go$required_version_major.$minimum_version_minor+ required (detected go$version)" >&2
    32    exit 1
    33  elif (( check_patch == 1 && version_patch < required_version_patch )); then
    34    minimum_version_patch=$(eval echo \$minimum_version_${minimum_version_minor}_patch)
    35    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
    36    exit 1
    37  fi