Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vet: split vet-proto from vet.sh #7099

Merged
merged 8 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/util.sh
arvindbr8 marked this conversation as resolved.
Show resolved Hide resolved
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
}
34 changes: 34 additions & 0 deletions scripts/vet-proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

set -ex # Exit on error; debugging enabled.
set -o pipefail # Fail a pipe if any sub-command fails.

source "$(dirname $0)/util.sh" || exit 1
arvindbr8 marked this conversation as resolved.
Show resolved Hide resolved

# - Install protoc if requested.
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}
bin/protoc --version
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)/util.sh" || exit 1

# 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
Loading