Debian Codegraph @

kokoro/testutils/install_go.sh

raw
1 #!/bin/bash
2
3 # Copyright 2022 Google LLC
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 ################################################################################
17
18 # This script installs a recent version of Go into a temporary directory. The Go
19 # bin directory is then added to the PATH environment variable.
20 #
21 # NOTE: This script MUST be sourced to update the environment of the calling
22 # script.
23 #
24 # Usage instructions:
25 #
26 # source ./kokoro/testutils/install_go.sh
27
28 set -eo pipefail
29
30 readonly GO_VERSION="1.24.0"
31 readonly GO_LINUX_AMD64_SHA256="dea9ca38a0b852a74e81c26134671af7c0fbe65d81b0dc1c5bfe22cf7d4c8858"
32 readonly GO_DARWIN_AMD64_SHA256="7af054e5088b68c24b3d6e135e5ca8d91bbd5a05cb7f7f0187367b3e6e9e05ee"
33 readonly PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"
34
35 install_temp_go() {
36 local go_platform
37 local go_sha256
38 case "${PLATFORM}" in
39 "linux")
40 go_platform="linux-amd64"
41 go_sha256="${GO_LINUX_AMD64_SHA256}"
42 ;;
43 "darwin")
44 go_platform="darwin-amd64"
45 go_sha256="${GO_DARWIN_AMD64_SHA256}"
46 ;;
47 *)
48 echo "Unsupported platform, unable to install Go."
49 exit 1
50 ;;
51 esac
52 readonly go_platform
53 readonly go_sha256
54
55 local -r go_archive="go${GO_VERSION}.${go_platform}.tar.gz"
56 local -r go_url="https://go.dev/dl/${go_archive}"
57 local -r go_tmpdir=$(mktemp -dt tink-go.XXXXXX)
58 (
59 set -x
60 cd "${go_tmpdir}"
61 curl -OLsS "${go_url}"
62 # The explicit "-" to specify stdin in sha256sum is needed on MacOS sequoia
63 echo "${go_sha256} ${go_archive}" | sha256sum -c -
64 tar -xzf "${go_archive}"
65 )
66
67 export GOROOT="${go_tmpdir}/go"
68 export PATH="${go_tmpdir}/go/bin:${PATH}"
69 }
70
71 if [[ -n "${KOKORO_ARTIFACTS_DIR:-}" ]] ; then
72 install_temp_go
73 fi