snapshot of https://github.com/grpc/grpc-go.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Testing / vet-proto (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
Stale bot / stale (push) Failing after 1s
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Testing / vet-proto (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
Stale bot / stale (push) Failing after 1s
This commit is contained in:
24
scripts/common.sh
Executable file
24
scripts/common.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/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.
|
||||
! "$@"
|
||||
}
|
||||
|
||||
# noret_grep will return 0 if zero or more lines were selected, and >1 if an
|
||||
# error occurred. Suppresses grep's return code of 1 when there are no matches
|
||||
# (for eg, empty file).
|
||||
noret_grep() {
|
||||
grep "$@" || [[ $? == 1 ]]
|
||||
}
|
||||
|
||||
die() {
|
||||
echo "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
23
scripts/gen-deps.sh
Executable file
23
scripts/gen-deps.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e # Exit on error
|
||||
set -o pipefail # Fail a pipe if any sub-command fails.
|
||||
|
||||
source "$(dirname $0)/common.sh"
|
||||
|
||||
if [[ "$#" -ne 1 || ! -d "$1" ]]; then
|
||||
echo "Specify a valid output directory as the first parameter."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPTS_DIR="$(dirname "$0")"
|
||||
OUTPUT_DIR="$1"
|
||||
|
||||
cd "${SCRIPTS_DIR}/.."
|
||||
|
||||
git ls-files -- '*.go' | grep -v '\(^\|/\)\(internal\|examples\|benchmark\|interop\|test\|testdata\)\(/\|$\)' | xargs dirname | sort -u | while read d; do
|
||||
pushd "$d" > /dev/null
|
||||
pkg="$(echo "$d" | sed 's;\.;grpc;' | sed 's;/;_;g')"
|
||||
go list -deps . | sort | noret_grep -v 'google.golang.org/grpc' >| "${OUTPUT_DIR}/$pkg"
|
||||
popd > /dev/null
|
||||
done
|
||||
94
scripts/install-protoc.sh
Executable file
94
scripts/install-protoc.sh
Executable file
@@ -0,0 +1,94 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2024 gRPC authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# install-protoc.sh
|
||||
#
|
||||
# This script installs the Protocol Buffers compiler (protoc) to the specified
|
||||
# directory. It is used to generate code from .proto files for gRPC
|
||||
# communication. The script downloads the protoc binary from the official GitHub
|
||||
# repository and installs it in the system.
|
||||
#
|
||||
# Usage: ./install-protoc.sh INSTALL_PATH
|
||||
#
|
||||
# Arguments:
|
||||
# INSTALL_PATH: The path where the protoc binary will be installed.
|
||||
#
|
||||
# Note: This script requires internet connectivity to download the protoc binary.
|
||||
|
||||
set -eu -o pipefail
|
||||
|
||||
source "$(dirname $0)/common.sh"
|
||||
|
||||
# The version of protoc that will be installed.
|
||||
PROTOC_VERSION="27.1"
|
||||
|
||||
main() {
|
||||
if [[ "$#" -ne 1 ]]; then
|
||||
die "Usage: $0 INSTALL_PATH"
|
||||
fi
|
||||
|
||||
INSTALL_PATH="${1}"
|
||||
|
||||
if [[ ! -d "${INSTALL_PATH}" ]]; then
|
||||
die "INSTALL_PATH (${INSTALL_PATH}) does not exist."
|
||||
fi
|
||||
|
||||
echo "Installing protoc version $PROTOC_VERSION to ${INSTALL_PATH}..."
|
||||
|
||||
# Detect the hardware platform.
|
||||
case "$(uname -m)" in
|
||||
"x86_64") ARCH="x86_64";;
|
||||
"aarch64") ARCH="aarch_64";;
|
||||
"arm64") ARCH="aarch_64";;
|
||||
*) die "Install unsuccessful. Hardware platform not supported by installer: $1";;
|
||||
esac
|
||||
|
||||
# Detect the Operating System.
|
||||
case "$(uname -s)" in
|
||||
"Darwin") OS="osx";;
|
||||
"Linux") OS="linux";;
|
||||
*) die "Install unsuccessful. OS not supported by installer: $2";;
|
||||
esac
|
||||
|
||||
# Check if the protoc binary with the right version is already installed.
|
||||
if [[ -f "${INSTALL_PATH}/bin/protoc" ]]; then
|
||||
if [[ "$("${INSTALL_PATH}/bin/protoc" --version)" == "libprotoc ${PROTOC_VERSION}" ]]; then
|
||||
echo "protoc version ${PROTOC_VERSION} is already installed in ${INSTALL_PATH}"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
DOWNLOAD_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${OS}-${ARCH}.zip"
|
||||
|
||||
# -L follows redirects.
|
||||
# -O writes output to a file.
|
||||
curl -LO "${DOWNLOAD_URL}"
|
||||
|
||||
# Unzip the downloaded file and except readme.txt.
|
||||
# The file structure should look like:
|
||||
# INSTALL_PATH
|
||||
# ├── bin
|
||||
# │ └── protoc
|
||||
# └── include
|
||||
# └── other files...
|
||||
unzip "protoc-${PROTOC_VERSION}-${OS}-${ARCH}.zip" -d "${INSTALL_PATH}" -x "readme.txt"
|
||||
rm "protoc-${PROTOC_VERSION}-${OS}-${ARCH}.zip"
|
||||
|
||||
# Make the protoc binary executable. ¯\_(ツ)_/¯ crazy, right?
|
||||
chmod +x "${INSTALL_PATH}/bin/protoc"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
131
scripts/regenerate.sh
Executable file
131
scripts/regenerate.sh
Executable file
@@ -0,0 +1,131 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2020 gRPC authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set -eu -o pipefail
|
||||
|
||||
WORKDIR="/tmp/grpc-go-tools"
|
||||
mkdir -p "${WORKDIR}"
|
||||
|
||||
"$(dirname "${0}")"/install-protoc.sh ${WORKDIR}
|
||||
|
||||
export GOBIN="${WORKDIR}"/bin
|
||||
export PATH="${GOBIN}:${PATH}"
|
||||
mkdir -p "${GOBIN}"
|
||||
|
||||
echo "removing existing generated files..."
|
||||
# grpc_testing_not_regenerated/*.pb.go is not re-generated,
|
||||
# see grpc_testing_not_regenerated/README.md for details.
|
||||
find . -name '*.pb.go' | grep -v 'grpc_testing_not_regenerated' | xargs rm -f || true
|
||||
|
||||
echo "Executing: go install google.golang.org/protobuf/cmd/protoc-gen-go..."
|
||||
(cd test/tools && go install google.golang.org/protobuf/cmd/protoc-gen-go)
|
||||
|
||||
echo "Executing: go install cmd/protoc-gen-go-grpc..."
|
||||
(cd cmd/protoc-gen-go-grpc && go install .)
|
||||
|
||||
echo "Pulling protos from https://github.com/grpc/grpc-proto..."
|
||||
if [ -d "${WORKDIR}/grpc-proto" ]; then
|
||||
(cd "${WORKDIR}/grpc-proto" && git pull)
|
||||
else
|
||||
git clone --quiet https://github.com/grpc/grpc-proto "${WORKDIR}/grpc-proto"
|
||||
fi
|
||||
|
||||
echo "Pulling protos from https://github.com/protocolbuffers/protobuf..."
|
||||
if [ -d "${WORKDIR}/protobuf" ]; then
|
||||
(cd "${WORKDIR}/protobuf" && git pull)
|
||||
else
|
||||
git clone --quiet https://github.com/protocolbuffers/protobuf "${WORKDIR}/protobuf"
|
||||
fi
|
||||
|
||||
# Pull in code.proto as a proto dependency
|
||||
mkdir -p "${WORKDIR}/googleapis/google/rpc"
|
||||
echo "Pulling code.proto from https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto..."
|
||||
curl --silent https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto > "${WORKDIR}/googleapis/google/rpc/code.proto"
|
||||
|
||||
|
||||
mkdir -p "${WORKDIR}/out"
|
||||
|
||||
# Generates sources without the embed requirement
|
||||
LEGACY_SOURCES=(
|
||||
"${WORKDIR}/grpc-proto/grpc/binlog/v1/binarylog.proto"
|
||||
"${WORKDIR}/grpc-proto/grpc/channelz/v1/channelz.proto"
|
||||
"${WORKDIR}/grpc-proto/grpc/health/v1/health.proto"
|
||||
"${WORKDIR}/grpc-proto/grpc/lb/v1/load_balancer.proto"
|
||||
profiling/proto/service.proto
|
||||
"${WORKDIR}/grpc-proto/grpc/reflection/v1alpha/reflection.proto"
|
||||
"${WORKDIR}/grpc-proto/grpc/reflection/v1/reflection.proto"
|
||||
)
|
||||
|
||||
# Generates only the new gRPC Service symbols
|
||||
SOURCES=(
|
||||
$(git ls-files --exclude-standard --cached --others "*.proto" | grep -v '^profiling/proto/service.proto$')
|
||||
"${WORKDIR}/grpc-proto/grpc/gcp/altscontext.proto"
|
||||
"${WORKDIR}/grpc-proto/grpc/gcp/handshaker.proto"
|
||||
"${WORKDIR}/grpc-proto/grpc/gcp/transport_security_common.proto"
|
||||
"${WORKDIR}/grpc-proto/grpc/lookup/v1/rls.proto"
|
||||
"${WORKDIR}/grpc-proto/grpc/lookup/v1/rls_config.proto"
|
||||
"${WORKDIR}"/grpc-proto/grpc/testing/*.proto
|
||||
"${WORKDIR}"/grpc-proto/grpc/core/*.proto
|
||||
)
|
||||
|
||||
# These options of the form 'Mfoo.proto=bar' instruct the codegen to use an
|
||||
# import path of 'bar' in the generated code when 'foo.proto' is imported in
|
||||
# one of the sources.
|
||||
#
|
||||
# Note that the protos listed here are all for testing purposes. All protos to
|
||||
# be used externally should have a go_package option (and they don't need to be
|
||||
# listed here).
|
||||
OPTS=Mgrpc/core/stats.proto=google.golang.org/grpc/interop/grpc_testing/core,\
|
||||
Mgrpc/testing/benchmark_service.proto=google.golang.org/grpc/interop/grpc_testing,\
|
||||
Mgrpc/testing/stats.proto=google.golang.org/grpc/interop/grpc_testing,\
|
||||
Mgrpc/testing/report_qps_scenario_service.proto=google.golang.org/grpc/interop/grpc_testing,\
|
||||
Mgrpc/testing/messages.proto=google.golang.org/grpc/interop/grpc_testing,\
|
||||
Mgrpc/testing/worker_service.proto=google.golang.org/grpc/interop/grpc_testing,\
|
||||
Mgrpc/testing/control.proto=google.golang.org/grpc/interop/grpc_testing,\
|
||||
Mgrpc/testing/test.proto=google.golang.org/grpc/interop/grpc_testing,\
|
||||
Mgrpc/testing/payloads.proto=google.golang.org/grpc/interop/grpc_testing,\
|
||||
Mgrpc/testing/empty.proto=google.golang.org/grpc/interop/grpc_testing
|
||||
|
||||
for src in "${SOURCES[@]}"; do
|
||||
echo "protoc ${src}"
|
||||
protoc --go_out="${OPTS}:${WORKDIR}/out" --go-grpc_out="${OPTS}:${WORKDIR}/out" \
|
||||
-I"." \
|
||||
-I"${WORKDIR}/grpc-proto" \
|
||||
-I"${WORKDIR}/googleapis" \
|
||||
-I"${WORKDIR}/protobuf/src" \
|
||||
"${src}"
|
||||
done
|
||||
|
||||
for src in "${LEGACY_SOURCES[@]}"; do
|
||||
echo "protoc ${src}"
|
||||
protoc --go_out="${OPTS}:${WORKDIR}/out" --go-grpc_out="${OPTS},require_unimplemented_servers=false:${WORKDIR}/out" \
|
||||
-I"." \
|
||||
-I"${WORKDIR}/grpc-proto" \
|
||||
-I"${WORKDIR}/googleapis" \
|
||||
-I"${WORKDIR}/protobuf/src" \
|
||||
"${src}"
|
||||
done
|
||||
|
||||
# The go_package option in grpc/lookup/v1/rls.proto doesn't match the
|
||||
# current location. Move it into the right place.
|
||||
mkdir -p "${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1"
|
||||
mv "${WORKDIR}"/out/google.golang.org/grpc/lookup/grpc_lookup_v1/* "${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1"
|
||||
|
||||
# grpc_testing_not_regenerated/*.pb.go are not re-generated,
|
||||
# see grpc_testing_not_regenerated/README.md for details.
|
||||
rm "${WORKDIR}"/out/google.golang.org/grpc/testdata/grpc_testing_not_regenerated/*.pb.go
|
||||
|
||||
cp -R "${WORKDIR}"/out/google.golang.org/grpc/* .
|
||||
60
scripts/revive.toml
Normal file
60
scripts/revive.toml
Normal file
@@ -0,0 +1,60 @@
|
||||
# Enabled rules
|
||||
[rule.blank-imports]
|
||||
|
||||
[rule.context-as-argument]
|
||||
|
||||
[rule.context-keys-type]
|
||||
|
||||
[rule.dot-imports]
|
||||
|
||||
[rule.errorf]
|
||||
|
||||
[rule.error-return]
|
||||
|
||||
[rule.error-strings]
|
||||
|
||||
[rule.error-naming]
|
||||
|
||||
[rule.exported]
|
||||
|
||||
[rule.increment-decrement]
|
||||
|
||||
[rule.indent-error-flow]
|
||||
arguments = ["preserveScope"]
|
||||
|
||||
[rule.package-comments]
|
||||
|
||||
[rule.range]
|
||||
|
||||
[rule.receiver-naming]
|
||||
|
||||
[rule.superfluous-else]
|
||||
arguments = ["preserveScope"]
|
||||
|
||||
[rule.time-naming]
|
||||
|
||||
[rule.unexported-return]
|
||||
|
||||
[rule.unnecessary-stmt]
|
||||
|
||||
[rule.unreachable-code]
|
||||
|
||||
[rule.unused-parameter]
|
||||
|
||||
[rule.use-any]
|
||||
|
||||
[rule.useless-break]
|
||||
|
||||
[rule.var-declaration]
|
||||
|
||||
[rule.var-naming]
|
||||
|
||||
# Disabled rules
|
||||
[rule.empty-block] # Disabled to allow intentional no-op blocks (e.g., channel draining).
|
||||
Disabled = true
|
||||
|
||||
[rule.import-shadowing] # Disabled to allow intentional reuse of variable names that are the same as package imports.
|
||||
Disabled = true
|
||||
|
||||
[rule.redefines-builtin-id] # Disabled to allow intentional reuse of variable names that are the same as built-in functions.
|
||||
Disabled = true
|
||||
46
scripts/vet-proto.sh
Executable file
46
scripts/vet-proto.sh
Executable file
@@ -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)/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
|
||||
source ./scripts/install-protoc.sh "/home/runner/go"
|
||||
else
|
||||
die "run protoc installer https://github.com/grpc/grpc-go/blob/master/scripts/install-protoc.sh"
|
||||
fi
|
||||
echo SUCCESS
|
||||
exit 0
|
||||
elif [[ "$#" -ne 0 ]]; then
|
||||
die "Unknown argument(s): $*"
|
||||
fi
|
||||
|
||||
for MOD_FILE in $(find . -name 'go.mod'); do
|
||||
MOD_DIR=$(dirname ${MOD_FILE})
|
||||
pushd ${MOD_DIR}
|
||||
go generate ./...
|
||||
popd
|
||||
done
|
||||
|
||||
# - Check that generated proto files are up to date.
|
||||
git status --porcelain 2>&1 | fail_on_output || \
|
||||
(git status; git --no-pager diff; exit 1)
|
||||
|
||||
echo SUCCESS
|
||||
exit 0
|
||||
217
scripts/vet.sh
Executable file
217
scripts/vet.sh
Executable file
@@ -0,0 +1,217 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ex # Exit on error; debugging enabled.
|
||||
set -o pipefail # Fail a pipe if any sub-command fails.
|
||||
|
||||
source "$(dirname $0)/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
|
||||
|
||||
if [ -n "${GOROOT}" ]; then
|
||||
PATH="${GOROOT}/bin:${PATH}"
|
||||
fi
|
||||
PATH="${HOME}/go/bin:${PATH}"
|
||||
go version
|
||||
|
||||
if [[ "$1" = "-install" ]]; then
|
||||
# Install the pinned versions as defined in module tools.
|
||||
pushd ./test/tools
|
||||
go install \
|
||||
golang.org/x/tools/cmd/goimports \
|
||||
honnef.co/go/tools/cmd/staticcheck \
|
||||
github.com/client9/misspell/cmd/misspell \
|
||||
github.com/mgechev/revive
|
||||
popd
|
||||
exit 0
|
||||
elif [[ "$#" -ne 0 ]]; then
|
||||
die "Unknown argument(s): $*"
|
||||
fi
|
||||
|
||||
# - Ensure all source files contain a copyright message.
|
||||
# (Done in two parts because Darwin "git grep" has broken support for compound
|
||||
# exclusion matches.)
|
||||
(grep -L "DO NOT EDIT" $(git grep -L "\(Copyright [0-9]\{4,\} gRPC authors\)" -- '*.go') || true) | fail_on_output
|
||||
|
||||
# - Make sure all tests in grpc and grpc/test use leakcheck via Teardown.
|
||||
not grep 'func Test[^(]' -- *_test.go
|
||||
not grep 'func Test[^(]' -- test/*.go
|
||||
|
||||
# - Check for typos in test function names
|
||||
git grep 'func (s) ' -- "*_test.go" | not grep -v 'func (s) Test'
|
||||
git grep 'func [A-Z]' -- "*_test.go" | not grep -v 'func Test\|Benchmark\|Example'
|
||||
|
||||
# - Do not use time.After except in tests. It has the potential to leak the
|
||||
# timer since there is no way to stop it early.
|
||||
git grep -l 'time.After(' -- "*.go" | not grep -v '_test.go\|soak_tests\|testutils'
|
||||
|
||||
# - Do not use "interface{}"; use "any" instead.
|
||||
git grep -l 'interface{}' -- "*.go" 2>&1 | not grep -v '\.pb\.go\|protoc-gen-go-grpc\|grpc_testing_not_regenerated'
|
||||
|
||||
# - Do not call grpclog directly. Use grpclog.Component instead.
|
||||
git grep -l -e 'grpclog.I' --or -e 'grpclog.W' --or -e 'grpclog.E' --or -e 'grpclog.F' --or -e 'grpclog.V' -- "*.go" | not grep -v '^grpclog/component.go\|^internal/grpctest/tlogger_test.go\|^internal/grpclog/prefix_logger.go'
|
||||
|
||||
# - Ensure that the deprecated protobuf dependency is not used.
|
||||
not git grep "\"github.com/golang/protobuf/*" -- "*.go" ':(exclude)testdata/grpc_testing_not_regenerated/*'
|
||||
|
||||
# - Ensure all usages of grpc_testing package are renamed when importing.
|
||||
not git grep "\(import \|^\s*\)\"google.golang.org/grpc/interop/grpc_testing" -- "*.go"
|
||||
|
||||
# - Ensure that no trailing spaces are found.
|
||||
not git grep -n '[[:blank:]]$'
|
||||
|
||||
# - Ensure that all files have a terminating newline.
|
||||
git ls-files | not xargs -I {} sh -c '[ -n "$(tail -c 1 "{}" 2>/dev/null)" ] && echo "{}: No terminating new line found"' | fail_on_output
|
||||
|
||||
# - Ensure that no tabs are found in markdown files.
|
||||
not git grep -n $'\t' -- '*.md'
|
||||
|
||||
# - Ensure all xds proto imports are renamed to *pb or *grpc.
|
||||
git grep '"github.com/envoyproxy/go-control-plane/envoy' -- '*.go' ':(exclude)*.pb.go' | not grep -v 'pb "\|grpc "'
|
||||
|
||||
# - Ensure all context usages are done with timeout.
|
||||
# Context tests under benchmark are excluded as they are testing the performance of context.Background() and context.TODO().
|
||||
git grep -e 'context.Background()' --or -e 'context.TODO()' -- "*_test.go" | grep -v "benchmark/primitives/context_test.go" | grep -v 'context.WithTimeout(' | not grep -v 'context.WithCancel('
|
||||
|
||||
# Disallow usage of net.ParseIP in favour of netip.ParseAddr as the former
|
||||
# can't parse link local IPv6 addresses.
|
||||
not git grep 'net.ParseIP' -- '*.go'
|
||||
|
||||
# - Ensure that direct calls to regexp.Compile are not allowed in xDS production code.
|
||||
# Use CompileSafeRegex instead to ensure full-string matching.
|
||||
(git grep -n 'regexp.Compile(' -- '*xds*' ':(exclude)*_test.go' ':(exclude)internal/xds/matcher/string_matcher.go' ':(exclude)internal/xds/xdsclient/xdsresource/unmarshal_rds.go' || true) | fail_on_output || {
|
||||
echo "Error: direct calls to regexp.Compile are not allowed in xDS production code."
|
||||
echo "Please use CompileSafeRegex instead to ensure full-string matching."
|
||||
exit 1
|
||||
}
|
||||
|
||||
misspell -error .
|
||||
|
||||
# Get the absolute path to revive.toml relative to the script location
|
||||
REVIVE_CONFIG_PATH="$(dirname "$(realpath "$0")")/revive.toml"
|
||||
|
||||
# - gofmt, goimports, go vet, go mod tidy.
|
||||
# Perform these checks on each module inside gRPC.
|
||||
for MOD_FILE in $(find . -name 'go.mod'); do
|
||||
MOD_DIR=$(dirname ${MOD_FILE})
|
||||
pushd ${MOD_DIR}
|
||||
go vet -all ./... | fail_on_output
|
||||
gofmt -s -d -l . 2>&1 | fail_on_output
|
||||
goimports -l . 2>&1 | not grep -vE "\.pb\.go"
|
||||
|
||||
go mod tidy -compat=1.25
|
||||
git status --porcelain 2>&1 | fail_on_output || \
|
||||
(git status; git --no-pager diff; exit 1)
|
||||
|
||||
# Error for violation of enabled lint rules in config excluding generated code.
|
||||
revive \
|
||||
-set_exit_status=1 \
|
||||
-exclude "testdata/grpc_testing_not_regenerated/" \
|
||||
-exclude "**/*.pb.go" \
|
||||
-formatter plain \
|
||||
-config "${REVIVE_CONFIG_PATH}" \
|
||||
./...
|
||||
|
||||
# - Collection of static analysis checks
|
||||
SC_OUT="$(mktemp)"
|
||||
# By default, Staticcheck targets the Go version declared in go.mod via the go
|
||||
# directive. For Go 1.21 and newer, that directive specifies the minimum
|
||||
# required version of Go.
|
||||
# If a version is provided to Staticcheck using the -go flag, and the go
|
||||
# toolchain version is higher than the one in go.mod, Staticcheck will report
|
||||
# errors for usages of new language features in the std lib code.
|
||||
staticcheck -checks 'all' ./... >"${SC_OUT}" || true
|
||||
|
||||
# Error for anything other than checks that need exclusions.
|
||||
noret_grep -v "(ST1000)" "${SC_OUT}" | noret_grep -v "(SA1019)" | noret_grep -v "(ST1003)" | noret_grep -v "(ST1019)\|\(other import of\)" | not grep -v "(SA4000)"
|
||||
|
||||
# Exclude underscore checks for generated code.
|
||||
noret_grep "(ST1003)" "${SC_OUT}" | not grep -v '\(.pb.go:\)\|\(code_string_test.go:\)\|\(grpc_testing_not_regenerated\)'
|
||||
|
||||
# Error for duplicate imports not including grpc protos.
|
||||
noret_grep "(ST1019)\|\(other import of\)" "${SC_OUT}" | not grep -Fv 'XXXXX PleaseIgnoreUnused
|
||||
channelz/grpc_channelz_v1"
|
||||
go-control-plane/envoy
|
||||
grpclb/grpc_lb_v1"
|
||||
health/grpc_health_v1"
|
||||
interop/grpc_testing"
|
||||
orca/v3"
|
||||
proto/grpc_gcp"
|
||||
proto/grpc_lookup_v1"
|
||||
examples/features/proto/echo"
|
||||
reflection/grpc_reflection_v1"
|
||||
reflection/grpc_reflection_v1alpha"
|
||||
XXXXX PleaseIgnoreUnused'
|
||||
|
||||
# Error for any package comments not in generated code.
|
||||
noret_grep "(ST1000)" "${SC_OUT}" | not grep -v "\.pb\.go:"
|
||||
|
||||
# Ignore a false positive when operands have side affects.
|
||||
# TODO(https://github.com/dominikh/go-tools/issues/54): Remove this once the issue is fixed in staticcheck.
|
||||
noret_grep "(SA4000)" "${SC_OUT}" | not grep -v -e "crl.go:[0-9]\+:[0-9]\+: identical expressions on the left and right side of the '||' operator (SA4000)"
|
||||
|
||||
# Usage of the deprecated Logger interface from prefix_logger.go is the only
|
||||
# allowed one. If any other files use the deprecated interface, this check
|
||||
# will fails. Also, note that this same deprecation notice is also added to
|
||||
# the list of ignored notices down below to allow for the usage in
|
||||
# prefix_logger.go to not case vet failure.
|
||||
noret_grep "(SA1019)" "${SC_OUT}" | noret_grep "internal.Logger is deprecated:" | not grep -v -e "grpclog/logger.go"
|
||||
|
||||
# Only ignore the following deprecated types/fields/functions and exclude
|
||||
# generated code.
|
||||
noret_grep "(SA1019)" "${SC_OUT}" | not grep -Fv 'XXXXX PleaseIgnoreUnused
|
||||
XXXXX Protobuf related deprecation errors:
|
||||
"github.com/golang/protobuf
|
||||
.pb.go:
|
||||
grpc_testing_not_regenerated
|
||||
: ptypes.
|
||||
proto.RegisterType
|
||||
XXXXX gRPC internal usage deprecation errors:
|
||||
"google.golang.org/grpc
|
||||
: grpc.
|
||||
: v1alpha.
|
||||
: v1alphareflectionpb.
|
||||
BalancerAttributes is deprecated:
|
||||
CredsBundle is deprecated:
|
||||
GetMetadata is deprecated:
|
||||
internal.Logger is deprecated:
|
||||
Metadata is deprecated: use Attributes instead.
|
||||
NewAddress is deprecated:
|
||||
NewSubConn is deprecated:
|
||||
OverrideServerName is deprecated:
|
||||
RemoveSubConn is deprecated:
|
||||
SecurityVersion is deprecated:
|
||||
.ServerName is deprecated:
|
||||
stats.PickerUpdated is deprecated:
|
||||
Target is deprecated: Use the Target field in the BuildOptions instead.
|
||||
UpdateAddresses is deprecated:
|
||||
UpdateSubConnState is deprecated:
|
||||
balancer.ErrTransientFailure is deprecated:
|
||||
grpc/reflection/v1alpha/reflection.proto
|
||||
SwitchTo is deprecated:
|
||||
XXXXX xDS deprecated fields we support
|
||||
.ContainsMatch
|
||||
.ExactMatch
|
||||
.PrefixMatch
|
||||
.SafeRegexMatch
|
||||
.SuffixMatch
|
||||
GetContainsMatch
|
||||
GetExactMatch
|
||||
GetMatchSubjectAltNames
|
||||
GetPrefixMatch
|
||||
GetSafeRegexMatch
|
||||
GetSuffixMatch
|
||||
GetSourceIp
|
||||
GetTlsCertificateCertificateProviderInstance
|
||||
GetValidationContextCertificateProviderInstance
|
||||
XXXXX PleaseIgnoreUnused'
|
||||
popd
|
||||
done
|
||||
|
||||
echo SUCCESS
|
||||
Reference in New Issue
Block a user