From f080854abdaed993e913cac2ed8c1aa3d195b0ae Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Tue, 24 Aug 2021 21:37:23 +0300 Subject: [PATCH] Go mod tidy after each go mod edit This prevents errors as it resolves non semantic versions such as latest to semantic ones --- environment.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/environment.go b/environment.go index 49f4166..f885e1e 100644 --- a/environment.go +++ b/environment.go @@ -135,11 +135,6 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) { if err != nil { return nil, err } - // tidy the module to ensure go.mod will not have versions such as `latest` - tidyCmd := env.newCommand("go", "mod", "tidy") - if err := env.runCommand(ctx, tidyCmd, b.TimeoutGet); err != nil { - return nil, err - } replace := fmt.Sprintf("%s=%s", k6ModulePath, b.K6Repo) if b.K6Version != "" { replace = fmt.Sprintf("%s@%s", replace, b.K6Version) @@ -260,7 +255,13 @@ func (env environment) execGoModRequire(ctx context.Context, modulePath, moduleV mod += "@latest" } cmd := env.newCommand("go", "mod", "edit", "-require", mod) - return env.runCommand(ctx, cmd, env.timeoutGoGet) + err := env.runCommand(ctx, cmd, env.timeoutGoGet) + if err != nil { + return err + } + // tidy the module to ensure go.mod will not have versions such as `latest` + tidyCmd := env.newCommand("go", "mod", "tidy") + return env.runCommand(ctx, tidyCmd, env.timeoutGoGet) } type goModTemplateContext struct {