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

Automatically run bazel mod tidy in @rules_go//go #3927

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

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Apr 24, 2024

What type of PR is this?

Feature

What does this PR do? Why is it needed?

bazel mod tidy is run if supported and if relevant files change due to the command.

Which issues(s) does this PR fix?

Fixes #3900
Fixes bazelbuild/bazel-gazelle#1749

Other notes for review

`bazel mod tidy` is run if supported and if relevant files change due to the command.
@stefanpenner
Copy link
Contributor

Just checking, will this also work for users of go.work workspaces?

@fmeum
Copy link
Collaborator Author

fmeum commented May 7, 2024

Just checking, will this also work for users of go.work workspaces?

This requires adding the relevant files to https://github.com/bazelbuild/bazel-gazelle/blob/7c84c339075a992ea1a6f720899d91c0e047efe2/internal/bzlmod/go_deps.bzl#L657. Maybe that already happens with the fake go.mod files we create for a workspace?

if len(diff) > 0 {
if HasBazelModTidy == "True" {
_, _ = fmt.Fprintf(os.Stderr, "\nrules_go: Running 'bazel mod tidy' since %s changed...\n", strings.Join(diff, ", "))
err = runProcess([]string{"bazel", "mod", "tidy"}, os.Environ(), cwd)
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: not everybody use the bazel binary from $PATH.

Some folks prefer using bazelisk, b, bb, blaze.

Could we make this configurable somehow? Or better, could we expose a starlark API for this?

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