3939 SlowTestThreshold = 5 * time .Minute
4040 ExtremelySlowTestThreshold = 10 * time .Minute
4141
42- DebugDirRoot = "ctf-ci-debug"
43- DebugSubDirWF = filepath .Join (DebugDirRoot , "workflows" )
44- DebugSubDirJobs = filepath .Join (DebugDirRoot , "jobs" )
42+ DebugDirRoot = "ctf-ci-debug"
43+ DebugSubDirWF = filepath .Join (DebugDirRoot , "workflows" )
44+ DebugSubDirJobs = filepath .Join (DebugDirRoot , "jobs" )
45+ DefaultResultsDir = "."
46+ DefaultResultsFile = "ctf-ci"
4547)
4648
4749type GitHubActionsClient interface {
@@ -50,38 +52,38 @@ type GitHubActionsClient interface {
5052}
5153
5254type AnalysisConfig struct {
53- Debug bool
54- Owner string
55- Repo string
56- WorkflowName string
57- TimeDaysBeforeStart int
58- TimeStart time.Time
59- TimeDaysBeforeEnd int
60- TimeEnd time.Time
61- Typ string
62- ResultsFile string
55+ Debug bool `json:"debug"`
56+ Owner string `json:"owner"`
57+ Repo string `json:"repo"`
58+ WorkflowName string `json:"workflow_name"`
59+ TimeDaysBeforeStart int `json:"time_days_before_start"`
60+ TimeStart time.Time `json:"time_start"`
61+ TimeDaysBeforeEnd int `json:"time_days_before_end"`
62+ TimeEnd time.Time `json:"time_end"`
63+ Typ string `json:"type"`
64+ ResultsFile string `json:"results_file"`
6365}
6466
6567type Stat struct {
66- Name string
67- Successes int
68- Failures int
69- Cancels int
70- ReRuns int
71- P50 time.Duration
72- P95 time.Duration
73- P99 time.Duration
74- TotalDuration time.Duration
75- Durations []time.Duration
68+ Name string `json:"name"`
69+ Successes int `json:"successes"`
70+ Failures int `json:"failures"`
71+ Cancels int `json:"cancels"`
72+ ReRuns int `json:"reRuns"`
73+ P50 time.Duration `json:"p50"`
74+ P95 time.Duration `json:"p95"`
75+ P99 time.Duration `json:"p99"`
76+ TotalDuration time.Duration `json:"totalDuration"`
77+ Durations []time.Duration `json:"-"`
7678}
7779
7880type Stats struct {
79- Mu * sync.Mutex
80- Runs int
81- CancelledRuns int
82- IgnoredRuns int
83- Jobs map [string ]* Stat
84- Steps map [string ]* Stat
81+ Mu * sync.Mutex `json:"-"`
82+ Runs int `json:"runs"`
83+ CancelledRuns int `json:"cancelled_runs"`
84+ IgnoredRuns int `json:"ignored_runs"`
85+ Jobs map [string ]* Stat `json:"jobs"`
86+ Steps map [string ]* Stat `json:"steps"`
8587}
8688
8789func calculatePercentiles (stat * Stat ) * Stat {
@@ -103,7 +105,7 @@ func refreshDebugDirs() {
103105 }
104106}
105107
106- func writeStruct (enabled bool , dir , name string , data interface {}) error {
108+ func dumpResults (enabled bool , dir , name string , data interface {}) error {
107109 if enabled {
108110 d , err := json .MarshalIndent (data , "" , " " )
109111 if err != nil {
@@ -145,7 +147,7 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
145147 // analyze workflow
146148 name := * wr .Name
147149 framework .L .Debug ().Str ("Name" , name ).Msg ("Analyzing workflow run" )
148- _ = writeStruct (cfg .Debug , DebugSubDirWF , name , wr )
150+ _ = dumpResults (cfg .Debug , DebugSubDirWF , name , wr )
149151 eg .Go (func () error {
150152 rlJobs .Take ()
151153 jobs , _ , err := client .ListWorkflowJobs (ctx , cfg .Owner , cfg .Repo , * wr .ID , & github.ListWorkflowJobsOptions {
@@ -159,7 +161,7 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
159161 defer stats .Mu .Unlock ()
160162 for _ , j := range jobs .Jobs {
161163 name := * j .Name
162- _ = writeStruct (cfg .Debug , DebugSubDirJobs , name , wr )
164+ _ = dumpResults (cfg .Debug , DebugSubDirJobs , name , wr )
163165 if skippedOrInProgressJob (j ) {
164166 stats .IgnoredRuns ++
165167 continue
@@ -283,6 +285,9 @@ func AnalyzeCIRuns(cfg *AnalysisConfig) (*Stats, error) {
283285 if err != nil {
284286 return nil , fmt .Errorf ("failed to fetch workflow runs: %w" , err )
285287 }
288+ if cfg .ResultsFile != "" {
289+ _ = dumpResults (true , DefaultResultsDir , DefaultResultsFile , stats )
290+ }
286291 return stats , nil
287292}
288293
0 commit comments