Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Protobuf linter to the project #971

Closed
3 tasks done
vinitamurthi opened this issue Apr 13, 2020 · 8 comments · Fixed by #1186
Closed
3 tasks done

Add a Protobuf linter to the project #971

vinitamurthi opened this issue Apr 13, 2020 · 8 comments · Fixed by #1186
Assignees
Labels
Z-ibt Temporary label for Ben to keep track of issues he's triaged.

Comments

@vinitamurthi
Copy link
Contributor

vinitamurthi commented Apr 13, 2020

We currently rely on reviewers to enforce the style guide for protobuf files. We would like to add a linter to automate this task.
Buf seems to be a good fit for our requirements and we would like to use that for our project. If you have recommendations for some other linter, please reach out to me to discuss if we can use it in our project before adding it.

Steps that need to be completed to add the linter:

  • Run the linter on our existing protobuf files. Create a PR that fixes all lint problems that the linter catches

  • Add steps in the linter job of our CircleCI workflow (similar to the Kotlin linting step) that will install and run the linter on our protobuf files

  • Add documentation on how to install the linter in the prerequisites section of our wiki

@vinitamurthi
Copy link
Contributor Author

@anandwana001 Would you be interested in taking this up?

@anandwana001
Copy link
Contributor

@anandwana001 Would you be interested in taking this up?

Sure, I will go through it.

@vinitamurthi
Copy link
Contributor Author

Great! I will assign it to you then

@anandwana001
Copy link
Contributor

anandwana001 commented May 28, 2020

Could you please update me with the command you are using to compile the proto files? I did some update in import statements and I need to update proto files in build folder as well.

Screenshot 2020-05-28 at 10 38 50

If I exclude the model/build, it seems like this:

Screenshot 2020-05-28 at 10 57 33

@vinitamurthi
Copy link
Contributor Author

I actually think your second screenshot shows that it is working right? We may have to update the lint checks to allow for certain things its shouting about

@anandwana001
Copy link
Contributor

anandwana001 commented May 28, 2020

ok. I am checking why are these proto files are there in build folder and what is their use if we will exclude them in buf.yaml.

Screenshot 2020-05-28 at 11 43 38

Now, step 2, to add it to the config.yaml.

@anandwana001
Copy link
Contributor

anandwana001 commented May 28, 2020

Step2 - Add steps in the linter job of our CircleCI workflow (similar to the Kotlin linting step) that will install and run the linter on our protobuf files

@vinitamurthi Just wanted to check with you before PR, as I can't test locally if it is correct or not.

anchor_for_install_buf: &install_buf
  name: Download latest buf
  command: >
        get_latest_or_prerelease() {
             curl --silent "https://api.github.com/repos/$1/releases" |
             grep '"tag_name":' |
             sed -E 's/.*"([^"]+)".*/\1/'
        }

        BUFBUILD=$(get_latest_or_prerelease bufbuild/buf)

        echo Using Bufbuild $BUFBUILD

        PROJECT="oppia-android"
        UNAME_OS=$(shell uname -s)
        UNAME_ARCH=$(shell uname -m)
        CACHE_BASE=$(HOME)/.cache/$(PROJECT)
        CACHE=$(CACHE_BASE)/$(UNAME_OS)/$(UNAME_ARCH)
        CACHE_BIN=$(CACHE)/bin

        curl -sSL \
        "https://github.com/bufbuild/buf/releases/download/v$BUFBUILD/buf-$(UNAME_OS)-$(UNAME_ARCH)" \
        -o "$(CACHE_BIN)/buf"

        chmod +x "$(CACHE_BIN)/buf"

Adding the step inside linters job as an another step after it completed the Kotlin tests step.

- run:
      name: Kotlin tests - Data, Utility
      command: ./ktlint utility/**/*.kt data/**/*.kt && echo "Lint completed successfully"
- run:
      <<: *install_buf
- run:
      name: Buf check - proto files
      command: buf check lint

at CircleCi it should run something like:

curl -sSL \
	"https://github.com/bufbuild/buf/releases/download/v0.13.0/buf-Linux-x86_64" \
	-o "/home/circleci/.cache/oppia-android/Linux/x86_64/bin/buf"
chmod +x "/home/circleci/.cache/oppia-android/Linux/x86_64/bin/buf"
buf check lint

@vinitamurthi
Copy link
Contributor Author

That looks good to me, only one thing - do the installation of linters together and then run tests together. i.e. let the steps be : install ktlint, install buf, run ktlint, run buf

As for testing, yes we cannot test locally but you can make these changes in circleci config and create a PR and see what happens with the continuous integration tests in that PR

rt4914 pushed a commit that referenced this issue Jun 5, 2020
* added protobuf linter

* update config and buf yaml files

* removed backslash before url

* removed buf cache system

* update chmod directory name

* removed need of directory

* trying using docker buf image

* tested success over circleci

* removing self putted buf error to check over ci

* seems like a final commit

* update enum suffix and exclude prefix check

* update namings

* update namings everywhere

* circleci path match to buf
@BenHenning BenHenning added the Z-ibt Temporary label for Ben to keep track of issues he's triaged. label Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-ibt Temporary label for Ben to keep track of issues he's triaged.
Development

Successfully merging a pull request may close this issue.

3 participants