...

Text file src/cloud.google.com/go/.github/workflows/vet.sh

Documentation: cloud.google.com/go/.github/workflows

     1#!/bin/bash
     2# Copyright 2019 Google LLC
     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# Fail on any error
    17set -e
    18
    19# Display commands being run
    20set -x
    21
    22# Fail if a dependency was added without the necessary go.mod/go.sum change
    23# being part of the commit.
    24go mod tidy
    25for i in $(find . -name go.mod); do
    26  pushd $(dirname $i)
    27  go mod tidy
    28  popd
    29done
    30
    31# Documentation for the :^ pathspec can be found at:
    32# https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
    33git diff '*go.mod' :^internal/generated/snippets | tee /dev/stderr | (! read)
    34git diff '*go.sum' :^internal/generated/snippets | tee /dev/stderr | (! read)
    35
    36gofmt -s -d -l . 2>&1 | tee /dev/stderr | (! read)
    37goimports -l . 2>&1 | tee /dev/stderr | (! read)
    38
    39# Runs the linter. Regrettably the linter is very simple and does not provide the ability to exclude rules or files,
    40# so we rely on inverse grepping to do this for us.
    41#
    42# Piping a bunch of greps may be slower than `grep -vE (thing|otherthing|anotherthing|etc)`, but since we have a good
    43# amount of things we're excluding, it seems better to optimize for readability.
    44#
    45# Note: since we added the linter after-the-fact, some of the ignored errors here are because we can't change an
    46# existing interface. (as opposed to us not caring about the error)
    47golint ./... 2>&1 | (
    48  grep -vE "gen\.go" |
    49    grep -vE "receiver name [a-zA-Z]+[0-9]* should be consistent with previous receiver name" |
    50    grep -vE "exported const AllUsers|AllAuthenticatedUsers|RoleOwner|SSD|HDD|PRODUCTION|DEVELOPMENT should have comment" |
    51    grep -v "exported func Value returns unexported type pretty.val, which can be annoying to use" |
    52    grep -vE "exported func (Increment|FieldTransformIncrement|FieldTransformMinimum|FieldTransformMaximum) returns unexported type firestore.transform, which can be annoying to use" |
    53    grep -v "ExecuteStreamingSql" |
    54    grep -v "MethodExecuteSql should be MethodExecuteSQL" |
    55    grep -vE " executeStreamingSql(Min|Rnd)Time" |
    56    grep -vE " executeSql(Min|Rnd)Time" |
    57    grep -vE "pubsub\/pstest\/fake\.go.+should have comment or be unexported" |
    58    grep -vE "pubsub\/subscription\.go.+ type name will be used as pubsub.PubsubWrapper by other packages" |
    59    grep -v "ClusterId" |
    60    grep -v "InstanceId" |
    61    grep -v "firestore.arrayUnion" |
    62    grep -v "firestore.arrayRemove" |
    63    grep -v "maxAttempts" |
    64    grep -v "UptimeCheckIpIterator" |
    65    grep -vE "apiv[0-9]+" |
    66    grep -v "ALL_CAPS" |
    67    grep -v "go-cloud-debug-agent" |
    68    grep -v "mock_test" |
    69    grep -v "internal/testutil/funcmock.go" |
    70    grep -v "internal/backoff" |
    71    grep -v "internal/trace" |
    72    grep -v "internal/gapicgen/generator" |
    73    grep -v "internal/generated/snippets" |
    74    grep -v "a blank import should be only in a main or test package" |
    75    grep -v "method ExecuteSql should be ExecuteSQL" |
    76    grep -vE "spanner/spansql/(sql|types).go:.*should have comment" |
    77    grep -vE "\.pb\.go:" |
    78    grep -v "third_party/go/doc"
    79) |
    80  tee /dev/stderr | (! read)
    81
    82staticcheck -go 1.15 ./... 2>&1 | (
    83  grep -v SA1019 |
    84    grep -v go-cloud-debug-agent |
    85    grep -v internal/btree/btree.go |
    86    grep -v httpreplay/internal/proxy/debug.go |
    87    grep -v third_party/go/doc |
    88    grep -v third_party/pkgsite/synopsis.go
    89) |
    90  tee /dev/stderr | (! read)
    91
    92echo "Done vetting!"

View as plain text