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

Bazelify go-protoparser, and use it in CI tests #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shaldengeki
Copy link
Contributor

This is a quick first pass at using Bazel in go-protoparser. This makes the CI tests run via Bazel. You can do the same on your machine, by running bazel test //.... If you don't have bazel, recommend you install bazelisk, which will manage your bazel version for you:
https://bazel.build/install/bazelisk

Roughly, this is the result of:

  • Setting up a WORKSPACE and root BUILD.bazel file, with go rules and gazelle in it
  • Running gazelle against the repo: bazel run //:gazelle, to generate BUILD.bazel files for every package
  • Changing _example/dump/main.go to read _testdata/simple.proto as a default argument at runtime
  • Changing the Makefile to run bazel commands where possible
  • Updating the Github workflow to use a persistent Bazel cache
  • Adding some Bazel configuration to display useful test failures

You can see the benefits of the caching in CI, if you rerun the builds -- you'll see that Bazel correctly doesn't re-run the tests again, and the build finishes very quickly:
https://github.com/shaldengeki/go-protoparser/actions/runs/7945280017/job/21691752664

INFO: Elapsed time: 6.377s, Critical Path: 0.09s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
//interpret/unordered:unordered_test                            (cached) PASSED in 0.1s
//lexer:lexer_test                                              (cached) PASSED in 0.1s
//lexer/scanner:scanner_test                                    (cached) PASSED in 0.1s
//parser:parser_test                                            (cached) PASSED in 0.1s
//parser/meta:meta_test                                         (cached) PASSED in 0.1s
Executed 0 out of 5 tests: 5 tests pass.

(Or you can run bazel test //... locally twice, and observe that the second run finishes ~instantly.)

I left the linting commands & job un-Bazelified. I think this'll take some more work -- basically, some of the linting packages take some work to bazelify, and doing it only partway will make the lint CI job slow (~40s).

Let me know what you think! I'm happy to keep plugging away at the lints if you'd rather do this in one fell swoop.

Copy link
Owner

@yoheimuta yoheimuta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your fantastic work!

I have a question. Is there anything new contributors need to know before diving into this repository? Do they just need to install bazelisk? I assume some developers might not be familiar with bazel, so I'd like to add some instructions on setup and any changes to the standard Go workflow.

@ehrktia
Copy link
Contributor

ehrktia commented Mar 2, 2024

@shaldengeki
out of curiosity, I have the following queries

  • from my understanding bazel build system is used mostly in mono repos with polygot code, i.e. - repo with front and back ends together to optimise build and CI run time.
    This is go go-based repo/lib can it not use the standard go build system go run, go build and go test both in CI and in local env to achieve the same?
  • As per the comment about caching test in local and build can we not use the go test flags to achieve the same?
    Am new to Bazel i.e. - have used it commercially for a year or so not more.
    The above queries are based on my understanding of Bazel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants