Skip to content

Commit

Permalink
fix(internal/godocfx): set exit code, print cmd output, no go get ... (
Browse files Browse the repository at this point in the history
  • Loading branch information
tbpg authored Jul 15, 2021
1 parent f6258a4 commit cc70f77
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/godocfx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,30 @@ func main() {
}
// Use a fake module that doesn't start with cloud.google.com/go.
runCmd(workingDir, "go", "mod", "init", "cloud.google.com/lets-build-some-docs")

failed := false
for _, m := range mods {
log.Printf("Processing %s@%s", m.Path, m.Version)

// Always output to specific directory.
path := filepath.Join(*outDir, fmt.Sprintf("%s@%s", m.Path, m.Version))
if err := process(m, workingDir, path, *print); err != nil {
log.Printf("Failed to process %v: %v", m, err)
failed = true
}
log.Printf("Done with %s@%s", m.Path, m.Version)
}
if failed {
os.Exit(1)
}
}

func runCmd(dir, name string, args ...string) error {
log.Printf("> [%s] %s %s", dir, name, strings.Join(args, " "))
cmd := exec.Command(name, args...)
cmd.Dir = dir
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
return fmt.Errorf("Start: %v", err)
}
Expand All @@ -143,7 +151,8 @@ func process(mod indexEntry, workingDir, outDir string, print bool) error {
if err := runCmd(workingDir, "go", "mod", "tidy"); err != nil {
return fmt.Errorf("go mod tidy error: %v", err)
}
if err := runCmd(workingDir, "go", "get", "-d", "-t", mod.Path+"/...@"+mod.Version); err != nil {
// 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)
}

Expand Down

0 comments on commit cc70f77

Please sign in to comment.