From 334285616146378efd5f0acbac2c18046fd0d524 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Fri, 24 Jan 2014 09:13:34 +1100 Subject: [PATCH] go.tools/dashboard/app: sort builder columns in a more useful manner Supported operating systems first, then race builders, then the rest. R=r, bradfitz CC=golang-codereviews https://golang.org/cl/56190043 --- dashboard/app/build/test.go | 9 ++++ dashboard/app/build/ui.go | 85 ++++++++++++++++++++++++++++--------- dashboard/app/build/ui.html | 4 +- 3 files changed, 77 insertions(+), 21 deletions(-) diff --git a/dashboard/app/build/test.go b/dashboard/app/build/test.go index bfaf1c75..3c9576e7 100644 --- a/dashboard/app/build/test.go +++ b/dashboard/app/build/test.go @@ -79,6 +79,15 @@ var testRequests = []struct { {"/result", nil, &Result{Builder: "linux-386", Hash: "0002", OK: true}, nil}, {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-386"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0003"}}}, + // Other builders, to test the UI. + {"/result", nil, &Result{Builder: "linux-amd64", Hash: "0001", OK: true}, nil}, + {"/result", nil, &Result{Builder: "linux-amd64-race", Hash: "0001", OK: true}, nil}, + {"/result", nil, &Result{Builder: "netbsd-386", Hash: "0001", OK: true}, nil}, + {"/result", nil, &Result{Builder: "plan9-386", Hash: "0001", OK: true}, nil}, + {"/result", nil, &Result{Builder: "windows-386", Hash: "0001", OK: true}, nil}, + {"/result", nil, &Result{Builder: "windows-amd64", Hash: "0001", OK: true}, nil}, + {"/result", nil, &Result{Builder: "windows-amd64-race", Hash: "0001", OK: true}, nil}, + // multiple builders {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-amd64"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0003"}}}, {"/result", nil, &Result{Builder: "linux-amd64", Hash: "0003", OK: true}, nil}, diff --git a/dashboard/app/build/ui.go b/dashboard/app/build/ui.go index 65762e60..108915e0 100644 --- a/dashboard/app/build/ui.go +++ b/dashboard/app/build/ui.go @@ -119,7 +119,9 @@ func commitBuilders(commits []*Commit, goHash string) []string { builders[r.Builder] = true } } - return keys(builders) + k := keys(builders) + sort.Sort(builderOrder(k)) + return k } func keys(m map[string]bool) (s []string) { @@ -130,6 +132,45 @@ func keys(m map[string]bool) (s []string) { return } +// builderOrder implements sort.Interface, sorting builder names +// ("darwin-amd64", etc) first by builderPriority and then alphabetically. +type builderOrder []string + +func (s builderOrder) Len() int { return len(s) } +func (s builderOrder) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s builderOrder) Less(i, j int) bool { + pi, pj := builderPriority(s[i]), builderPriority(s[j]) + if pi == pj { + return s[i] < s[j] + } + return pi < pj +} + +func builderPriority(builder string) int { + // Group race builders together. + if isRace(builder) { + return 1 + } + // Put supported OSes first. + if supportedOS[builderOS(builder)] { + return 0 + } + // Everyone else. + return 2 +} + +func isRace(s string) bool { + return strings.Contains(s, "-race-") || strings.HasSuffix(s, "-race") +} + +// Operating systems that should appear first on the dashboard. +var supportedOS = map[string]bool{ + "darwin": true, + "freebsd": true, + "linux": true, + "windows": true, +} + // TagState represents the state of all Packages at a Tag. type TagState struct { Tag *Commit @@ -181,18 +222,15 @@ var uiTemplate = template.Must( ) var tmplFuncs = template.FuncMap{ - "builderOS": builderOS, - "builderArch": builderArch, - "builderArchShort": builderArchShort, - "builderArchChar": builderArchChar, - "builderTitle": builderTitle, - "builderSpans": builderSpans, - "buildDashboards": buildDashboards, - "repoURL": repoURL, - "shortDesc": shortDesc, - "shortHash": shortHash, - "shortUser": shortUser, - "tail": tail, + "builderSubheading": builderSubheading, + "builderTitle": builderTitle, + "builderSpans": builderSpans, + "buildDashboards": buildDashboards, + "repoURL": repoURL, + "shortDesc": shortDesc, + "shortHash": shortHash, + "shortUser": shortUser, + "tail": tail, } func splitDash(s string) (string, string) { @@ -209,6 +247,14 @@ func builderOS(s string) string { return os } +// builderOSOrRace returns the builder OS or, if it is a race builder, "race". +func builderOSOrRace(s string) string { + if isRace(s) { + return "race" + } + return builderOS(s) +} + // builderArch returns the arch tag for a builder string func builderArch(s string) string { _, arch := splitDash(s) @@ -216,10 +262,11 @@ func builderArch(s string) string { return arch } -// builderArchShort returns a short arch tag for a builder string -func builderArchShort(s string) string { - if strings.Contains(s+"-", "-race-") { - return "race" +// builderSubheading returns a short arch tag for a builder string +// or, if it is a race builder, the builder OS. +func builderSubheading(s string) string { + if isRace(s) { + return builderOS(s) } arch := builderArch(s) switch arch { @@ -255,8 +302,8 @@ func builderSpans(s []string) []builderSpan { var sp []builderSpan for len(s) > 0 { i := 1 - os := builderOS(s[0]) - for i < len(s) && builderOS(s[i]) == os { + os := builderOSOrRace(s[0]) + for i < len(s) && builderOSOrRace(s[i]) == os { i++ } sp = append(sp, builderSpan{i, os}) diff --git a/dashboard/app/build/ui.html b/dashboard/app/build/ui.html index f9476398..1c787c89 100644 --- a/dashboard/app/build/ui.html +++ b/dashboard/app/build/ui.html @@ -102,7 +102,7 @@   {{range $.Builders}} - {{builderArchShort .}} + {{builderSubheading .}} {{end}} {{range $c := $.Commits}} @@ -174,7 +174,7 @@ {{range $.Builders}} - {{builderArchShort .}} + {{builderSubheading .}} {{end}}