From 2ee5d4e874ea562c91fd2434a5efe2adfdb4c198 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 17 Apr 2024 13:20:41 +0200 Subject: [PATCH 1/2] fix: use plugin version --- pkg/commands/internal/builder.go | 57 ++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/pkg/commands/internal/builder.go b/pkg/commands/internal/builder.go index 39ec2a251c37..d263e8f4f859 100644 --- a/pkg/commands/internal/builder.go +++ b/pkg/commands/internal/builder.go @@ -53,9 +53,9 @@ func (b Builder) Build(ctx context.Context) error { b.log.Infof("Adding replace directives") - err = b.addReplaceDirectives(ctx) + err = b.addToGoMod(ctx) if err != nil { - return fmt.Errorf("add replace directives: %w", err) + return fmt.Errorf("add to go.mod: %w", err) } b.log.Infof("Running go mod tidy") @@ -103,25 +103,56 @@ func (b Builder) clone(ctx context.Context) error { return nil } -func (b Builder) addReplaceDirectives(ctx context.Context) error { +func (b Builder) addToGoMod(ctx context.Context) error { for _, plugin := range b.cfg.Plugins { - if plugin.Path == "" { + if plugin.Path != "" { + err := b.addReplaceDirective(ctx, plugin) + if err != nil { + return err + } + continue } - replace := fmt.Sprintf("%s=%s", plugin.Module, plugin.Path) + err := b.goGet(ctx, plugin) + if err != nil { + return err + } + } + + return nil +} - cmd := exec.CommandContext(ctx, "go", "mod", "edit", "-replace", replace) - cmd.Dir = b.repo +func (b Builder) goGet(ctx context.Context, plugin *Plugin) error { + //nolint:gosec // the variables user related. + cmd := exec.CommandContext(ctx, "go", "get", plugin.Module+"@"+plugin.Version) + cmd.Dir = b.repo - b.log.Infof("run: %s", strings.Join(cmd.Args, " ")) + b.log.Infof("run: %s", strings.Join(cmd.Args, " ")) - output, err := cmd.CombinedOutput() - if err != nil { - b.log.Warnf(string(output)) + output, err := cmd.CombinedOutput() + if err != nil { + b.log.Warnf(string(output)) - return fmt.Errorf("%s: %w", strings.Join(cmd.Args, " "), err) - } + return fmt.Errorf("%s: %w", strings.Join(cmd.Args, " "), err) + } + + return nil +} + +func (b Builder) addReplaceDirective(ctx context.Context, plugin *Plugin) error { + replace := fmt.Sprintf("%s=%s", plugin.Module, plugin.Path) + + cmd := exec.CommandContext(ctx, "go", "mod", "edit", "-replace", replace) + cmd.Dir = b.repo + + b.log.Infof("run: %s", strings.Join(cmd.Args, " ")) + + output, err := cmd.CombinedOutput() + if err != nil { + b.log.Warnf(string(output)) + + return fmt.Errorf("%s: %w", strings.Join(cmd.Args, " "), err) } return nil From 26d92719c03001576ea72429106f025ec5fd7cb7 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 18 Apr 2024 01:11:59 +0200 Subject: [PATCH 2/2] chore: fix typo --- pkg/commands/internal/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/internal/builder.go b/pkg/commands/internal/builder.go index d263e8f4f859..7253615a45e5 100644 --- a/pkg/commands/internal/builder.go +++ b/pkg/commands/internal/builder.go @@ -124,7 +124,7 @@ func (b Builder) addToGoMod(ctx context.Context) error { } func (b Builder) goGet(ctx context.Context, plugin *Plugin) error { - //nolint:gosec // the variables user related. + //nolint:gosec // the variables are user related. cmd := exec.CommandContext(ctx, "go", "get", plugin.Module+"@"+plugin.Version) cmd.Dir = b.repo