Skip to content

Commit d2dcf00

Browse files
jeffmendozaistio-testing
authored andcommitted
Add prototool for linting, precommit, Circle, Prow. (#685)
1 parent 011906d commit d2dcf00

6 files changed

Lines changed: 61 additions & 1 deletion

File tree

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
defaults: &defaults
33
working_directory: /src/istio.io/api
44
docker:
5-
- image: gcr.io/istio-testing/api-build-tools:2018-10-24
5+
- image: gcr.io/istio-testing/api-build-tools:2018-10-31
66
environment:
77
GOPATH: /go
88
OUT_PATH: /src
@@ -16,6 +16,7 @@ jobs:
1616
command: |
1717
./scripts/generate-protos.sh || die "could not generate *.pb.go"
1818
make proto-commit || die "could not regenerate proto.lock"
19+
make lint || die "Lint errors"
1920
if [[ -n $(git status --porcelain) ]]; then
2021
git status
2122
git --no-pager diff

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ repo_dir = .
1111
docker_gen = /usr/bin/protoc -I/protobuf -I$(repo_dir)
1212
out_path = $(OUT_PATH)
1313
docker_lock = protolock
14+
docker_tool = prototool
1415
else
1516
gen_img := gcr.io/istio-testing/protoc:2018-06-12
1617
lock_img := gcr.io/istio-testing/protolock:2018-10-23
18+
all_img := gcr.io/istio-testing/api-build-tools:2018-10-31
1719
pwd := $(shell pwd)
1820
mount_dir := /src
1921
repo_dir := istio.io/api
2022
repo_mount := $(mount_dir)/istio.io/api
2123
docker_gen := docker run --rm -v $(pwd):$(repo_mount) -w $(mount_dir) $(gen_img) -I$(repo_dir)
2224
out_path = .
2325
docker_lock = docker run --rm -v $(pwd):$(repo_mount) -w $(repo_mount) $(lock_img)
26+
docker_tool = docker run --rm -v $(pwd):$(repo_mount) -w $(repo_mount) $(all_img) prototool
2427
endif
2528

2629
########################
@@ -344,9 +347,17 @@ clean-envoy:
344347
#####################
345348
# Protolock
346349
#####################
350+
347351
proto-commit:
348352
@$(docker_lock) commit
349353

354+
#####################
355+
# Lint
356+
#####################
357+
358+
lint:
359+
@$(docker_tool) lint --protoc-bin-path=/usr/bin/protoc --protoc-wkt-path=/protobuf
360+
350361
#####################
351362
# Cleanup
352363
#####################

prototool.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
protoc:
2+
# This is ignored because we always run with
3+
# --protoc-bin-path=/usr/bin/protoc to use the protoc from our
4+
# container
5+
version: 3.6.1
6+
7+
lint:
8+
# Linter files to ignore.
9+
ignores:
10+
- id: MESSAGE_FIELD_NAMES_LOWER_SNAKE_CASE
11+
files:
12+
- rbac/v1alpha1/rbac.proto
13+
- id: REQUEST_RESPONSE_TYPES_IN_SAME_FILE
14+
files:
15+
- mixer/v1/service.proto
16+
- id: ENUM_FIELD_NAMES_UPPER_SNAKE_CASE
17+
files:
18+
- networking/v1alpha3/gateway.proto
19+
20+
# Linter rules.
21+
rules:
22+
# The specific linters to remove.
23+
remove:
24+
- FILE_OPTIONS_REQUIRE_JAVA_MULTIPLE_FILES
25+
- FILE_OPTIONS_REQUIRE_JAVA_OUTER_CLASSNAME
26+
- FILE_OPTIONS_REQUIRE_JAVA_PACKAGE
27+
- FILE_OPTIONS_EQUAL_GO_PACKAGE_PB_SUFFIX
28+
- ENUM_FIELD_PREFIXES
29+
- ENUM_ZERO_VALUES_INVALID

prow/api-presubmit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ cd ${ROOT}
4242

4343
./scripts/generate-protos.sh || die "Could not generate *.pb.go"
4444
make proto-commit || die "Could not commit new proto.lock"
45+
make lint || die "Lint errors"
4546

4647
if [[ -n $(git status --porcelain) ]]; then
4748
git status

scripts/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ if [ $BRANCH_NAME != '(no branch)' ]; then
3535

3636
echo "Updating proto.lock"
3737
make proto-commit
38+
39+
echo "Checking lint"
40+
make lint
3841
fi

tools/all/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
FROM alpine:3.7 as prototool_download
2+
3+
RUN apk update && \
4+
apk add curl && \
5+
curl -sSL https://github.com/uber/prototool/releases/download/v1.3.0/prototool-Linux-x86_64 \
6+
-o /usr/bin/prototool && \
7+
chmod +x /usr/bin/prototool
8+
19
FROM gcr.io/istio-testing/protolock:2018-10-23 as protolock
210

311
FROM gcr.io/istio-testing/protoc:2018-06-12
@@ -6,4 +14,11 @@ COPY --from=protolock \
614
/usr/bin/protolock \
715
/usr/bin/
816

17+
COPY --from=prototool_download \
18+
/usr/bin/prototool \
19+
/usr/bin/
20+
21+
RUN apk update && \
22+
apk add libc6-compat
23+
924
ENTRYPOINT []

0 commit comments

Comments
 (0)