Skip to content

Commit

Permalink
add explanation in readme, use go mod edit -require
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinapathak committed May 21, 2024
1 parent 6fa9678 commit d26542f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions cmd/builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ to only execute the compilation step.

### Avoiding the use of a new go.mod file

You can optionally skip creating a new `go.mod` file.
When the `--skip-new-go-module` command-line flag is supplied,
the build process issues a `go get` command for each component,
relying on the Go toolchain to update the enclosing Go module
You can optionally skip creating a new `go.mod` file. This is helpful when
using a monorepo setup with a shared go.mod file. When the `--skip-new-go-module`
command-line flag is supplied, the build process issues a `go get` command for
each component, relying on the Go toolchain to update the enclosing Go module
appropriately.

This command will avoid downgrading a dependency in the enclosing
Expand Down
13 changes: 7 additions & 6 deletions cmd/builder/internal/builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,18 @@ func (c *Config) updateModules() error {
}

func (c *Config) updateGoModule(modspec string) error {
mod, ver, found := strings.Cut(modspec, " ")
if !found {
return fmt.Errorf("ill-formatted modspec %q: missing space separator", modspec)
}

// Re-parse the go.mod file on each iteration, since it can
// change each time.
modulePath, dependencyVersions, err := c.readGoModFile()
if err != nil {
return err
}

mod, ver, found := strings.Cut(modspec, " ")
if !found {
return fmt.Errorf("ill-formatted modspec %q: missing space separator", modspec)
}
if mod == modulePath {
// this component is part of the same module, nothing to update.
return nil
Expand All @@ -295,9 +296,9 @@ func (c *Config) updateGoModule(modspec string) error {
}

// upgrading or changing version
updatespec := mod + "@" + ver
updatespec := "-require=" + mod + "@" + ver

if _, err := runGoCommand(*c, "get", updatespec); err != nil {
if _, err := runGoCommand(*c, "mod", "edit", updatespec); err != nil {
return err
}
return nil
Expand Down

0 comments on commit d26542f

Please sign in to comment.