Skip to content

Commit

Permalink
vet: split vet-proto from vet.sh (#7099)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvindbr8 authored Apr 5, 2024
1 parent 28cccf3 commit eb4e411
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 50 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
17 changes: 17 additions & 0 deletions scripts/vet-common.sh
Original file line number Diff line number Diff line change
@@ -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
}
46 changes: 46 additions & 0 deletions scripts/vet-proto.sh
Original file line number Diff line number Diff line change
@@ -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
39 changes: 1 addition & 38 deletions vet.sh → scripts/vet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.)
Expand Down

0 comments on commit eb4e411

Please sign in to comment.