Skip to content

Commit 137df90

Browse files
authored
api/tools: Shift validation script to bazel (#41775)
Signed-off-by: Ryan Northey <[email protected]>
1 parent cc99dc6 commit 137df90

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

ci/do_ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function bazel_envoy_api_build() {
194194
--//tools/api_proto_plugin:extra_args=api_version:3.7 \
195195
//tools/protoprint:protoprint_test
196196
echo "Validating API structure..."
197-
"${ENVOY_SRCDIR}"/tools/api/validate_structure.py
197+
bazel run "${BAZEL_BUILD_OPTIONS[@]}" //tools/api:validate_structure "${PWD}/api/envoy"
198198
echo "Testing API..."
199199
bazel_with_collection \
200200
test "${BAZEL_BUILD_OPTIONS[@]}" \

tools/api/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@rules_python//python:defs.bzl", "py_binary")
2+
3+
licenses(["notice"]) # Apache 2
4+
5+
py_binary(
6+
name = "validate_structure",
7+
srcs = ["validate_structure.py"],
8+
# deps = [":validate"],
9+
)

tools/api/validate_structure.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# ./tools/api/validate_structure.py
66

7+
import argparse
78
import pathlib
89
import re
910
import sys
@@ -77,12 +78,18 @@ def validate_proto_paths(proto_paths):
7778
return error_msgs
7879

7980

80-
if __name__ == '__main__':
81-
api_root = 'api/envoy'
82-
api_protos = pathlib.Path(api_root).rglob('*.proto')
83-
error_msgs = validate_proto_paths(p.relative_to(api_root) for p in api_protos)
81+
def main(*args):
82+
parser = argparse.ArgumentParser(description="Check API structure.")
83+
parser.add_argument("api_root", type=str, help="Specify the path to the api root.")
84+
args = parser.parse_args(args)
85+
api_protos = pathlib.Path(args.api_root).rglob('*.proto')
86+
error_msgs = validate_proto_paths(p.relative_to(args.api_root) for p in api_protos)
8487
if error_msgs:
8588
for m in error_msgs:
8689
print(m)
8790
sys.exit(1)
8891
sys.exit(0)
92+
93+
94+
if __name__ == '__main__':
95+
main(*sys.argv[1:])

0 commit comments

Comments
 (0)