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.
 
 
 

102 lines
4.7 KiB

  1. #!/bin/bash
  2. # Fail on any error
  3. set -eo pipefail
  4. # Display commands being run
  5. set -x
  6. # Only run the linter on go1.11, because:
  7. # - It needs type aliases (so we can't use anything less than 1.9).
  8. # - It only has to run once per CI (so we just have to pick 1 version).
  9. # - It runs out of memory in go 1.12 https://github.com/dominikh/go-tools/issues/419.
  10. if [[ `go version` != *"go1.11"* ]]; then
  11. exit 0
  12. fi
  13. go install \
  14. github.com/golang/protobuf/protoc-gen-go \
  15. golang.org/x/lint/golint \
  16. golang.org/x/tools/cmd/goimports \
  17. honnef.co/go/tools/cmd/staticcheck
  18. # Fail if a dependency was added without the necessary go.mod/go.sum change
  19. # being part of the commit.
  20. go mod tidy
  21. git diff go.mod | tee /dev/stderr | (! read)
  22. git diff go.sum | tee /dev/stderr | (! read)
  23. # Easier to debug CI.
  24. pwd
  25. # Look at all .go files (ignoring .pb.go files) and make sure they have a Copyright. Fail if any don't.
  26. git ls-files "*[^.pb].go" | xargs grep -L "\(Copyright [0-9]\{4,\}\)" 2>&1 | tee /dev/stderr | (! read)
  27. gofmt -s -d -l . 2>&1 | tee /dev/stderr | (! read)
  28. goimports -l . 2>&1 | tee /dev/stderr | (! read)
  29. # Runs the linter. Regrettably the linter is very simple and does not provide the ability to exclude rules or files,
  30. # so we rely on inverse grepping to do this for us.
  31. #
  32. # Piping a bunch of greps may be slower than `grep -vE (thing|otherthing|anotherthing|etc)`, but since we have a good
  33. # amount of things we're excluding, it seems better to optimize for readability.
  34. #
  35. # Note: since we added the linter after-the-fact, some of the ignored errors here are because we can't change an
  36. # existing interface. (as opposed to us not caring about the error)
  37. golint ./... 2>&1 | ( \
  38. grep -vE "gen\.go" | \
  39. grep -vE "receiver name [a-zA-Z]+[0-9]* should be consistent with previous receiver name" | \
  40. grep -vE "exported const AllUsers|AllAuthenticatedUsers|RoleOwner|SSD|HDD|PRODUCTION|DEVELOPMENT should have comment" | \
  41. grep -v "exported func Value returns unexported type pretty.val, which can be annoying to use" | \
  42. grep -v "ExecuteStreamingSql" | \
  43. grep -vE "pubsub\/pstest\/fake\.go.+should have comment or be unexported" | \
  44. grep -v "ClusterId" | \
  45. grep -v "InstanceId" | \
  46. grep -v "firestore.arrayUnion" | \
  47. grep -v "firestore.arrayRemove" | \
  48. grep -v "maxAttempts" | \
  49. grep -v "UptimeCheckIpIterator" | \
  50. grep -vE "apiv[0-9]+" | \
  51. grep -v "ALL_CAPS" | \
  52. grep -v "go-cloud-debug-agent" | \
  53. grep -v "mock_test" | \
  54. grep -v "internal/testutil/funcmock.go" | \
  55. grep -v "internal/backoff" | \
  56. grep -v "internal/trace" | \
  57. grep -v "a blank import should be only in a main or test package" | \
  58. grep -v "method ExecuteSql should be ExecuteSQL" | \
  59. grep -vE "\.pb\.go:" || true) | tee /dev/stderr | (! read)
  60. # TODO(deklerk) It doesn't seem like it, but is it possible to glob both before
  61. # and after the colon? Then we could do *go-cloud-debug-agent*:*
  62. staticcheck -go 1.9 -ignore '
  63. *:S1007
  64. *:SA1019
  65. cloud.google.com/go/firestore/internal/doc-snippets.go:*
  66. cloud.google.com/go/functions/metadata/metadata_test.go:SA1012
  67. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/controller/client_test.go:*
  68. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/debug/dwarf/frame.go:*
  69. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/debug/dwarf/typeunit.go:*
  70. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/debug/dwarf/const.go:*
  71. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/debug/dwarf/line.go:*
  72. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/debug/server/server.go:*
  73. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/debug/server/dwarf.go:*
  74. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/debug/server/eval.go:*
  75. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/debug/server/value.go:*
  76. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/debug/elf/file.go:*
  77. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/breakpoints/breakpoints_test.go:*
  78. cloud.google.com/go/cmd/go-cloud-debug-agent/internal/debug/gosym/pclntab_test.go:*
  79. cloud.google.com/go/cmd/go-cloud-debug-agent/debuglet.go:*
  80. cloud.google.com/go/translate/internal/translate/v2/translate-nov2016-gen.go:*
  81. cloud.google.com/go/storage/bucket.go:S1002
  82. cloud.google.com/go/spanner/value.go:S1025
  83. cloud.google.com/go/pubsub/integration_test.go:S1012
  84. cloud.google.com/go/internal/fields/fold.go:S1008
  85. cloud.google.com/go/httpreplay/internal/proxy/debug.go:*
  86. cloud.google.com/go/bigtable/internal/cbtconfig/cbtconfig.go:ST1005
  87. cloud.google.com/go/bigtable/cmd/cbt/cbt.go:ST1005
  88. cloud.google.com/go/asset/v1beta1/doc.go:*
  89. cloud.google.com/go/spanner/value_test.go:S1019
  90. cloud.google.com/go/bigtable/reader.go:S1002
  91. cloud.google.com/go/internal/btree/btree.go:U1000
  92. ' ./...