You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
2.6 KiB

  1. # Copyright 2019 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. # http://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. #!/bin/bash
  15. # Fail on error, and display commands being run.
  16. set -ex
  17. # Only run the linter on go1.12, since it needs type aliases (and we only care
  18. # about its output once).
  19. if [[ `go version` != *"go1.12"* ]]; then
  20. exit 0
  21. fi
  22. go install \
  23. golang.org/x/lint/golint \
  24. golang.org/x/tools/cmd/goimports \
  25. honnef.co/go/tools/cmd/staticcheck
  26. # Fail if a dependency was added without the necessary go.mod/go.sum change
  27. # being part of the commit.
  28. go mod tidy
  29. git diff go.mod | tee /dev/stderr | (! read)
  30. git diff go.sum | tee /dev/stderr | (! read)
  31. # Easier to debug CI.
  32. pwd
  33. # Look at all .go files (ignoring .pb.go files) and make sure they have a Copyright. Fail if any don't.
  34. git ls-files "*[^.pb].go" | xargs grep -L "\(Copyright [0-9]\{4,\}\)" 2>&1 | tee /dev/stderr | (! read)
  35. gofmt -s -d -l . 2>&1 | tee /dev/stderr | (! read)
  36. goimports -l . 2>&1 | tee /dev/stderr | (! read)
  37. # Runs the linter. Regrettably the linter is very simple and does not provide the ability to exclude rules or files,
  38. # so we rely on inverse grepping to do this for us.
  39. golint ./... 2>&1 | ( \
  40. grep -v "gen.go" | \
  41. grep -v "disco.go" | \
  42. grep -v "exported const DefaultDelayThreshold should have comment" | \
  43. grep -v "exported const DefaultBundleCountThreshold should have comment" | \
  44. grep -v "exported const DefaultBundleByteThreshold should have comment" | \
  45. grep -v "exported const DefaultBufferedByteLimit should have comment" | \
  46. grep -v "error var Done should have name of the form ErrFoo" | \
  47. grep -v "exported method APIKey.RoundTrip should have comment or be unexported" | \
  48. grep -v "exported method MarshalStyle.JSONReader should have comment or be unexported" | \
  49. grep -v "UnmarshalJSON should have comment or be unexported" | \
  50. grep -v "MarshalJSON should have comment or be unexported" | \
  51. grep -vE "\.pb\.go:" || true) | tee /dev/stderr | (! read)
  52. staticcheck -go 1.9 ./... 2>&1 | ( \
  53. grep -v "SA1019" | \
  54. grep -v "S1007" | \
  55. grep -v "error var Done should have name of the form ErrFoo" | \
  56. grep -v "examples" | \
  57. grep -v "gen.go" || true) | tee /dev/stderr | (! read)