Skip to content

Commit dc54d45

Browse files
committed
cmd/coordinator: support specifying a builder for x-repo slowbots
Add support for the syntax `x/repo@builder`, as suggested in #39201. For golang/go#39201 Change-Id: Iac49169f12b90cbdfea626fcb4f5408358639760 Reviewed-on: https://go-review.googlesource.com/c/build/+/342712 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 9683a14 commit dc54d45

File tree

2 files changed

+59
-25
lines changed

2 files changed

+59
-25
lines changed

cmd/coordinator/coordinator.go

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,14 +1376,26 @@ func newTrySet(work *apipb.GerritTryWorkItem) *trySet {
13761376
// For the Go project on the "master" branch,
13771377
// use the TRY= syntax to test against x repos.
13781378
if branch := key.Branch; key.Project == "go" && branch == "master" {
1379-
// linuxBuilder is the standard builder as it is the fastest and least expensive.
1380-
linuxBuilder := dashboard.Builders["linux-amd64"]
1379+
// customBuilder optionally specifies the builder to use for the build
1380+
// (empty string means to use the default builder).
1381+
addXrepo := func(project, customBuilder string) *buildStatus {
1382+
// linux-amd64 is the default builder as it is the fastest and least
1383+
// expensive.
1384+
builder := dashboard.Builders["linux-amd64"]
1385+
if customBuilder != "" {
1386+
b, ok := dashboard.Builders[customBuilder]
1387+
if !ok {
1388+
log.Printf("can't resolve requested builder %q", customBuilder)
1389+
return nil
1390+
}
1391+
builder = b
1392+
}
13811393

1382-
addXrepo := func(project string) *buildStatus {
13831394
if testingKnobSkipBuilds {
13841395
return nil
13851396
}
1386-
if !linuxBuilder.BuildsRepoTryBot(project, branch, branch) {
1397+
if !builder.BuildsRepoTryBot(project, branch, branch) {
1398+
log.Printf("builder %q isn't configured to build %q@%q as a trybot", builder.Name, project, branch)
13871399
return nil
13881400
}
13891401
rev, err := getRepoHead(project)
@@ -1392,7 +1404,7 @@ func newTrySet(work *apipb.GerritTryWorkItem) *trySet {
13921404
return nil
13931405
}
13941406
brev := buildgo.BuilderRev{
1395-
Name: linuxBuilder.Name,
1407+
Name: builder.Name,
13961408
Rev: work.Commit,
13971409
SubName: project,
13981410
SubRev: rev,
@@ -1407,17 +1419,17 @@ func newTrySet(work *apipb.GerritTryWorkItem) *trySet {
14071419
}
14081420

14091421
// First, add the opt-in x repos.
1410-
xrepos := xReposFromComments(work)
1411-
for project := range xrepos {
1412-
if bs := addXrepo(project); bs != nil {
1422+
repoBuilders := xReposFromComments(work)
1423+
for rb := range repoBuilders {
1424+
if bs := addXrepo(rb.Project, rb.Builder); bs != nil {
14131425
ts.xrepos = append(ts.xrepos, bs)
14141426
}
14151427
}
14161428

1417-
// Always include x/tools. See golang.org/issue/34348.
1429+
// Always include the default x/tools builder. See golang.org/issue/34348.
14181430
// Do not add it to the trySet's list of opt-in x repos, however.
1419-
if !xrepos["tools"] {
1420-
addXrepo("tools")
1431+
if haveDefaultToolsBuild := repoBuilders[xRepoAndBuilder{Project: "tools"}]; !haveDefaultToolsBuild {
1432+
addXrepo("tools", "")
14211433
}
14221434
}
14231435

@@ -4193,18 +4205,39 @@ func slowBotsFromComments(work *apipb.GerritTryWorkItem) (builders []*dashboard.
41934205
return builders
41944206
}
41954207

4196-
// xReposFromComments looks at the TRY= comments from Gerrit (in
4197-
// work) and returns any additional subrepos that should be tested.
4198-
// The TRY= comments are expected to be of the format TRY=x/foo,
4199-
// where foo is the name of the subrepo.
4200-
func xReposFromComments(work *apipb.GerritTryWorkItem) map[string]bool {
4201-
xrepos := map[string]bool{}
4208+
type xRepoAndBuilder struct {
4209+
Project string // "net", "tools", etc.
4210+
Builder string // Builder to use. Empty string means default builder.
4211+
}
4212+
4213+
func (rb xRepoAndBuilder) String() string {
4214+
if rb.Builder == "" {
4215+
return rb.Project
4216+
}
4217+
return rb.Project + "@" + rb.Builder
4218+
}
4219+
4220+
// xReposFromComments looks at the TRY= comments from Gerrit (in work) and
4221+
// returns any additional subrepos that should be tested. The TRY= comments
4222+
// are expected to be of the format TRY=x/foo or TRY=x/foo@builder where foo is
4223+
// the name of the subrepo and builder is a builder name. If no builder is
4224+
// provided, a default builder is used.
4225+
func xReposFromComments(work *apipb.GerritTryWorkItem) map[xRepoAndBuilder]bool {
4226+
xrepos := make(map[xRepoAndBuilder]bool)
42024227
for _, term := range latestTryTerms(work) {
42034228
if len(term) < len("x/_") || term[:2] != "x/" {
42044229
continue
42054230
}
4206-
xrepo := term[2:]
4207-
xrepos[xrepo] = true
4231+
parts := strings.SplitN(term, "@", 2)
4232+
xrepo := parts[0][2:]
4233+
builder := "" // By convention, this means the default builder.
4234+
if len(parts) > 1 {
4235+
builder = parts[1]
4236+
}
4237+
xrepos[xRepoAndBuilder{
4238+
Project: xrepo,
4239+
Builder: builder,
4240+
}] = true
42084241
}
42094242
return xrepos
42104243
}
@@ -4219,7 +4252,7 @@ func latestTryTerms(work *apipb.GerritTryWorkItem) []string {
42194252
return nil
42204253
}
42214254
return strings.FieldsFunc(tryMsg, func(c rune) bool {
4222-
return !unicode.IsLetter(c) && !unicode.IsNumber(c) && c != '-' && c != '_' && c != '/'
4255+
return !unicode.IsLetter(c) && !unicode.IsNumber(c) && c != '-' && c != '_' && c != '/' && c != '@'
42234256
})
42244257
}
42254258

cmd/coordinator/coordinator_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,16 @@ func TestSubreposFromComments(t *testing.T) {
365365
TryMessage: []*apipb.TryVoteMessage{
366366
{
367367
Version: 2,
368-
Message: "x/build, x/sync x/tools, x/sync",
368+
Message: "x/build, x/sync x/tools, x/sync, x/tools@freebsd-amd64-race",
369369
},
370370
},
371371
}
372372
got := xReposFromComments(work)
373-
want := map[string]bool{
374-
"build": true,
375-
"sync": true,
376-
"tools": true,
373+
want := map[xRepoAndBuilder]bool{
374+
{"build", ""}: true,
375+
{"sync", ""}: true,
376+
{"tools", ""}: true,
377+
{"tools", "freebsd-amd64-race"}: true,
377378
}
378379
if !reflect.DeepEqual(got, want) {
379380
t.Errorf("mismatch:\n got: %v\nwant: %v\n", got, want)

0 commit comments

Comments
 (0)