Skip to content

Commit 8f16efb

Browse files
author
Bryan C. Mills
committed
greplogs: set more flag defaults when --triage is set
Also omit builders with known issues when --triage is set. For golang/go#52653.
1 parent f32396e commit 8f16efb

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

Diff for: greplogs/_embed/broken.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Command broken lists the current Go builders with known issues.
6+
//
7+
// To test this program, cd to its directory and run:
8+
// go mod init
9+
// go get golang.org/x/build/dashboard@HEAD
10+
// go run .
11+
// rm go.mod go.sum
12+
package main
13+
14+
import (
15+
"fmt"
16+
17+
"golang.org/x/build/dashboard"
18+
)
19+
20+
func main() {
21+
for _, b := range dashboard.Builders {
22+
if len(b.KnownIssues) > 0 {
23+
fmt.Println(b.Name)
24+
}
25+
}
26+
}

Diff for: greplogs/broken.go

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
_ "embed"
9+
"fmt"
10+
"os"
11+
"os/exec"
12+
"path/filepath"
13+
"sort"
14+
"strings"
15+
)
16+
17+
//go:embed _embed/broken.go
18+
var brokenScript []byte
19+
20+
// listBrokenBuilders returns the builders that are marked
21+
// as broken in golang.org/x/build/dashboard at HEAD.
22+
func listBrokenBuilders() (broken []string, err error) {
23+
defer func() {
24+
if err != nil {
25+
err = fmt.Errorf("identifying broken builders: %v", err)
26+
}
27+
}()
28+
29+
modDir, err := os.MkdirTemp("", "greplogs")
30+
if err != nil {
31+
return nil, err
32+
}
33+
defer func() {
34+
removeErr := os.RemoveAll(modDir)
35+
if err == nil {
36+
err = removeErr
37+
}
38+
}()
39+
40+
runCommand := func(name string, args ...string) ([]byte, error) {
41+
cmd := exec.Command(name, args...)
42+
cmd.Dir = modDir
43+
cmd.Env = append(os.Environ(), "GO111MODULE=on", "PWD="+modDir)
44+
cmd.Stderr = new(strings.Builder)
45+
46+
out, err := cmd.Output()
47+
if err != nil {
48+
return out, fmt.Errorf("%s: %w\nstderr:\n%s", strings.Join(cmd.Args, " "), err, cmd.Stderr)
49+
}
50+
return out, nil
51+
}
52+
53+
_, err = runCommand("go", "mod", "init", "github.com/aclements/go-misc/greplogs/_embed")
54+
if err != nil {
55+
return nil, err
56+
}
57+
58+
_, err = runCommand("go", "get", "golang.org/x/build/dashboard@HEAD")
59+
if err != nil {
60+
return nil, err
61+
}
62+
63+
err = os.WriteFile(filepath.Join(modDir, "broken.go"), brokenScript, 0644)
64+
if err != nil {
65+
return nil, err
66+
}
67+
68+
out, err := runCommand("go", "run", "broken.go")
69+
if err != nil {
70+
return nil, err
71+
}
72+
73+
broken = strings.Split(strings.TrimSpace(string(out)), "\n")
74+
sort.Strings(broken)
75+
return broken, nil
76+
}

Diff for: greplogs/main.go

+30
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const (
6464
colorMatch = colorBold | colorFgRed
6565
)
6666

67+
var brokenBuilders []string
68+
6769
func main() {
6870
// XXX What I want right now is just to point it at a bunch of
6971
// logs and have it extract the failures.
@@ -91,6 +93,29 @@ func main() {
9193
os.Exit(2)
9294
}
9395

96+
if *flagTriage {
97+
*flagFilesOnly = true
98+
if len(failRegexps) == 0 && len(fileRegexps) == 0 {
99+
failRegexps.Set(".")
100+
}
101+
102+
if before.Time.IsZero() {
103+
year, month, day := time.Now().UTC().Date()
104+
before = timeFlag{Time: time.Date(year, month, day, 0, 0, 0, 0, time.UTC)}
105+
}
106+
107+
var err error
108+
brokenBuilders, err = listBrokenBuilders()
109+
if err != nil {
110+
fmt.Fprintln(os.Stderr, err)
111+
os.Exit(1)
112+
}
113+
if len(brokenBuilders) > 0 {
114+
fmt.Fprintf(os.Stderr, "omitting builders with known issues:\n\t%s\n\n", strings.Join(brokenBuilders, "\n\t"))
115+
}
116+
117+
}
118+
94119
status := 1
95120
defer func() { os.Exit(status) }()
96121

@@ -169,6 +194,11 @@ var pathDateRE = regexp.MustCompile(`^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})-([0-
169194
func process(path, nicePath string) (found bool, err error) {
170195
// If this is from the dashboard, filter by builder and date and get the builder URL.
171196
builder := filepath.Base(nicePath)
197+
for _, b := range brokenBuilders {
198+
if builder == b {
199+
return false, nil
200+
}
201+
}
172202
if omit.AnyMatchString(builder) {
173203
return false, nil
174204
}

0 commit comments

Comments
 (0)