github.com/pvitto98/fabric@v2.1.1+incompatible/scripts/check_go_version.sh (about)

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