Skip to content

Commit 7fb9df8

Browse files
committed
Merge branch 'main' into devbox
# Conflicts: # framework/cmd/ci.go
2 parents e81af05 + 0688f5e commit 7fb9df8

File tree

5 files changed

+49
-41
lines changed

5 files changed

+49
-41
lines changed

book/src/framework/components/analyze_ci.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ ctf ci -r "smartcontractkit/chainlink" -w "CI Core" -t jobs -s 5 -e 3
3535
ctf ci -r "smartcontractkit/chainlink-testing-framework" -w "Framework Golden Tests Examples" -t jobs -s 3
3636
```
3737
You can also use `-debug` flag to dump all the workflow runs/jobs to `ctf-ci-debug` folder.
38+
39+
All the results are also saved by default into `ctf-ci-$uuid.json` files so you can use this tool as CI performance linter.

framework/cmd/ci.go

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"os"
89
"path/filepath"
@@ -11,14 +12,12 @@ import (
1112
"sync"
1213
"time"
1314

14-
"github.com/pkg/errors"
15-
"go.uber.org/ratelimit"
16-
"golang.org/x/sync/errgroup"
17-
1815
"github.com/fatih/color"
1916
"github.com/google/go-github/v50/github"
2017
"github.com/google/uuid"
18+
"go.uber.org/ratelimit"
2119
"golang.org/x/oauth2"
20+
"golang.org/x/sync/errgroup"
2221

2322
"github.com/smartcontractkit/chainlink-testing-framework/framework"
2423
)
@@ -40,9 +39,11 @@ var (
4039
SlowTestThreshold = 5 * time.Minute
4140
ExtremelySlowTestThreshold = 10 * time.Minute
4241

43-
DebugDirRoot = "ctf-ci-debug"
44-
DebugSubDirWF = filepath.Join(DebugDirRoot, "workflows")
45-
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"
4647
)
4748

4849
type GitHubActionsClient interface {
@@ -51,38 +52,38 @@ type GitHubActionsClient interface {
5152
}
5253

5354
type AnalysisConfig struct {
54-
Debug bool
55-
Owner string
56-
Repo string
57-
WorkflowName string
58-
TimeDaysBeforeStart int
59-
TimeStart time.Time
60-
TimeDaysBeforeEnd int
61-
TimeEnd time.Time
62-
Typ string
63-
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"`
6465
}
6566

6667
type Stat struct {
67-
Name string
68-
Successes int
69-
Failures int
70-
Cancels int
71-
ReRuns int
72-
P50 time.Duration
73-
P95 time.Duration
74-
P99 time.Duration
75-
TotalDuration time.Duration
76-
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:"-"`
7778
}
7879

7980
type Stats struct {
80-
Mu *sync.Mutex
81-
Runs int
82-
CancelledRuns int
83-
IgnoredRuns int
84-
Jobs map[string]*Stat
85-
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"`
8687
}
8788

8889
func calculatePercentiles(stat *Stat) *Stat {
@@ -104,7 +105,7 @@ func refreshDebugDirs() {
104105
}
105106
}
106107

107-
func writeStruct(enabled bool, dir, name string, data interface{}) error {
108+
func dumpResults(enabled bool, dir, name string, data interface{}) error {
108109
if enabled {
109110
d, err := json.MarshalIndent(data, "", " ")
110111
if err != nil {
@@ -137,6 +138,7 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
137138

138139
eg := &errgroup.Group{}
139140
for _, wr := range runs.WorkflowRuns {
141+
framework.L.Debug().Str("Name", *wr.Name).Msg("Analyzing workflow run")
140142
if !strings.Contains(*wr.Name, cfg.WorkflowName) {
141143
stats.IgnoredRuns++
142144
continue
@@ -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{
@@ -155,11 +157,11 @@ func AnalyzeJobsSteps(ctx context.Context, client GitHubActionsClient, cfg *Anal
155157
return err
156158
}
157159
// analyze jobs
160+
stats.Mu.Lock()
161+
defer stats.Mu.Unlock()
158162
for _, j := range jobs.Jobs {
159-
stats.Mu.Lock()
160-
defer stats.Mu.Unlock()
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

framework/cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func main() {
263263
TimeDaysBeforeStart: c.Int("start"),
264264
TimeDaysBeforeEnd: c.Int("end"),
265265
Typ: typ,
266+
ResultsFile: "ctf-ci.json",
266267
})
267268
return err
268269
},

parrot/.changeset/v0.6.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Statically linked binary

parrot/.goreleaser.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ builds:
3030
- amd64
3131
- arm64
3232
binary: parrot
33-
34-
archives:
35-
- formats: ['binary']
33+
env:
34+
- CGO_ENABLED=0
3635

3736
dockers:
3837
- id: linux-amd64-parrot

0 commit comments

Comments
 (0)