From ab0a7889e85d8ed1beb2da1c1522697835e7e846 Mon Sep 17 00:00:00 2001 From: Jeff Mendoza Date: Wed, 31 Oct 2018 09:29:25 -0700 Subject: [PATCH] Add prototool for linting, precommit, Circle, Prow. --- .circleci/config.yml | 3 ++- Makefile | 11 +++++++++++ prototool.yaml | 29 +++++++++++++++++++++++++++++ prow/api-presubmit.sh | 1 + scripts/pre-commit | 3 +++ tools/all/Dockerfile | 15 +++++++++++++++ 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 prototool.yaml diff --git a/.circleci/config.yml b/.circleci/config.yml index c081c13298..a3edfcf89f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 defaults: &defaults working_directory: /src/istio.io/api docker: - - image: gcr.io/istio-testing/api-build-tools:2018-10-24 + - image: gcr.io/istio-testing/api-build-tools:2018-10-31 environment: GOPATH: /go OUT_PATH: /src @@ -16,6 +16,7 @@ jobs: command: | ./scripts/generate-protos.sh || die "could not generate *.pb.go" make proto-commit || die "could not regenerate proto.lock" + make lint || die "Lint errors" if [[ -n $(git status --porcelain) ]]; then git status git --no-pager diff diff --git a/Makefile b/Makefile index 52bc7707ed..a74a1d6faa 100644 --- a/Makefile +++ b/Makefile @@ -11,9 +11,11 @@ repo_dir = . docker_gen = /usr/bin/protoc -I/protobuf -I$(repo_dir) out_path = $(OUT_PATH) docker_lock = protolock +docker_tool = prototool else gen_img := gcr.io/istio-testing/protoc:2018-06-12 lock_img := gcr.io/istio-testing/protolock:2018-10-23 +all_img := gcr.io/istio-testing/api-build-tools:2018-10-31 pwd := $(shell pwd) mount_dir := /src repo_dir := istio.io/api @@ -21,6 +23,7 @@ repo_mount := $(mount_dir)/istio.io/api docker_gen := docker run --rm -v $(pwd):$(repo_mount) -w $(mount_dir) $(gen_img) -I$(repo_dir) out_path = . docker_lock = docker run --rm -v $(pwd):$(repo_mount) -w $(repo_mount) $(lock_img) +docker_tool = docker run --rm -v $(pwd):$(repo_mount) -w $(repo_mount) $(all_img) prototool endif ######################## @@ -344,9 +347,17 @@ clean-envoy: ##################### # Protolock ##################### + proto-commit: @$(docker_lock) commit +##################### +# Lint +##################### + +lint: + @$(docker_tool) lint --protoc-bin-path=/usr/bin/protoc --protoc-wkt-path=/protobuf + ##################### # Cleanup ##################### diff --git a/prototool.yaml b/prototool.yaml new file mode 100644 index 0000000000..f46de81d01 --- /dev/null +++ b/prototool.yaml @@ -0,0 +1,29 @@ +protoc: + # This is ignored because we always run with + # --protoc-bin-path=/usr/bin/protoc to use the protoc from our + # container + version: 3.6.1 + +lint: + # Linter files to ignore. + ignores: + - id: MESSAGE_FIELD_NAMES_LOWER_SNAKE_CASE + files: + - rbac/v1alpha1/rbac.proto + - id: REQUEST_RESPONSE_TYPES_IN_SAME_FILE + files: + - mixer/v1/service.proto + - id: ENUM_FIELD_NAMES_UPPER_SNAKE_CASE + files: + - networking/v1alpha3/gateway.proto + + # Linter rules. + rules: + # The specific linters to remove. + remove: + - FILE_OPTIONS_REQUIRE_JAVA_MULTIPLE_FILES + - FILE_OPTIONS_REQUIRE_JAVA_OUTER_CLASSNAME + - FILE_OPTIONS_REQUIRE_JAVA_PACKAGE + - FILE_OPTIONS_EQUAL_GO_PACKAGE_PB_SUFFIX + - ENUM_FIELD_PREFIXES + - ENUM_ZERO_VALUES_INVALID diff --git a/prow/api-presubmit.sh b/prow/api-presubmit.sh index 62baa836f6..da4ece7da5 100755 --- a/prow/api-presubmit.sh +++ b/prow/api-presubmit.sh @@ -42,6 +42,7 @@ cd ${ROOT} ./scripts/generate-protos.sh || die "Could not generate *.pb.go" make proto-commit || die "Could not commit new proto.lock" +make lint || die "Lint errors" if [[ -n $(git status --porcelain) ]]; then git status diff --git a/scripts/pre-commit b/scripts/pre-commit index 8fca5f1cc1..7a9d2a96da 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -35,4 +35,7 @@ if [ $BRANCH_NAME != '(no branch)' ]; then echo "Updating proto.lock" make proto-commit + + echo "Checking lint" + make lint fi diff --git a/tools/all/Dockerfile b/tools/all/Dockerfile index 76de314f9d..0c8c47956e 100644 --- a/tools/all/Dockerfile +++ b/tools/all/Dockerfile @@ -1,3 +1,11 @@ +FROM alpine:3.7 as prototool_download + +RUN apk update && \ + apk add curl && \ + curl -sSL https://github.com/uber/prototool/releases/download/v1.3.0/prototool-Linux-x86_64 \ + -o /usr/bin/prototool && \ + chmod +x /usr/bin/prototool + FROM gcr.io/istio-testing/protolock:2018-10-23 as protolock FROM gcr.io/istio-testing/protoc:2018-06-12 @@ -6,4 +14,11 @@ COPY --from=protolock \ /usr/bin/protolock \ /usr/bin/ +COPY --from=prototool_download \ + /usr/bin/prototool \ + /usr/bin/ + +RUN apk update && \ + apk add libc6-compat + ENTRYPOINT []