diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 556b8f5f7652..690f78598bf4 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -19,8 +19,6 @@ jobs: vet-proto: runs-on: ubuntu-latest timeout-minutes: 20 - env: - VET_ONLY_PROTO: 1 steps: # Setup the environment. - name: Setup Go @@ -30,15 +28,12 @@ jobs: - name: Checkout repo uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 - # Run the vet checks. - - name: vet - run: ./vet.sh -install && ./vet.sh + # Run the vet-proto checks. + - name: vet-proto + run: ./scripts/vet-proto.sh -install && ./scripts/vet-proto.sh # Run the main gRPC-Go tests. tests: - # Proto checks are run in the above job. - env: - VET_SKIP_PROTO: 1 runs-on: ubuntu-latest timeout-minutes: 20 strategy: @@ -98,7 +93,7 @@ jobs: # Only run vet for 'vet' runs. - name: Run vet.sh if: matrix.type == 'vet' - run: ./vet.sh -install && ./vet.sh + run: ./scripts/vet.sh -install && ./scripts/vet.sh # Main tests run for everything except when testing "extras" # (where we run a reduced set of tests). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 608aa6e1ac5e..0854d298e413 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,7 +66,7 @@ How to get your contributions merged smoothly and quickly. - **All tests need to be passing** before your change can be merged. We recommend you **run tests locally** before creating your PR to catch breakages early on. - - `VET_SKIP_PROTO=1 ./vet.sh` to catch vet errors + - `./scripts/vet.sh` to catch vet errors - `go test -cpu 1,4 -timeout 7m ./...` to run the tests - `go test -race -cpu 1,4 -timeout 7m ./...` to run tests in race mode diff --git a/Makefile b/Makefile index 1f8960922b3b..d54c95d8f1f1 100644 --- a/Makefile +++ b/Makefile @@ -30,10 +30,10 @@ testdeps: GO111MODULE=on go get -d -v -t google.golang.org/grpc/... vet: vetdeps - ./vet.sh + ./scripts/vet.sh vetdeps: - ./vet.sh -install + ./scripts/vet.sh -install .PHONY: \ all \ diff --git a/scripts/vet-common.sh b/scripts/vet-common.sh new file mode 100755 index 000000000000..dede0789840f --- /dev/null +++ b/scripts/vet-common.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +fail_on_output() { + tee /dev/stderr | not read +} + +# not makes sure the command passed to it does not exit with a return code of 0. +not() { + # This is required instead of the earlier (! $COMMAND) because subshells and + # pipefail don't work the same on Darwin as in Linux. + ! "$@" +} + +die() { + echo "$@" >&2 + exit 1 +} diff --git a/scripts/vet-proto.sh b/scripts/vet-proto.sh new file mode 100755 index 000000000000..26c1ac65885a --- /dev/null +++ b/scripts/vet-proto.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -ex # Exit on error; debugging enabled. +set -o pipefail # Fail a pipe if any sub-command fails. + +# - Source them sweet sweet helpers. +source "$(dirname $0)/vet-common.sh" + +# - Check to make sure it's safe to modify the user's git repo. +git status --porcelain | fail_on_output + +# - Undo any edits made by this script. +cleanup() { + git reset --hard HEAD +} +trap cleanup EXIT + +# - Installs protoc into your ${GOBIN} directory, if requested. +# ($GOBIN might not be the best place for the protoc binary, but is at least +# consistent with the place where all binaries installed by scripts in this repo +# go.) +if [[ "$1" = "-install" ]]; then + if [[ "${GITHUB_ACTIONS}" = "true" ]]; then + PROTOBUF_VERSION=25.2 # Shows up in pb.go files as v4.22.0 + PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip + pushd /home/runner/go + wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME} + unzip ${PROTOC_FILENAME} + protoc --version # Check that the binary works. + popd + else + # TODO: replace with install protoc when https://github.com/grpc/grpc-go/pull/7064 is merged. + die "-install currently intended for use in CI only." + fi + echo SUCCESS + exit 0 +elif [[ "$#" -ne 0 ]]; then + die "Unknown argument(s): $*" +fi + +# - Check that generated proto files are up to date. +go generate google.golang.org/grpc/... && git status --porcelain 2>&1 | fail_on_output || \ +(git status; git --no-pager diff; exit 1) + +echo SUCCESS +exit 0 diff --git a/vet.sh b/scripts/vet.sh similarity index 83% rename from vet.sh rename to scripts/vet.sh index fb3d443f637f..236e1ef78766 100755 --- a/vet.sh +++ b/scripts/vet.sh @@ -3,21 +3,7 @@ set -ex # Exit on error; debugging enabled. set -o pipefail # Fail a pipe if any sub-command fails. -# not makes sure the command passed to it does not exit with a return code of 0. -not() { - # This is required instead of the earlier (! $COMMAND) because subshells and - # pipefail don't work the same on Darwin as in Linux. - ! "$@" -} - -die() { - echo "$@" >&2 - exit 1 -} - -fail_on_output() { - tee /dev/stderr | not read -} +source "$(dirname $0)/vet-common.sh" # Check to make sure it's safe to modify the user's git repo. git status --porcelain | fail_on_output @@ -39,34 +25,11 @@ if [[ "$1" = "-install" ]]; then honnef.co/go/tools/cmd/staticcheck \ github.com/client9/misspell/cmd/misspell popd - if [[ -z "${VET_SKIP_PROTO}" ]]; then - if [[ "${GITHUB_ACTIONS}" = "true" ]]; then - PROTOBUF_VERSION=25.2 # a.k.a. v4.22.0 in pb.go files. - PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip - pushd /home/runner/go - wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME} - unzip ${PROTOC_FILENAME} - bin/protoc --version - popd - elif not which protoc > /dev/null; then - die "Please install protoc into your path" - fi - fi exit 0 elif [[ "$#" -ne 0 ]]; then die "Unknown argument(s): $*" fi -# - Check that generated proto files are up to date. -if [[ -z "${VET_SKIP_PROTO}" ]]; then - make proto && git status --porcelain 2>&1 | fail_on_output || \ - (git status; git --no-pager diff; exit 1) -fi - -if [[ -n "${VET_ONLY_PROTO}" ]]; then - exit 0 -fi - # - Ensure all source files contain a copyright message. # (Done in two parts because Darwin "git grep" has broken support for compound # exclusion matches.)