Skip to content

Commit

Permalink
fix(internal/godocfx): retry go get with explicit envoy dependency (#…
Browse files Browse the repository at this point in the history
…11564)

This is a bit of a hack. Alternatively, we could capture stderr and check for the ambiguous import string before retrying.

This gets around errors of the form:
```
        github.com/envoyproxy/go-control-plane/envoy/type/matcher/v3: ambiguous import: found package github.com/envoyproxy/go-control-plane/envoy/type/matcher/v3 in multiple modules:
```

I confirmed this works by running it locally (fails before this commit, succeeds after):

```
go run . cloud.google.com/go/bigquery
```

I also removed the now-deprecated `-d` flag.
  • Loading branch information
tbpg authored Feb 5, 2025
1 parent 8f38b3d commit a06a6a5
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions internal/godocfx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,26 @@ func process(mod indexEntry, workingDir, outDir string, namer *friendlyAPINamer,
return fmt.Errorf("go mod tidy error: %v", err)
}
// Don't do /... because it fails on submodules.
if err := runCmd(workingDir, "go", "get", "-d", "-t", mod.Path+"@"+mod.Version); err != nil {
return fmt.Errorf("go get %s@%s: %v", mod.Path, mod.Version, err)
module := mod.Path + "@" + mod.Version
if err := runCmd(workingDir, "go", "get", "-t", module); err != nil {
// Retry to work around https://github.com/googleapis/google-cloud-go/issues/11542.
// First, add an explicit dependency on the Envoy module, then try getting the
// module to document.
// This can be removed in the future if you create a new, empty module and can
// successfully run `go get -t cloud.google.com/go/[email protected]`.
// Alternatively, we could check stderr for the "ambiguous import" error, but this seems
// simpler.
log.Printf("go get -t %s failed: %v", module, err)
log.Printf("Adding hack to depend on envoy and retrying")

if err := runCmd(workingDir, "go", "get", "github.com/envoyproxy/go-control-plane/envoy"); err != nil {
return fmt.Errorf("go get github.com/envoyproxy/go-control-plane/envoy failed: %v", err)
}

log.Printf("Trying again with %s", module)
if err := runCmd(workingDir, "go", "get", "-t", module); err != nil {
return fmt.Errorf("go get -t %s@%s failed again: %v", mod.Path, mod.Version, err)
}
}

log.Println("Starting to parse")
Expand Down

0 comments on commit a06a6a5

Please sign in to comment.