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

Enable plugins by default remove BUF_BETA_PLUGINS_ENABLED #3326

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

- Add support for custom lint and breaking change plugins. See
[our launch blog post](https://buf.build/blog/buf-custom-lint-breaking-change-plugins)
for more details!
- Add `buf dep graph --format` flag that defaults to `dot`, and adds the option `json`, to print
the dependency graph in JSON format.
- Fix bugs in `buf format` where trailing comments on commas in message literals were not properly
Expand Down
8 changes: 0 additions & 8 deletions private/buf/bufcli/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
)

const (
betaPluginEnabledEnvKey = "BUF_BETA_PLUGINS_ENABLED"
inputHTTPSUsernameEnvKey = "BUF_INPUT_HTTPS_USERNAME"
inputHTTPSPasswordEnvKey = "BUF_INPUT_HTTPS_PASSWORD"
inputSSHKeyFileEnvKey = "BUF_INPUT_SSH_KEY_FILE"
Expand Down Expand Up @@ -85,10 +84,3 @@ func WarnBetaCommand(_ context.Context, container appext.Container) {
container.Logger().Warn("This command is in beta. It is unstable and likely to change. To suppress this warning, set " + betaSuppressWarningsEnvKey + "=1")
}
}

// IsPluginEnabled returns whether the env var enabling beta lint/breaking plugin is set.
//
// TODO: remove this as part of publicly releasing lint/breaking plugins
func IsPluginEnabled(container appext.Container) bool {
return container.Env(betaPluginEnabledEnvKey) != ""
}
3 changes: 0 additions & 3 deletions private/buf/cmd/buf/command/breaking/breaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,6 @@ func run(
if flags.ExcludeImports {
breakingOptions = append(breakingOptions, bufcheck.BreakingWithExcludeImports())
}
if bufcli.IsPluginEnabled(container) {
breakingOptions = append(breakingOptions, bufcheck.WithPluginsEnabled())
}
if err := client.Breaking(
ctx,
imageWithConfig.BreakingConfig(),
Expand Down
6 changes: 0 additions & 6 deletions private/buf/cmd/buf/command/config/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,6 @@ func lsRun(
configuredRuleOptions := []bufcheck.ConfiguredRulesOption{
bufcheck.WithPluginConfigs(bufYAMLFile.PluginConfigs()...),
}
if bufcli.IsPluginEnabled(container) {
configuredRuleOptions = append(configuredRuleOptions, bufcheck.WithPluginsEnabled())
}
rules, err = client.ConfiguredRules(
ctx,
ruleType,
Expand All @@ -246,9 +243,6 @@ func lsRun(
allRulesOptions := []bufcheck.AllRulesOption{
bufcheck.WithPluginConfigs(bufYAMLFile.PluginConfigs()...),
}
if bufcli.IsPluginEnabled(container) {
allRulesOptions = append(allRulesOptions, bufcheck.WithPluginsEnabled())
}
rules, err = client.AllRules(
ctx,
ruleType,
Expand Down
3 changes: 0 additions & 3 deletions private/buf/cmd/buf/command/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ func run(
lintOptions := []bufcheck.LintOption{
bufcheck.WithPluginConfigs(imageWithConfig.PluginConfigs()...),
}
if bufcli.IsPluginEnabled(container) {
lintOptions = append(lintOptions, bufcheck.WithPluginsEnabled())
}
if err := client.Lint(
ctx,
imageWithConfig.LintConfig(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ func NewEnvFunc(tb testing.TB) func(string) map[string]string {
useEnvVar(use, "CACHE_DIR"): tempDirPath,
useEnvVar(use, "CONFIG_DIR"): tempDirPath,
"PATH": os.Getenv("PATH"),
// TODO: remove this as part of publicly releasing lint/breaking plugins
"BUF_BETA_PLUGINS_ENABLED": "1",
}
}
}
Expand Down
1 change: 0 additions & 1 deletion private/bufpkg/bufcheck/breaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,6 @@ func testBreaking(
previousImage,
bufcheck.BreakingWithExcludeImports(),
bufcheck.WithPluginConfigs(workspace.PluginConfigs()...),
bufcheck.WithPluginsEnabled(),
)
if len(expectedFileAnnotations) == 0 {
assert.NoError(t, err)
Expand Down
8 changes: 0 additions & 8 deletions private/bufpkg/bufcheck/bufcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,6 @@ func WithPluginConfigs(pluginConfigs ...bufconfig.PluginConfig) ClientFunctionOp
}
}

// WithPluginsEnabled returns a new ClientFunctionOption that says to enable the use of plugins.
// Client Methods, such as Client.Lint(), fail if WithPluginConfigs is set without this.
//
// TODO: remove this as part of publicly releasing lint/breaking plugins
func WithPluginsEnabled() ClientFunctionOption {
return pluginsEnabledOption{}
}

// RunnerProvider provides pluginrpc.Runners for a given plugin config.
type RunnerProvider interface {
NewRunner(pluginConfig bufconfig.PluginConfig) (pluginrpc.Runner, error)
Expand Down
57 changes: 1 addition & 56 deletions private/bufpkg/bufcheck/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ func (c *client) Lint(
for _, option := range options {
option.applyToLint(lintOptions)
}
if err := validatePluginConfigs(lintOptions.pluginConfigs, lintOptions.pluginEnabled); err != nil {
return err
}
allRules, allCategories, err := c.allRulesAndCategories(
ctx,
lintConfig.FileVersion(),
Expand Down Expand Up @@ -160,9 +157,6 @@ func (c *client) Breaking(
for _, option := range options {
option.applyToBreaking(breakingOptions)
}
if err := validatePluginConfigs(breakingOptions.pluginConfigs, breakingOptions.pluginEnabled); err != nil {
return err
}
allRules, allCategories, err := c.allRulesAndCategories(
ctx,
breakingConfig.FileVersion(),
Expand Down Expand Up @@ -230,9 +224,6 @@ func (c *client) ConfiguredRules(
for _, option := range options {
option.applyToConfiguredRules(configuredRulesOptions)
}
if err := validatePluginConfigs(configuredRulesOptions.pluginConfigs, configuredRulesOptions.pluginEnabled); err != nil {
return nil, err
}
allRules, allCategories, err := c.allRulesAndCategories(
ctx,
checkConfig.FileVersion(),
Expand Down Expand Up @@ -263,9 +254,6 @@ func (c *client) AllRules(
for _, option := range options {
option.applyToAllRules(allRulesOptions)
}
if err := validatePluginConfigs(allRulesOptions.pluginConfigs, allRulesOptions.pluginEnabled); err != nil {
return nil, err
}
rules, _, err := c.allRulesAndCategories(ctx, fileVersion, allRulesOptions.pluginConfigs, false)
if err != nil {
return nil, err
Expand All @@ -285,9 +273,6 @@ func (c *client) AllCategories(
for _, option := range options {
option.applyToAllCategories(allCategoriesOptions)
}
if err := validatePluginConfigs(allCategoriesOptions.pluginConfigs, allCategoriesOptions.pluginEnabled); err != nil {
return nil, err
}
_, categories, err := c.allRulesAndCategories(ctx, fileVersion, allCategoriesOptions.pluginConfigs, false)
return categories, err
}
Expand Down Expand Up @@ -360,14 +345,6 @@ func (c *client) getMultiClient(
return newMultiClient(c.logger, checkClientSpecs), nil
}

// TODO: remove this as part of publicly releasing lint/breaking plugins
func validatePluginConfigs(pluginConfigs []bufconfig.PluginConfig, isPluginEnabled bool) error {
if len(pluginConfigs) > 0 && !isPluginEnabled {
return fmt.Errorf("custom plugins are not yet supported. For more information, please contact us at https://buf.build/docs/contact")
}
return nil
}

func annotationsToFilteredFileAnnotationSetOrError(
config *config,
image bufimage.Image,
Expand Down Expand Up @@ -510,18 +487,14 @@ func checkCommentLineForCheckIgnore(

type lintOptions struct {
pluginConfigs []bufconfig.PluginConfig
// TODO: remove this as part of publicly releasing lint/breaking plugins
pluginEnabled bool
}

func newLintOptions() *lintOptions {
return &lintOptions{}
}

type breakingOptions struct {
pluginConfigs []bufconfig.PluginConfig
// TODO: remove this as part of publicly releasing lint/breaking plugins
pluginEnabled bool
pluginConfigs []bufconfig.PluginConfig
excludeImports bool
}

Expand All @@ -531,8 +504,6 @@ func newBreakingOptions() *breakingOptions {

type configuredRulesOptions struct {
pluginConfigs []bufconfig.PluginConfig
// TODO: remove this as part of publicly releasing lint/breaking plugins
pluginEnabled bool
}

func newConfiguredRulesOptions() *configuredRulesOptions {
Expand All @@ -541,8 +512,6 @@ func newConfiguredRulesOptions() *configuredRulesOptions {

type allRulesOptions struct {
pluginConfigs []bufconfig.PluginConfig
// TODO: remove this as part of publicly releasing lint/breaking plugins
pluginEnabled bool
}

func newAllRulesOptions() *allRulesOptions {
Expand All @@ -551,8 +520,6 @@ func newAllRulesOptions() *allRulesOptions {

type allCategoriesOptions struct {
pluginConfigs []bufconfig.PluginConfig
// TODO: remove this as part of publicly releasing lint/breaking plugins
pluginEnabled bool
}

func newAllCategoriesOptions() *allCategoriesOptions {
Expand Down Expand Up @@ -596,25 +563,3 @@ func (p *pluginConfigsOption) applyToAllRules(allRulesOptions *allRulesOptions)
func (p *pluginConfigsOption) applyToAllCategories(allCategoriesOptions *allCategoriesOptions) {
allCategoriesOptions.pluginConfigs = append(allCategoriesOptions.pluginConfigs, p.pluginConfigs...)
}

type pluginsEnabledOption struct{}

func (pluginsEnabledOption) applyToLint(lintOptions *lintOptions) {
lintOptions.pluginEnabled = true
}

func (pluginsEnabledOption) applyToBreaking(breakingOptions *breakingOptions) {
breakingOptions.pluginEnabled = true
}

func (pluginsEnabledOption) applyToConfiguredRules(configuredRulesOptions *configuredRulesOptions) {
configuredRulesOptions.pluginEnabled = true
}

func (pluginsEnabledOption) applyToAllRules(allRulesOptions *allRulesOptions) {
allRulesOptions.pluginEnabled = true
}

func (pluginsEnabledOption) applyToAllCategories(allCategoriesOptions *allCategoriesOptions) {
allCategoriesOptions.pluginEnabled = true
}
1 change: 0 additions & 1 deletion private/bufpkg/bufcheck/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,6 @@ func testLintWithOptions(
lintConfig,
image,
bufcheck.WithPluginConfigs(workspace.PluginConfigs()...),
bufcheck.WithPluginsEnabled(),
)
if len(expectedFileAnnotations) == 0 {
assert.NoError(t, err)
Expand Down