...
1# Copyright 2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15#!/bin/bash
16
17set -ex
18set -o pipefail
19
20readonly PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"
21
22not() {
23 ! "$@"
24}
25
26fail_on_output() {
27 tee /dev/stderr | not read
28}
29
30which go
31sudo rm -rf /usr/local/go
32case "${PLATFORM}" in
33 'linux')
34 sudo rm -rf /usr/local/go
35 curl -O https://dl.google.com/go/go1.19.12.linux-amd64.tar.gz
36 tar -xvf go1.19.12.linux-amd64.tar.gz
37 sudo mv go /usr/local
38 export GOROOT=/usr/local/go
39 export PATH=$PATH:$GOROOT/bin
40 ;;
41 'darwin')
42 sudo rm -rf /usr/local/go
43 curl -O https://dl.google.com/go/go1.19.12.darwin-amd64.tar.gz
44 tar -xvf go1.19.12.darwin-amd64.tar.gz
45 sudo mv go /usr/local
46 export GOROOT=/usr/local/go
47 export PATH="${GOROOT}/bin:${PATH}"
48 ;;
49 *)
50 echo "Using existing Go installation."
51 ;;
52esac
53
54go version
55
56# TODO(mattstev): Install goimports and run:
57# goimports -l . 2>&1 | not grep -vE "\.pb\.go"
58
59go vet -all ./... | fail_on_output
60gofmt -s -d -l . 2>&1 | fail_on_output
61go mod tidy
62
63echo SUCCESS
64
View as plain text