@@ -357,11 +357,24 @@ func main() {
357
357
var ignoreAllNewWork bool
358
358
359
359
// addWorkTestHook is optionally set by tests.
360
- var addWorkTestHook func (work buildgo.BuilderRev )
360
+ var addWorkTestHook func (buildgo.BuilderRev , * commitDetail )
361
+
362
+ type commitDetail struct {
363
+ CommitTime string // in time.RFC3339 format
364
+ Branch string
365
+ }
361
366
362
367
func addWork (work buildgo.BuilderRev ) {
368
+ addWorkDetail (work , nil )
369
+ }
370
+
371
+ // addWorkDetail adds some work to (maybe) do, if it's not already
372
+ // enqueued and the builders are configured to run the given repo. The
373
+ // detail argument is optional and used for scheduling. It's currently
374
+ // only used for post-submit builds.
375
+ func addWorkDetail (work buildgo.BuilderRev , detail * commitDetail ) {
363
376
if f := addWorkTestHook ; f != nil {
364
- f (work )
377
+ f (work , detail )
365
378
return
366
379
}
367
380
if ignoreAllNewWork || isBuilding (work ) {
@@ -375,12 +388,12 @@ func addWork(work buildgo.BuilderRev) {
375
388
}
376
389
return
377
390
}
378
- st , err := newBuild (work )
391
+ st , err := newBuild (work , detail )
379
392
if err != nil {
380
393
log .Printf ("Bad build work params %v: %v" , work , err )
381
- } else {
382
- st .start ()
394
+ return
383
395
}
396
+ st .start ()
384
397
}
385
398
386
399
// httpToHTTPSRedirector redirects all requests from http to https.
@@ -872,12 +885,28 @@ func findWork() error {
872
885
873
886
var goRevisions []string // revisions of repo "go", branch "master" revisions
874
887
seenSubrepo := make (map [string ]bool )
888
+ commitTime := make (map [string ]string ) // git rev => "2019-11-20T22:54:54Z" (time.RFC3339 from build.golang.org's JSON)
889
+ commitBranch := make (map [string ]string ) // git rev => "master"
890
+
891
+ add := func (br buildgo.BuilderRev ) {
892
+ rev := br .SubRev
893
+ if br .SubRev == "" {
894
+ rev = br .Rev
895
+ }
896
+ addWorkDetail (br , & commitDetail {
897
+ CommitTime : commitTime [rev ],
898
+ Branch : commitBranch [rev ],
899
+ })
900
+ }
901
+
875
902
for _ , br := range bs .Revisions {
876
903
if br .Repo == "grpc-review" {
877
904
// Skip the grpc repo. It's only for reviews
878
905
// for now (using LetsUseGerrit).
879
906
continue
880
907
}
908
+ commitTime [br .Revision ] = br .Date
909
+ commitBranch [br .Revision ] = br .Branch
881
910
awaitSnapshot := false
882
911
if br .Repo == "go" {
883
912
if br .Branch == "master" {
@@ -938,7 +967,7 @@ func findWork() error {
938
967
}
939
968
}
940
969
941
- addWork (rev )
970
+ add (rev )
942
971
}
943
972
}
944
973
@@ -950,7 +979,7 @@ func findWork() error {
950
979
continue
951
980
}
952
981
for _ , rev := range goRevisions {
953
- addWork (buildgo.BuilderRev {Name : b , Rev : rev })
982
+ add (buildgo.BuilderRev {Name : b , Rev : rev })
954
983
}
955
984
}
956
985
return nil
@@ -1160,7 +1189,7 @@ func newTrySet(work *apipb.GerritTryWorkItem) *trySet {
1160
1189
continue
1161
1190
}
1162
1191
brev := tryKeyToBuilderRev (bconf .Name , key , goRev )
1163
- bs , err := newBuild (brev )
1192
+ bs , err := newBuild (brev , noCommitDetail )
1164
1193
if err != nil {
1165
1194
log .Printf ("can't create build for %q: %v" , brev , err )
1166
1195
continue
@@ -1190,7 +1219,7 @@ func newTrySet(work *apipb.GerritTryWorkItem) *trySet {
1190
1219
continue
1191
1220
}
1192
1221
brev := tryKeyToBuilderRev (linuxBuilder .Name , key , goRev )
1193
- bs , err := newBuild (brev )
1222
+ bs , err := newBuild (brev , noCommitDetail )
1194
1223
if err != nil {
1195
1224
log .Printf ("can't create build for %q: %v" , brev , err )
1196
1225
continue
@@ -1221,7 +1250,7 @@ func newTrySet(work *apipb.GerritTryWorkItem) *trySet {
1221
1250
SubName : project ,
1222
1251
SubRev : rev ,
1223
1252
}
1224
- bs , err := newBuild (brev )
1253
+ bs , err := newBuild (brev , noCommitDetail )
1225
1254
if err != nil {
1226
1255
log .Printf ("can't create x/%s trybot build for go/master commit %s: %v" , project , rev , err )
1227
1256
return nil
@@ -1338,7 +1367,7 @@ func (ts *trySet) awaitTryBuild(idx int, bs *buildStatus, brev buildgo.BuilderRe
1338
1367
if ! ts .wanted () {
1339
1368
return
1340
1369
}
1341
- bs , _ = newBuild (brev )
1370
+ bs , _ = newBuild (brev , noCommitDetail )
1342
1371
bs .trySet = ts
1343
1372
bs .goBranch = old .goBranch
1344
1373
go bs .start ()
@@ -1588,7 +1617,12 @@ func poolForConf(conf *dashboard.HostConfig) BuildletPool {
1588
1617
}
1589
1618
}
1590
1619
1591
- func newBuild (rev buildgo.BuilderRev ) (* buildStatus , error ) {
1620
+ // noCommitDetail is just a nice name for nil at call sites.
1621
+ var noCommitDetail * commitDetail = nil
1622
+
1623
+ // newBuild constructs a new *buildStatus from rev and an optional detail.
1624
+ // If detail is nil, the scheduler just has less information to work with.
1625
+ func newBuild (rev buildgo.BuilderRev , detail * commitDetail ) (* buildStatus , error ) {
1592
1626
// Note: can't acquire statusMu in newBuild, as this is called
1593
1627
// from findTryWork -> newTrySet, which holds statusMu.
1594
1628
@@ -1600,6 +1634,19 @@ func newBuild(rev buildgo.BuilderRev) (*buildStatus, error) {
1600
1634
return nil , fmt .Errorf ("required field Rev is empty; got %+v" , rev )
1601
1635
}
1602
1636
1637
+ var branch string
1638
+ var commitTime time.Time
1639
+ if detail != nil {
1640
+ branch = detail .Branch
1641
+ if detail .CommitTime != "" {
1642
+ var err error
1643
+ commitTime , err = time .Parse (time .RFC3339 , detail .CommitTime )
1644
+ if err != nil {
1645
+ return nil , fmt .Errorf ("invalid commit time %q, for %+v: %err" , detail .CommitTime , rev , err )
1646
+ }
1647
+ }
1648
+ }
1649
+
1603
1650
ctx , cancel := context .WithCancel (context .Background ())
1604
1651
return & buildStatus {
1605
1652
buildID : "B" + randHex (9 ),
@@ -1608,6 +1655,8 @@ func newBuild(rev buildgo.BuilderRev) (*buildStatus, error) {
1608
1655
startTime : time .Now (),
1609
1656
ctx : ctx ,
1610
1657
cancel : cancel ,
1658
+ commitTime : commitTime ,
1659
+ branch : branch ,
1611
1660
}, nil
1612
1661
}
1613
1662
@@ -1717,6 +1766,8 @@ func (st *buildStatus) onceInitHelpersFunc() {
1717
1766
BuilderRev : st .BuilderRev ,
1718
1767
HostType : st .conf .HostType ,
1719
1768
IsTry : st .isTry (),
1769
+ CommitTime : st .commitTime ,
1770
+ Branch : st .branch ,
1720
1771
}
1721
1772
st .helpers = getBuildlets (st .ctx , st .conf .NumTestHelpers (st .isTry ()), schedTmpl , st )
1722
1773
}
@@ -1799,6 +1850,8 @@ func (st *buildStatus) getBuildlet() (*buildlet.Client, error) {
1799
1850
HostType : st .conf .HostType ,
1800
1851
IsTry : st .trySet != nil ,
1801
1852
BuilderRev : st .BuilderRev ,
1853
+ CommitTime : st .commitTime ,
1854
+ Branch : st .branch ,
1802
1855
}
1803
1856
st .mu .Lock ()
1804
1857
st .schedItem = schedItem
@@ -2110,6 +2163,8 @@ func (st *buildStatus) crossCompileMakeAndSnapshot(config *dashboard.CrossCompil
2110
2163
HostType : config .CompileHostType ,
2111
2164
IsTry : st .trySet != nil ,
2112
2165
BuilderRev : st .BuilderRev ,
2166
+ CommitTime : st .commitTime ,
2167
+ Branch : st .branch ,
2113
2168
})
2114
2169
sp .Done (err )
2115
2170
if err != nil {
@@ -3370,11 +3425,13 @@ type eventAndTime struct {
3370
3425
type buildStatus struct {
3371
3426
// Immutable:
3372
3427
buildgo.BuilderRev
3373
- buildID string // "B" + 9 random hex
3374
- goBranch string // non-empty for subrepo trybots if not go master branch
3375
- conf * dashboard.BuildConfig
3376
- startTime time.Time // actually time of newBuild (~same thing); TODO(bradfitz): rename this createTime
3377
- trySet * trySet // or nil
3428
+ buildID string // "B" + 9 random hex
3429
+ goBranch string // non-empty for subrepo trybots if not go master branch
3430
+ conf * dashboard.BuildConfig
3431
+ startTime time.Time // actually time of newBuild (~same thing)
3432
+ trySet * trySet // or nil
3433
+ commitTime time.Time // non-zero for post-submit builders
3434
+ branch string // non-empty for post-submit work
3378
3435
3379
3436
onceInitHelpers sync.Once // guards call of onceInitHelpersFunc
3380
3437
helpers <- chan * buildlet.Client
0 commit comments