Skip to content

Commit

Permalink
ci-matrix: improve description
Browse files Browse the repository at this point in the history
and format elapsed time in the output
and remove overly verbose debug log
  • Loading branch information
dnephin committed Sep 4, 2022
1 parent 49930c4 commit 59954dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions cmd/tool/matrix/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ func packageTiming(files []*os.File) (map[string][]time.Duration, error) {
}

for _, pkg := range exec.Packages() {
log.Debugf("package elapsed time %v %v", pkg, exec.Package(pkg).Elapsed())
timing[pkg] = append(timing[pkg], exec.Package(pkg).Elapsed())
}
}
Expand Down Expand Up @@ -254,29 +253,27 @@ type matrix struct {
}

type Partition struct {
ID int `json:"id"`
EstimatedRuntime time.Duration `json:"estimatedRuntime"`
Packages []string `json:"packages"`
Description string `json:"description"`
ID int `json:"id"`
EstimatedRuntime string `json:"estimatedRuntime"`
Packages []string `json:"packages"`
Description string `json:"description"`
}

func writeMatrix(out io.Writer, buckets []bucket) error {
m := matrix{Include: make([]Partition, len(buckets))}
for i, bucket := range buckets {
p := Partition{
ID: i,
EstimatedRuntime: bucket.Total,
EstimatedRuntime: bucket.Total.String(),
Packages: bucket.Packages,
}
if len(p.Packages) > 0 {
var extra string
if len(p.Packages) > 1 {
extra = fmt.Sprintf(" and %d others", len(p.Packages)-1)
}
p.Description = fmt.Sprintf("package %v%v (%v)",
testjson.RelativePackagePath(p.Packages[0]),
extra,
p.EstimatedRuntime)
p.Description = fmt.Sprintf("partition %d - package %v%v",
p.ID, testjson.RelativePackagePath(p.Packages[0]), extra)
}

m.Include[i] = p
Expand Down
2 changes: 1 addition & 1 deletion cmd/tool/matrix/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,5 @@ func TestRun(t *testing.T) {

// expectedMatrix can be automatically updated by running tests with -update
// nolint:lll
var expectedMatrix = `{"include":[{"id":0,"estimatedRuntime":6000000000,"packages":["pkg2"],"description":"package pkg2 (6s)"},{"id":1,"estimatedRuntime":4000000000,"packages":["pkg1"],"description":"package pkg1 (4s)"},{"id":2,"estimatedRuntime":2000000000,"packages":["pkg0","other"],"description":"package pkg0 and 1 others (2s)"}]}
var expectedMatrix = `{"include":[{"id":0,"estimatedRuntime":"6s","packages":["pkg2"],"description":"partition 0 - package pkg2"},{"id":1,"estimatedRuntime":"4s","packages":["pkg1"],"description":"partition 1 - package pkg1"},{"id":2,"estimatedRuntime":"2s","packages":["pkg0","other"],"description":"partition 2 - package pkg0 and 1 others"}]}
`

0 comments on commit 59954dd

Please sign in to comment.