@@ -15,10 +15,11 @@ import (
1515 "github.com/fatih/color"
1616 "github.com/google/go-github/v50/github"
1717 "github.com/google/uuid"
18- "github.com/smartcontractkit/chainlink-testing-framework/framework"
1918 "go.uber.org/ratelimit"
2019 "golang.org/x/oauth2"
2120 "golang.org/x/sync/errgroup"
21+
22+ "github.com/smartcontractkit/chainlink-testing-framework/framework"
2223)
2324
2425const (
3839 SlowTestThreshold = 5 * time .Minute
3940 ExtremelySlowTestThreshold = 10 * time .Minute
4041
41- DebugDirRoot = "ctf-ci-debug"
42- DebugSubDirWF = filepath .Join (DebugDirRoot , "workflows" )
43- DebugSubDirJobs = filepath .Join (DebugDirRoot , "jobs" )
42+ DebugSubDirWF = filepath .Join (DebugDirRoot , "workflows" )
43+ DebugSubDirJobs = filepath .Join (DebugDirRoot , "jobs" )
44+ DefaultResultsDir = "."
45+ DefaultResultsFile = "ctf-ci"
4446)
4547
4648type GitHubActionsClient interface {
@@ -49,38 +51,38 @@ type GitHubActionsClient interface {
4951}
5052
5153type AnalysisConfig struct {
52- Debug bool
53- Owner string
54- Repo string
55- WorkflowName string
56- TimeDaysBeforeStart int
57- TimeStart time.Time
58- TimeDaysBeforeEnd int
59- TimeEnd time.Time
60- Typ string
61- ResultsFile string
54+ Debug bool `json:"debug"`
55+ Owner string `json:"owner"`
56+ Repo string `json:"repo"`
57+ WorkflowName string `json:"workflow_name"`
58+ TimeDaysBeforeStart int `json:"time_days_before_start"`
59+ TimeStart time.Time `json:"time_start"`
60+ TimeDaysBeforeEnd int `json:"time_days_before_end"`
61+ TimeEnd time.Time `json:"time_end"`
62+ Typ string `json:"type"`
63+ ResultsFile string `json:"results_file"`
6264}
6365
6466type Stat struct {
65- Name string
66- Successes int
67- Failures int
68- Cancels int
69- ReRuns int
70- P50 time.Duration
71- P95 time.Duration
72- P99 time.Duration
73- TotalDuration time.Duration
74- Durations []time.Duration
67+ Name string `json:"name"`
68+ Successes int `json:"successes"`
69+ Failures int `json:"failures"`
70+ Cancels int `json:"cancels"`
71+ ReRuns int `json:"reRuns"`
72+ P50 time.Duration `json:"p50"`
73+ P95 time.Duration `json:"p95"`
74+ P99 time.Duration `json:"p99"`
75+ TotalDuration time.Duration `json:"totalDuration"`
76+ Durations []time.Duration `json:"-"`
7577}
7678
7779type Stats struct {
78- Mu * sync.Mutex
79- Runs int
80- CancelledRuns int
81- IgnoredRuns int
82- Jobs map [string ]* Stat
83- Steps map [string ]* Stat
80+ Mu * sync.Mutex `json:"-"`
81+ Runs int `json:"runs"`
82+ CancelledRuns int `json:"cancelled_runs"`
83+ IgnoredRuns int `json:"ignored_runs"`
84+ Jobs map [string ]* Stat `json:"jobs"`
85+ Steps map [string ]* Stat `json:"steps"`
8486}
8587
8688func calculatePercentiles (stat * Stat ) * Stat {
@@ -102,7 +104,7 @@ func refreshDebugDirs() {
102104 }
103105}
104106
105- func writeStruct (enabled bool , dir , name string , data interface {}) error {
107+ func dumpResults (enabled bool , dir , name string , data interface {}) error {
106108 if enabled {
107109 d , err := json .MarshalIndent (data , "" , " " )
108110 if err != nil {
@@ -135,6 +137,7 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
135137
136138 eg := & errgroup.Group {}
137139 for _ , wr := range runs .WorkflowRuns {
140+ framework .L .Debug ().Str ("Name" , * wr .Name ).Msg ("Analyzing workflow run" )
138141 if ! strings .Contains (* wr .Name , cfg .WorkflowName ) {
139142 stats .IgnoredRuns ++
140143 continue
@@ -143,7 +146,7 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
143146 // analyze workflow
144147 name := * wr .Name
145148 framework .L .Debug ().Str ("Name" , name ).Msg ("Analyzing workflow run" )
146- _ = writeStruct (cfg .Debug , DebugSubDirWF , name , wr )
149+ _ = dumpResults (cfg .Debug , DebugSubDirWF , name , wr )
147150 eg .Go (func () error {
148151 rlJobs .Take ()
149152 jobs , _ , err := client .ListWorkflowJobs (ctx , cfg .Owner , cfg .Repo , * wr .ID , & github.ListWorkflowJobsOptions {
@@ -153,11 +156,11 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
153156 return err
154157 }
155158 // analyze jobs
159+ stats .Mu .Lock ()
160+ defer stats .Mu .Unlock ()
156161 for _ , j := range jobs .Jobs {
157- stats .Mu .Lock ()
158- defer stats .Mu .Unlock ()
159162 name := * j .Name
160- _ = writeStruct (cfg .Debug , DebugSubDirJobs , name , wr )
163+ _ = dumpResults (cfg .Debug , DebugSubDirJobs , name , wr )
161164 if skippedOrInProgressJob (j ) {
162165 stats .IgnoredRuns ++
163166 continue
@@ -281,6 +284,9 @@ func AnalyzeCIRuns(cfg *AnalysisConfig) (*Stats, error) {
281284 if err != nil {
282285 return nil , fmt .Errorf ("failed to fetch workflow runs: %w" , err )
283286 }
287+ if cfg .ResultsFile != "" {
288+ _ = dumpResults (true , DefaultResultsDir , DefaultResultsFile , stats )
289+ }
284290 return stats , nil
285291}
286292
0 commit comments