-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
main.go
72 lines (59 loc) · 2.01 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"flag"
"io"
"log"
"os"
"os/signal"
"strings"
"github.com/smartcontractkit/chainlink/v2/tools/flakeytests"
)
const numReruns = 2
func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
go func() {
<-ctx.Done()
stop() // restore default exit behavior
log.Println("Cancelling... interrupt again to exit")
}()
grafanaHost := flag.String("grafana_host", "", "grafana host URL")
grafanaAuth := flag.String("grafana_auth", "", "grafana basic auth for Loki API")
grafanaOrgID := flag.String("grafana_org_id", "", "grafana org ID")
command := flag.String("command", "", "test command being rerun; used to tag metrics")
ghSHA := flag.String("gh_sha", "", "commit sha for which we're rerunning tests")
ghEventPath := flag.String("gh_event_path", "", "path to associated gh event")
ghEventName := flag.String("gh_event_name", "", "type of associated gh event")
ghRepo := flag.String("gh_repo", "", "name of gh repository")
ghRunID := flag.String("gh_run_id", "", "run id of the gh workflow")
flag.Parse()
if *grafanaHost == "" {
log.Fatal("Error re-running flakey tests: `grafana_host` is required")
}
if *grafanaAuth == "" {
log.Fatal("Error re-running flakey tests: `grafana_auth` is required")
}
if *grafanaOrgID == "" {
log.Fatal("Error re-running flakey tests: `grafana_org_id` is required")
}
if *command == "" {
log.Fatal("Error re-running flakey tests: `command` is required")
}
args := flag.Args()
log.Printf("Parsing output at: %v", strings.Join(args, ", "))
readers := []io.Reader{}
for _, f := range args {
r, err := os.Open(f)
if err != nil {
log.Fatal(err)
}
readers = append(readers, r)
}
meta := flakeytests.GetGithubMetadata(*ghRepo, *ghEventName, *ghSHA, *ghEventPath, *ghRunID)
rep := flakeytests.NewLokiReporter(*grafanaHost, *grafanaAuth, *grafanaOrgID, *command, meta)
r := flakeytests.NewRunner(readers, rep, numReruns)
err := r.Run(ctx)
if err != nil {
log.Fatalf("Error re-running flakey tests: %s", err)
}
}