Skip to content
Permalink
Browse files
fix(internal/gapicgen): filter out internal directory changes (#4085)
- Filter out internal dir changes since they do not need a module
  update.
- Remove unneeded param from method
- Log extra details when a excuting a command yields an error
  • Loading branch information
codyoss committed May 12, 2021
1 parent 80b9422 commit 01473f6d8db26c6e18969ace7f9e87c66e94ad9e
Showing with 28 additions and 12 deletions.
  1. +1 −1 internal/gapicgen/cmd/genbot/update.go
  2. +20 −2 internal/gapicgen/execv/command.go
  3. +7 −9 internal/gapicgen/git/github.go
@@ -30,7 +30,7 @@ func updateGocloudPR(ctx context.Context, githubClient *git.GithubClient, pr *gi
}

// Checkout PR and update go.mod
if err := githubClient.UpdateGocloudGoMod(pr); err != nil {
if err := githubClient.UpdateGocloudGoMod(); err != nil {
return err
}

@@ -41,8 +41,26 @@ func Command(name string, arg ...string) *CmdWrapper {

// Run a command.
func (c *CmdWrapper) Run() error {
log.Printf("[%s] >>>> %v <<<<", c.Dir, strings.Join(c.Args, " ")) // NOTE: we have some multi-line commands, make it clear where the command starts and ends
return c.Cmd.Run()
log.Printf("[%s] >>>> %v <<<<", c.Dir, strings.Join(c.Args, " "))
err := c.Cmd.Run()
if err != nil {
if ee, ok := err.(*exec.ExitError); ok {
log.Println(string(ee.Stderr))
}
}
return err
}

// Output a command.
func (c *CmdWrapper) Output() ([]byte, error) {
log.Printf("[%s] >>>> %v <<<<", c.Dir, strings.Join(c.Args, " "))
b, err := c.Cmd.Output()
if err != nil {
if ee, ok := err.(*exec.ExitError); ok {
log.Println(string(ee.Stderr))
}
}
return b, err
}

// ForEachMod runs the given function with the directory of
@@ -15,7 +15,6 @@
package git

import (
"bytes"
"context"
"errors"
"fmt"
@@ -336,7 +335,7 @@ func (gc *GithubClient) MarkPRReadyForReview(ctx context.Context, repo string, n

// UpdateGocloudGoMod updates the go.mod to include latest version of genproto
// for the given gocloud ref.
func (gc *GithubClient) UpdateGocloudGoMod(pr *PullRequest) error {
func (gc *GithubClient) UpdateGocloudGoMod() error {
tmpDir, err := ioutil.TempDir("", "finalize-github-pr")
if err != nil {
return err
@@ -374,26 +373,25 @@ git checkout $BRANCH_NAME

func updateDeps(tmpDir string) error {
// Find directories that had code changes.
out := bytes.NewBuffer(nil)
c := execv.Command("git", "diff", "--name-only", "HEAD", "HEAD~1")
c.Stdout = out
c.Dir = tmpDir
if err := c.Run(); err != nil {
out, err := c.Output()
if err != nil {
return err
}
files := strings.Split(out.String(), "\n")
files := strings.Split(string(out), "\n")
dirs := map[string]bool{}
for _, file := range files {
if strings.HasPrefix(file, "internal") {
continue
}
dir := filepath.Dir(file)
dirs[filepath.Join(tmpDir, dir)] = true
}

// Find which modules had code changes.
updatedModDirs := map[string]bool{}
errWriter := bytes.NewBuffer(nil)
for dir := range dirs {
out.Reset()
errWriter.Reset()
modDir, err := gocmd.ListModDirName(dir)
if err != nil {
if errors.Is(err, gocmd.ErrBuildConstraint) {

0 comments on commit 01473f6

Please sign in to comment.