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 8, 2024
1 parent 3cfa1df commit 3b91ace
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)

Check warning on line 269 in cmd/builder/internal/builder/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/builder/internal/builder/main.go#L266-L269

Added lines #L266 - L269 were not covered by tests
}

// 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

Check warning on line 276 in cmd/builder/internal/builder/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/builder/internal/builder/main.go#L274-L276

Added lines #L274 - L276 were not covered by tests
}

mod, ver, found := strings.Cut(modspec, " ")
if !found {
return fmt.Errorf("ill-formatted modspec %q: missing space separator", modspec)
}
if mod == modulePath {

Check warning on line 279 in cmd/builder/internal/builder/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/builder/internal/builder/main.go#L279

Added line #L279 was not covered by tests
// this component is part of the same module, nothing to update.
return nil

Check warning on line 281 in cmd/builder/internal/builder/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/builder/internal/builder/main.go#L281

Added line #L281 was not covered by tests
Expand All @@ -295,9 +296,9 @@ func (c *Config) updateGoModule(modspec string) error {
}

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

Check warning on line 299 in cmd/builder/internal/builder/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/builder/internal/builder/main.go#L299

Added line #L299 was not covered by tests

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

Check warning on line 302 in cmd/builder/internal/builder/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/builder/internal/builder/main.go#L301-L302

Added lines #L301 - L302 were not covered by tests
}
return nil

Check warning on line 304 in cmd/builder/internal/builder/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/builder/internal/builder/main.go#L304

Added line #L304 was not covered by tests
Expand Down

0 comments on commit 3b91ace

Please sign in to comment.