From f4cb783626375e1cd9330e925b836cdaccc44663 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 18 May 2023 00:01:53 +0000 Subject: [PATCH] [tools][perfmon]: Minor improvements * Ignore changes on non-main branches * Increase the timeout for git cloning the repo * Improve the error message on git error Change-Id: I22af2b8042c14c3c413f52d65dc5b89b7f5c3f11 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132820 Kokoro: Kokoro Commit-Queue: Ben Clayton Reviewed-by: Antonio Maiorano --- tools/src/cmd/perfmon/main.go | 6 ++++++ tools/src/git/git.go | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/src/cmd/perfmon/main.go b/tools/src/cmd/perfmon/main.go index 530bbd9829..bcaf8e9320 100644 --- a/tools/src/cmd/perfmon/main.go +++ b/tools/src/cmd/perfmon/main.go @@ -863,6 +863,11 @@ func (e env) findGerritChangeToBenchmark() (*gerrit.ChangeInfo, error) { } canBenchmark := func() bool { + // Don't benchmark changes on non-main branches + if change.Branch != "main" { + return false + } + // Is the change from a Googler, reviewed by a Googler or is from a allow-listed external developer? if !(strings.HasSuffix(current.Commit.Committer.Email, "@google.com") || strings.HasSuffix(change.Labels["Code-Review"].Approved.Email, "@google.com") || @@ -1045,6 +1050,7 @@ func createOrOpenGitRepo(g *git.Git, filepath string, cfg GitConfig) (*git.Repos repo, err = g.Clone(filepath, cfg.URL, &git.CloneOptions{ Branch: cfg.Branch, Credentials: cfg.Credentials, + Timeout: time.Minute * 30, }) } if err != nil { diff --git a/tools/src/git/git.go b/tools/src/git/git.go index 9af245f39f..f949cf638d 100644 --- a/tools/src/git/git.go +++ b/tools/src/git/git.go @@ -472,8 +472,11 @@ func (g Git) run(dir string, env []string, timeout time.Duration, args ...string fmt.Println(string(out)) } if err != nil { - return string(out), fmt.Errorf("%v> %v %v failed:\n %w\n%v", - dir, g.exe, strings.Join(args, " "), err, string(out)) + msg := fmt.Sprintf("%v> %v %v failed:", dir, g.exe, strings.Join(args, " ")) + if err := ctx.Err(); err != nil { + msg += "\n" + err.Error() + } + return string(out), fmt.Errorf("%s\n %w\n%v", msg, err, string(out)) } return strings.TrimSpace(string(out)), nil }