@@ -3,7 +3,7 @@ use crate::comparison::{ComparisonSummary, Direction};
3
3
use crate :: load:: { Config , SiteCtxt , TryCommit } ;
4
4
5
5
use anyhow:: Context as _;
6
- use database:: ArtifactId ;
6
+ use database:: { ArtifactId , QueuedCommit } ;
7
7
use hashbrown:: HashSet ;
8
8
use reqwest:: header:: USER_AGENT ;
9
9
use serde:: { Deserialize , Serialize } ;
@@ -501,6 +501,8 @@ pub struct PostComment {
501
501
pub body : String ,
502
502
}
503
503
504
+ /// Post messages to GitHub for all queued commits that have
505
+ /// not yet been marked as completed.
504
506
pub async fn post_finished ( ctxt : & SiteCtxt ) {
505
507
// If the github token is not configured, do not run this -- we don't want
506
508
// to mark things as complete without posting the comment.
@@ -509,92 +511,128 @@ pub async fn post_finished(ctxt: &SiteCtxt) {
509
511
}
510
512
let conn = ctxt. conn ( ) . await ;
511
513
let index = ctxt. index . load ( ) ;
512
- let mut commits = index
514
+ let mut known_commits = index
513
515
. commits ( )
514
516
. into_iter ( )
515
517
. map ( |c| c. sha . to_string ( ) )
516
518
. collect :: < HashSet < _ > > ( ) ;
517
- let queued = conn. queued_commits ( ) . await ;
519
+ let ( master_commits, queued_pr_commits, in_progress_artifacts) = futures:: join!(
520
+ collector:: master_commits( ) ,
521
+ conn. queued_commits( ) ,
522
+ conn. in_progress_artifacts( )
523
+ ) ;
524
+ let master_commits = if let Ok ( mcs) = master_commits {
525
+ mcs. into_iter ( ) . map ( |c| c. sha ) . collect :: < HashSet < _ > > ( )
526
+ } else {
527
+ // If we can't fetch master commits, return.
528
+ // We'll eventually try again later
529
+ return ;
530
+ } ;
518
531
519
- for aid in conn . in_progress_artifacts ( ) . await {
532
+ for aid in in_progress_artifacts {
520
533
match aid {
521
534
ArtifactId :: Commit ( c) => {
522
- commits . remove ( & c. sha ) ;
535
+ known_commits . remove ( & c. sha ) ;
523
536
}
524
537
ArtifactId :: Tag ( _) => {
525
- // do nothing, for now, though eventually we'll want an artifact
526
- // queue
538
+ // do nothing, for now, though eventually we'll want an artifact queue
527
539
}
528
540
}
529
541
}
530
- for commit in queued {
531
- if !commits . contains ( & commit . sha ) {
532
- continue ;
533
- }
534
-
535
- // This commit has been benchmarked.
542
+ for queued_commit in queued_pr_commits
543
+ . into_iter ( )
544
+ . filter ( |c| known_commits . contains ( & c . sha ) )
545
+ {
546
+ if let Some ( completed ) = conn . mark_complete ( & queued_commit . sha ) . await {
547
+ assert_eq ! ( completed , queued_commit ) ;
536
548
537
- if let Some ( completed) = conn. mark_complete ( & commit. sha ) . await {
538
- assert_eq ! ( completed, commit) ;
549
+ let is_master_commit = master_commits. contains ( & queued_commit. sha ) ;
550
+ post_comparison_comment ( ctxt, queued_commit, is_master_commit) . await ;
551
+ }
552
+ }
553
+ }
539
554
540
- let comparison_url = format ! (
541
- "https://perf.rust-lang.org/compare.html?start={}&end={}" ,
542
- commit. parent_sha, commit. sha
543
- ) ;
544
- let ( summary, direction) = categorize_benchmark ( & commit, ctxt) . await ;
545
- let label = match direction {
546
- Some ( Direction :: Regression | Direction :: Mixed ) => "+perf-regression" ,
547
- Some ( Direction :: Improvement ) | None => "-perf-regression" ,
548
- } ;
549
- let msg = direction
550
- . map ( |d| {
551
- format ! (
552
- "While you can manually mark this PR as fit \
555
+ /// Posts a comment to GitHub summarizing the comparison of the queued commit with its parent
556
+ ///
557
+ /// `is_master_commit` is used to differentiate messages for try runs and post-merge runs.
558
+ async fn post_comparison_comment ( ctxt : & SiteCtxt , commit : QueuedCommit , is_master_commit : bool ) {
559
+ let comparison_url = format ! (
560
+ "https://perf.rust-lang.org/compare.html?start={}&end={}" ,
561
+ commit. parent_sha, commit. sha
562
+ ) ;
563
+ let ( summary, direction) =
564
+ categorize_benchmark ( commit. sha . clone ( ) , commit. parent_sha , ctxt) . await ;
565
+ let label = match direction {
566
+ Some ( Direction :: Regression | Direction :: Mixed ) => "+perf-regression" ,
567
+ Some ( Direction :: Improvement ) | None => "-perf-regression" ,
568
+ } ;
569
+ let rollup_msg = if is_master_commit {
570
+ ""
571
+ } else {
572
+ "Benchmarking this pull request likely means that it is \
573
+ perf-sensitive, so we're automatically marking it as not fit \
574
+ for rolling up. "
575
+ } ;
576
+ let next_steps_msg = direction
577
+ . map ( |d| {
578
+ format ! (
579
+ "{}{}" ,
580
+ if is_master_commit {
581
+ ""
582
+ } else {
583
+ "While you can manually mark this PR as fit \
553
584
for rollup, we strongly recommend not doing so since this PR led to changes in \
554
- compiler perf.{}",
555
- match d {
556
- Direction :: Regression | Direction :: Mixed =>
557
- "\n \n **Next Steps**: If you can justify the \
585
+ compiler perf."
586
+ } ,
587
+ match d {
588
+ Direction :: Regression | Direction :: Mixed =>
589
+ "\n \n **Next Steps**: If you can justify the \
558
590
regressions found in this perf run, please indicate this with \
559
591
`@rustbot label: +perf-regression-triaged` along with \
560
592
sufficient written justification. If you cannot justify the regressions \
561
- please fix the regressions and do another perf run. If the next run shows \
562
- neutral or positive results, the label will be automatically removed.",
563
- Direction :: Improvement => "" ,
564
- }
565
- )
566
- } )
567
- . unwrap_or ( String :: new ( ) ) ;
568
-
569
- post_comment (
570
- & ctxt. config ,
571
- commit. pr ,
572
- format ! (
573
- "Finished benchmarking try commit ({}): [comparison url]({}).
574
-
575
- **Summary**: {}
576
-
577
- Benchmarking this pull request likely means that it is \
578
- perf-sensitive, so we're automatically marking it as not fit \
579
- for rolling up. {}
580
-
581
- @bors rollup=never
582
- @rustbot label: +S-waiting-on-review -S-waiting-on-perf {}" ,
583
- commit. sha, comparison_url, summary, msg, label
584
- ) ,
593
+ please fix the regressions (either in this PR if it's not yet merged or \
594
+ in another PR), and then add the `perf-regression-triaged` label to this PR.",
595
+ Direction :: Improvement => "" ,
596
+ }
585
597
)
586
- . await ;
587
- }
588
- }
598
+ } )
599
+ . unwrap_or ( String :: new ( ) ) ;
600
+ let bors_msg = if is_master_commit {
601
+ ""
602
+ } else {
603
+ "@bors rollup=never\n "
604
+ } ;
605
+ post_comment (
606
+ & ctxt. config ,
607
+ commit. pr ,
608
+ format ! (
609
+ "Finished benchmarking commit ({sha}): [comparison url]({url}).
610
+
611
+ **Summary**: {summary}
612
+
613
+ {rollup}{next_steps}
614
+ {bors}
615
+ @rustbot label: +S-waiting-on-review -S-waiting-on-perf {label}" ,
616
+ sha = commit. sha,
617
+ url = comparison_url,
618
+ summary = summary,
619
+ rollup = rollup_msg,
620
+ next_steps = next_steps_msg,
621
+ bors = bors_msg,
622
+ label = label
623
+ ) ,
624
+ )
625
+ . await ;
589
626
}
590
627
591
628
async fn categorize_benchmark (
592
- commit : & database:: QueuedCommit ,
629
+ commit_sha : String ,
630
+ parent_sha : String ,
593
631
ctxt : & SiteCtxt ,
594
632
) -> ( String , Option < Direction > ) {
595
633
let comparison = match crate :: comparison:: compare (
596
- collector:: Bound :: Commit ( commit . parent_sha . clone ( ) ) ,
597
- collector:: Bound :: Commit ( commit . sha . clone ( ) ) ,
634
+ collector:: Bound :: Commit ( parent_sha) ,
635
+ collector:: Bound :: Commit ( commit_sha ) ,
598
636
"instructions:u" . to_owned ( ) ,
599
637
ctxt,
600
638
)
0 commit comments