Skip to content

Commit

Permalink
Fix update-modules not updating non public modules (#1444)
Browse files Browse the repository at this point in the history
* Fix update-modules not updating non public modules

* Bump non public modules import path version

* genmod: drop pkg/errors dependency
  • Loading branch information
carsonip authored May 22, 2023
1 parent bcfd117 commit 72f5e12
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
4 changes: 2 additions & 2 deletions internal/apmgodog/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module apmgodog
module apmgodog/v2

go 1.13
go 1.15

require (
github.com/cucumber/godog v0.12.2
Expand Down
6 changes: 3 additions & 3 deletions internal/tracecontexttest/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module tracecontexttest
module tracecontexttest/v2

require go.elastic.co/apm/module/apmhttp/v2 v2.0.0
require go.elastic.co/apm/module/apmhttp/v2 v2.4.1

replace go.elastic.co/apm/v2 => ../..

replace go.elastic.co/apm/module/apmhttp/v2 => ../../module/apmhttp

go 1.13
go 1.15
6 changes: 3 additions & 3 deletions module/apmelasticsearch/internal/integration/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module apmelasticsearch_integration
module apmelasticsearch_integration/v2

require (
github.com/elastic/go-elasticsearch/v7 v7.5.0
github.com/fortytw2/leaktest v1.3.0 // indirect
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 // indirect
github.com/olivere/elastic v6.2.16+incompatible
github.com/stretchr/testify v1.6.1
go.elastic.co/apm/module/apmelasticsearch/v2 v2.1.0
go.elastic.co/apm/module/apmelasticsearch/v2 v2.4.1
go.elastic.co/apm/v2 v2.4.1
)

Expand All @@ -16,4 +16,4 @@ replace go.elastic.co/apm/module/apmelasticsearch/v2 => ../..

replace go.elastic.co/apm/module/apmhttp/v2 => ../../../apmhttp

go 1.13
go 1.15
5 changes: 2 additions & 3 deletions scripts/genmod/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module genmod
module genmod/v2

require (
github.com/pkg/errors v0.9.1
go.elastic.co/apm/v2 v2.1.0
go.elastic.co/apm/v2 v2.4.1
golang.org/x/mod v0.5.1
)

Expand Down
20 changes: 8 additions & 12 deletions scripts/genmod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"strconv"
"strings"

"github.com/pkg/errors"
"golang.org/x/mod/semver"

"go.elastic.co/apm/v2"
Expand Down Expand Up @@ -88,10 +87,7 @@ func main() {
if err != nil {
return err
}
// Skip non-public modules.
if strings.HasPrefix(gomod.Module.Path, "go.elastic.co/apm") {
modules[gomod.Module.Path] = gomod
}
modules[gomod.Module.Path] = gomod
}
return nil
}
Expand Down Expand Up @@ -156,13 +152,13 @@ func updateModule(dir string, gomod *GoMod, modules map[string]*GoMod) error {
cmd.Stderr = os.Stderr
cmd.Dir = dir
if err := cmd.Run(); err != nil {
return err
return fmt.Errorf("'go mod edit' failed: %w", err)
}
}
return nil
}

// checkModule checks that the require stanzas in $dir/go.mod have the
// checkModule checks that the required stanzas in $dir/go.mod have the
// correct versions, appropriate matching "replace" stanzas, and the
// correct required Go version (if -go is specified).
func checkModule(dir string, gomod *GoMod, modules map[string]*GoMod) error {
Expand Down Expand Up @@ -223,7 +219,7 @@ func checkModule(dir string, gomod *GoMod, modules map[string]*GoMod) error {
}
}
if gomodBad {
return errors.Errorf("%s/go.mod invalid", gomod.dir)
return fmt.Errorf("%s/go.mod invalid", gomod.dir)
}
return nil
}
Expand All @@ -237,7 +233,7 @@ func checkModuleComplete(dir string, gomod *GoMod, modules map[string]*GoMod) er
cmd.Stderr = os.Stderr
cmd.Dir = gomod.dir
if err := cmd.Run(); err != nil {
return errors.Wrap(err, "'go mod download' failed")
return fmt.Errorf("'go mod download' failed: %w", err)
}

// Check we can build the module's tests and its transitive dependencies
Expand All @@ -246,7 +242,7 @@ func checkModuleComplete(dir string, gomod *GoMod, modules map[string]*GoMod) er
cmd.Stderr = os.Stderr
cmd.Dir = gomod.dir
if err := cmd.Run(); err != nil {
return errors.Wrap(err, "'go test' failed")
return fmt.Errorf("'go test' failed: %w", err)
}

// We create a temporary program which imports the module, and then
Expand Down Expand Up @@ -308,7 +304,7 @@ func main() {}
cmd.Stderr = os.Stderr
cmd.Dir = tmpdir
if err := cmd.Run(); err != nil {
return err
return fmt.Errorf("'go mod tidy' failed: %w", err)
}

cmd = exec.Command("diff", "-c", "-", "--label=old", tmpGomodPath, "--label=new")
Expand All @@ -330,7 +326,7 @@ func required(path string, modules map[string]*GoMod) []string {
}

// toposort topologically sorts the required modules, starting
// with the moduled specified by path.
// with the module specified by path.
func toposort(path string, modules map[string]*GoMod, seen map[string]bool, paths *[]string) {
if seen[path] {
return
Expand Down

0 comments on commit 72f5e12

Please sign in to comment.