From 23cf5971cfd26752c26445575132a0e0e4f0b473 Mon Sep 17 00:00:00 2001 From: Cody Oss <6331106+codyoss@users.noreply.github.com> Date: Tue, 30 May 2023 16:38:14 -0500 Subject: [PATCH] chore(internal/postprocessor): ensure new modules are added to workspace (#8013) --- internal/postprocessor/execv/gocmd/gocmd.go | 7 +++++++ internal/postprocessor/main.go | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/postprocessor/execv/gocmd/gocmd.go b/internal/postprocessor/execv/gocmd/gocmd.go index 0224622e6a00..cbda042eab96 100644 --- a/internal/postprocessor/execv/gocmd/gocmd.go +++ b/internal/postprocessor/execv/gocmd/gocmd.go @@ -138,3 +138,10 @@ func EditReplace(dir, mod, modPath string) error { } return c.Run() } + +// WorkUse updates the go.work file for added modules. +func WorkUse(dir string) error { + c := execv.Command("go", "work", "use", "-r", ".") + c.Dir = dir + return c.Run() +} diff --git a/internal/postprocessor/main.go b/internal/postprocessor/main.go index 38707c6cba68..319353f93f5a 100644 --- a/internal/postprocessor/main.go +++ b/internal/postprocessor/main.go @@ -250,7 +250,11 @@ func (p *postProcessor) generateModule(modPath, importPath string) error { return err } log.Printf("Creating %s/go.mod", modPath) - return gocmd.ModInit(modPath, importPath) + if err := gocmd.ModInit(modPath, importPath); err != nil { + return err + } + log.Print("Updating workspace") + return gocmd.WorkUse(p.googleCloudDir) } func (p *postProcessor) generateVersionFile(moduleName, path string) error {