github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/hack/build/setup-go.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2021 The Kubernetes Authors.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  # script to setup go version with gimme as needed
    17  # Ensure running from root dir
    18  REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
    19  trap "popd >/dev/null 2>&1" EXIT
    20  pushd "${REPO_ROOT}" >/dev/null 2>&1
    21  
    22  # read go-version file unless GO_VERSION is set
    23  GO_VERSION="${GO_VERSION:-"$(cat .go-version)"}"
    24  
    25  # we don't actually care where the .env files are
    26  # however, GIMME_SILENT_ENV doesn't trigger re-generating a .env if it
    27  # already exists and isn't "silent" (no `go version` command in it)
    28  # so we fix that by changing where the .env is written, ensuring ours
    29  # is generated from this repo and silent.
    30  export GIMME_ENV_PREFIX=./_bin/.gimme/
    31  export GIMME_SILENT_ENV=y
    32  
    33  # only setup go if we haven't set FORCE_HOST_GO, or `go version` doesn't match
    34  # go version output looks like:
    35  # go version go1.14.5 darwin/amd64
    36  if ! ([ -n "${FORCE_HOST_GO:-}" ] || \
    37        (command -v go >/dev/null && [ "$(go version | cut -d' ' -f3)" = "go${GO_VERSION}" ])); then
    38      # eval because the output of this is shell to set PATH etc.
    39      eval "$(hack/third_party/gimme/gimme "${GO_VERSION}")"
    40  fi
    41  
    42  # force go modules
    43  export GO111MODULE=on
    44