From 7ac5e9a3d039fb6dbefe255f3d03d97e49fccdf4 Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Fri, 24 Jun 2022 11:31:26 +0100 Subject: [PATCH] repo: Add `buf` linting initially just for unused imports Fix #45 Signed-off-by: Ryan Northey --- bazel/repositories.bzl | 19 +++++++++++++++++++ bazel/repository_locations.bzl | 5 +++++ buf.lock | 11 +++++++++++ buf.yaml | 7 +++++++ ci/check.sh | 3 +++ 5 files changed, 45 insertions(+) create mode 100644 buf.lock create mode 100644 buf.yaml diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 3ab16c5..1bf3826 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -6,6 +6,12 @@ def xds_api_dependencies(): "bazel_gazelle", locations = REPOSITORY_LOCATIONS, ) + xds_http_archive( + "com_github_bufbuild_buf", + locations = REPOSITORY_LOCATIONS, + build_file_content = BUF_BUILD_CONTENT, + tags = ["manual"], + ) xds_http_archive( "com_envoyproxy_protoc_gen_validate", locations = REPOSITORY_LOCATIONS, @@ -31,3 +37,16 @@ def xds_api_dependencies(): # TODO(roth): Remove once all callers are updated to use the new name. def udpa_api_dependencies(): xds_api_dependencies() + +BUF_BUILD_CONTENT = """ +package( + default_visibility = ["//visibility:public"], +) + +filegroup( + name = "buf", + srcs = [ + "@com_github_bufbuild_buf//:bin/buf", + ], +) +""" diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index c6f9f4e..cdd65a7 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -7,6 +7,11 @@ REPOSITORY_LOCATIONS = dict( sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c", urls = ["https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz"], ), + com_github_bufbuild_buf = dict( + sha256 = "826ad701db09805eb425723ad3ea0c13ce7ca8353d6a1fb473399db915dafdf9", + strip_prefix = "buf", + urls = ["https://github.com/bufbuild/buf/releases/download/v1.4.0/buf-Linux-x86_64.tar.gz"], + ), com_envoyproxy_protoc_gen_validate = dict( sha256 = "c695fc5a2e5a1b52904cd8a58ce7a1c3a80f7f50719496fd606e551685c01101", strip_prefix = "protoc-gen-validate-0.6.1", diff --git a/buf.lock b/buf.lock new file mode 100644 index 0000000..7223782 --- /dev/null +++ b/buf.lock @@ -0,0 +1,11 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: gogo + repository: protobuf + commit: 4df00b267f944190a229ce3695781e99 + - remote: buf.build + owner: googleapis + repository: googleapis + commit: d1a849b8f8304950832335723096e954 diff --git a/buf.yaml b/buf.yaml new file mode 100644 index 0000000..a200f34 --- /dev/null +++ b/buf.yaml @@ -0,0 +1,7 @@ +version: v1 +deps: + - buf.build/googleapis/googleapis:d1a849b8f8304950832335723096e954 + - buf.build/gogo/protobuf +lint: + use: + - IMPORT_USED diff --git a/ci/check.sh b/ci/check.sh index f6faf04..384908a 100755 --- a/ci/check.sh +++ b/ci/check.sh @@ -2,6 +2,9 @@ set -e +bazel run @com_github_bufbuild_buf//:bin/buf lint -- --path xds +bazel run @com_github_bufbuild_buf//:bin/buf lint -- --path udpa + bazel test --config=ci //... rm -rf go/xds go/udpa