Skip to content

Commit

Permalink
Merge pull request #12286 from fejta/tg
Browse files Browse the repository at this point in the history
Check in testgrid protos, and ensure they stay up to date
  • Loading branch information
k8s-ci-robot committed Apr 20, 2019
2 parents 2167412 + c7f9895 commit a8f5ca0
Show file tree
Hide file tree
Showing 13 changed files with 2,243 additions and 69 deletions.
40 changes: 40 additions & 0 deletions hack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,50 @@ sh_test(
tags = ["lint"],
)

protoc = "@com_google_protobuf//:protoc"

protoc_gen_go = "@com_github_golang_protobuf//protoc-gen-go"

sh_binary(
name = "update-protos",
srcs = ["update-protos.sh"],
args = [
"$(location %s)" % protoc,
"$(location %s)" % protoc_gen_go,
"$(location %s)" % ":boilerplate/boilerplate.generated.go.txt",
],
data = [
":boilerplate/boilerplate.generated.go.txt",
"//:all-srcs",
protoc,
protoc_gen_go,
],
tags = ["local"],
)

sh_test(
name = "verify-protos",
srcs = ["verify-protos.sh"],
args = [
"$(location %s)" % ":update-protos",
"$(location %s)" % protoc,
"$(location %s)" % protoc_gen_go,
"$(location %s)" % ":boilerplate/boilerplate.generated.go.txt",
],
data = [
":boilerplate/boilerplate.generated.go.txt",
":update-protos",
protoc,
protoc_gen_go,
"//:all-srcs",
],
)

test_suite(
name = "verify-all",
tags = ["lint"],
tests = [
"verify-protos",
"verify-pylint",
"verify_boilerplate",
],
Expand Down
46 changes: 46 additions & 0 deletions hack/update-protos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes 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 -o errexit
set -o nounset
set -o pipefail

if [[ $# -lt 3 ]]; then
echo "Usage: bazel run //hack:update-protos [-- tmpdir]" >&2
exit 1
fi

protoc=$1
plugin=$2
boiler=$3
dest=${4:-$BUILD_WORKSPACE_DIRECTORY}

genproto() {
dir=$(dirname "$1")
base=$(basename "$1")
"$protoc" "--plugin=$plugin" "--proto_path=$dir" "--go_out=$dest/$dir" "$1"
tmp=$(mktemp)
out=$dest/$dir/${base%.proto}.pb.go
mv "$out" "$tmp"
cat "$boiler" "$tmp" > "$out"
}

echo -n "Generating protos: " >&2
for p in $(find . -not '(' -path './vendor' -prune ')' -name '*.proto'); do
echo -n "$p "
genproto "$p"
done
echo
51 changes: 51 additions & 0 deletions hack/verify-protos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes 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 -o errexit
set -o nounset
set -o pipefail

if [[ -z "${TEST_WORKSPACE:-}" ]]; then
echo "Usage: bazel test //hack:verify-protos" >&2
exit 1
fi

TESTINFRA_ROOT=$PWD

_tmpdir="$(mktemp -d -t verify-deps.XXXXXX)"
trap "rm -rf ${_tmpdir}" EXIT

cp -a "${TESTINFRA_ROOT}/." "${_tmpdir}"

# Update protos, outputting to $_tmpdir
update_protos=$1
protoc=$2
plugin=$3
boiler=$4
"$update_protos" "$protoc" "$plugin" "$boiler" "${_tmpdir}"

# Ensure nothing changed
diff=$(diff -Nupr \
-x ".git" \
-x "bazel-*" \
-x "_output" \
"${TESTINFRA_ROOT}" "${_tmpdir}" 2>/dev/null || true)

if [[ -n "${diff}" ]]; then
echo "${diff}" >&2
echo >&2
echo "Run bazel run //hack:update-protos" >&2
exit 1
fi
1 change: 1 addition & 0 deletions hack/verify_boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def get_refs():
"// Code generated by deepcopy-gen. DO NOT EDIT.",
"// Code generated by informer-gen. DO NOT EDIT.",
"// Code generated by lister-gen. DO NOT EDIT.",
"// Code generated by protoc-gen-go. DO NOT EDIT.",
]

# given the file contents, return true if the file appears to be generated
Expand Down
4 changes: 2 additions & 2 deletions testgrid/cmd/updater/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ go_library(
deps = [
"//testgrid/config:go_default_library",
"//testgrid/metadata/junit:go_default_library",
"//testgrid/state:state_go_proto",
"//testgrid/state:go_default_library",
"//testgrid/util/gcs:go_default_library",
"//vendor/cloud.google.com/go/storage:go_default_library",
"//vendor/github.com/golang/protobuf/proto:go_default_library",
Expand Down Expand Up @@ -49,7 +49,7 @@ go_test(
embed = [":go_default_library"],
deps = [
"//testgrid/metadata/junit:go_default_library",
"//testgrid/state:state_go_proto",
"//testgrid/state:go_default_library",
"//vendor/github.com/golang/protobuf/proto:go_default_library",
],
)
23 changes: 4 additions & 19 deletions testgrid/config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")

# gazelle:proto package
# gazelle:resolve go github.com/golang/protobuf/proto //vendor/github.com/golang/protobuf/proto:go_default_library

go_library(
name = "go_default_library",
srcs = ["config.go"],
embed = [":config_go_proto"],
srcs = [
"config.go",
"config.pb.go",
],
importpath = "k8s.io/test-infra/testgrid/config",
visibility = ["//visibility:public"],
deps = [
Expand All @@ -30,16 +28,3 @@ filegroup(
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

proto_library(
name = "config_proto",
srcs = ["config.proto"],
visibility = ["//visibility:public"],
)

go_proto_library(
name = "config_go_proto",
importpath = "k8s.io/test-infra/testgrid/config",
proto = ":config_proto",
visibility = ["//visibility:public"],
)
Loading

0 comments on commit a8f5ca0

Please sign in to comment.