@@ -10,17 +10,58 @@ type BoxedError = Box<dyn std::error::Error + Send + Sync>;
10
10
11
11
pub use comparison_summary:: post_finished;
12
12
13
+ /// Enqueues try build artifacts and posts a message about them on the original rollup PR
14
+ pub async fn unroll_rollup (
15
+ ci_client : client:: Client ,
16
+ main_repo_client : client:: Client ,
17
+ rollup_merges : impl Iterator < Item = & Commit > ,
18
+ previous_master : & str ,
19
+ rollup_pr_number : u32 ,
20
+ ) -> Result < ( ) , String > {
21
+ let mapping = enqueue_unrolled_try_builds ( ci_client, rollup_merges, previous_master)
22
+ . await ?
23
+ . into_iter ( )
24
+ . fold ( String :: new ( ) , |mut string, c| {
25
+ use std:: fmt:: Write ;
26
+ write ! (
27
+ & mut string,
28
+ "|#{pr}|[{commit}](https://github.com/rust-lang-ci/rust/commit/{commit})|\n " ,
29
+ pr = c. original_pr_number,
30
+ commit = c. sha
31
+ )
32
+ . unwrap ( ) ;
33
+ string
34
+ } ) ;
35
+ let msg =
36
+ format ! ( "📌 Perf builds for each rolled up PR:\n \n \
37
+ |PR# | Perf Build Sha|\n |----|-----|\n \
38
+ {mapping}\n In the case of a perf regression, \
39
+ run the following command for each PR you suspect might be the cause: `@rust-timer build $SHA`") ;
40
+ main_repo_client. post_comment ( rollup_pr_number, msg) . await ;
41
+ Ok ( ( ) )
42
+ }
43
+
13
44
/// Enqueues try builds on the try-perf branch for every rollup merge in `rollup_merges`.
14
45
/// Returns a mapping between the rollup merge commit and the try build sha.
15
- ///
16
- /// `rollup_merges` must only include actual rollup merge commits.
17
- pub async fn enqueue_unrolled_try_builds < ' a > (
46
+ async fn enqueue_unrolled_try_builds < ' a > (
18
47
client : client:: Client ,
19
48
rollup_merges : impl Iterator < Item = & ' a Commit > ,
20
49
previous_master : & str ,
21
- ) -> Result < Vec < ( & ' a Commit , String ) > , String > {
50
+ ) -> Result < Vec < UnrolledCommit < ' a > > , String > {
22
51
let mut mapping = Vec :: new ( ) ;
23
52
for rollup_merge in rollup_merges {
53
+ // Grab the number of the rolled up PR from its commit message
54
+ let original_pr_number = ROLLEDUP_PR_NUMBER
55
+ . captures ( & rollup_merge. message )
56
+ . and_then ( |c| c. get ( 1 ) )
57
+ . map ( |m| m. as_str ( ) )
58
+ . ok_or_else ( || {
59
+ format ! (
60
+ "Could not get PR number from message: '{}'" ,
61
+ rollup_merge. message
62
+ )
63
+ } ) ?;
64
+
24
65
// Fetch the rollup merge commit which should have two parents.
25
66
// The first parent is in the chain of rollup merge commits all the way back to `previous_master`.
26
67
// The second parent is the head of the PR that was rolled up. We want the second parent.
@@ -45,7 +86,11 @@ pub async fn enqueue_unrolled_try_builds<'a>(
45
86
46
87
// Merge in the rolled up PR's head commit into the previous master
47
88
let sha = client
48
- . merge_branch ( "perf-tmp" , rolled_up_head, "merge" )
89
+ . merge_branch (
90
+ "perf-tmp" ,
91
+ rolled_up_head,
92
+ & format ! ( "Unrolled build for #{}" , original_pr_number) ,
93
+ )
49
94
. await
50
95
. map_err ( |e| format ! ( "Error merging commit into perf-tmp: {e:?}" ) ) ?;
51
96
@@ -55,17 +100,33 @@ pub async fn enqueue_unrolled_try_builds<'a>(
55
100
. await
56
101
. map_err ( |e| format ! ( "Error updating the try-perf branch: {e:?}" ) ) ?;
57
102
58
- mapping. push ( ( rollup_merge, sha) ) ;
103
+ mapping. push ( UnrolledCommit {
104
+ original_pr_number,
105
+ rollup_merge,
106
+ sha,
107
+ } ) ;
59
108
// Wait to ensure there's enough time for GitHub to checkout these changes before they are overwritten
60
109
tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( 15 ) ) . await
61
110
}
62
111
63
112
Ok ( mapping)
64
113
}
65
114
115
+ /// A commit representing a rolled up PR as if it had been merged into master directly
116
+ pub struct UnrolledCommit < ' a > {
117
+ /// The PR number that was rolled up
118
+ pub original_pr_number : & ' a str ,
119
+ /// The original rollup merge commit
120
+ pub rollup_merge : & ' a Commit ,
121
+ /// The sha of the new unrolled merge commit
122
+ pub sha : String ,
123
+ }
124
+
66
125
lazy_static:: lazy_static! {
67
126
static ref ROLLUP_PR_NUMBER : regex:: Regex =
68
127
regex:: Regex :: new( r#"^Auto merge of #(\d+)"# ) . unwrap( ) ;
128
+ static ref ROLLEDUP_PR_NUMBER : regex:: Regex =
129
+ regex:: Regex :: new( r#"^Rollup merge of #(\d+)"# ) . unwrap( ) ;
69
130
}
70
131
71
132
// Gets the pr number for the associated rollup PR message. Returns None if this is not a rollup PR
@@ -101,43 +162,49 @@ pub async fn rollup_pr_number(
101
162
. then ( || issue. number ) )
102
163
}
103
164
104
- pub async fn enqueue_sha (
165
+ pub async fn enqueue_shas (
105
166
ctxt : & SiteCtxt ,
106
167
main_client : & client:: Client ,
107
168
ci_client : & client:: Client ,
108
169
pr_number : u32 ,
109
- commit : String ,
170
+ commits : impl Iterator < Item = & str > ,
110
171
) -> Result < ( ) , String > {
111
- let commit_response = ci_client
112
- . get_commit ( & commit)
113
- . await
114
- . map_err ( |e| e. to_string ( ) ) ?;
115
- if commit_response. parents . len ( ) != 2 {
116
- log:: error!(
117
- "Bors try commit {} unexpectedly has {} parents." ,
118
- commit_response. sha,
119
- commit_response. parents. len( )
120
- ) ;
121
- return Ok ( ( ) ) ;
122
- }
123
- let try_commit = TryCommit {
124
- sha : commit_response. sha . clone ( ) ,
125
- parent_sha : commit_response. parents [ 0 ] . sha . clone ( ) ,
126
- } ;
127
- let queued = {
128
- let conn = ctxt. conn ( ) . await ;
129
- conn. pr_attach_commit ( pr_number, & try_commit. sha , & try_commit. parent_sha )
172
+ let mut msg = String :: new ( ) ;
173
+ for commit in commits {
174
+ let mut commit_response = ci_client
175
+ . get_commit ( & commit)
130
176
. await
131
- } ;
132
- if queued {
133
- let msg = format ! (
134
- "Queued {} with parent {}, future [comparison URL]({})." ,
135
- try_commit. sha,
136
- try_commit. parent_sha,
137
- try_commit. comparison_url( ) ,
138
- ) ;
139
- main_client. post_comment ( pr_number, msg) . await ;
177
+ . map_err ( |e| e. to_string ( ) ) ?;
178
+ if commit_response. parents . len ( ) != 2 {
179
+ log:: error!(
180
+ "Bors try commit {} unexpectedly has {} parents." ,
181
+ commit_response. sha,
182
+ commit_response. parents. len( )
183
+ ) ;
184
+ return Ok ( ( ) ) ;
185
+ }
186
+ let try_commit = TryCommit {
187
+ sha : commit_response. sha ,
188
+ parent_sha : commit_response. parents . remove ( 0 ) . sha ,
189
+ } ;
190
+ let queued = {
191
+ let conn = ctxt. conn ( ) . await ;
192
+ conn. pr_attach_commit ( pr_number, & try_commit. sha , & try_commit. parent_sha )
193
+ . await
194
+ } ;
195
+ if queued {
196
+ if !msg. is_empty ( ) {
197
+ msg. push ( '\n' ) ;
198
+ }
199
+ msg. push_str ( & format ! (
200
+ "Queued {} with parent {}, future [comparison URL]({})." ,
201
+ try_commit. sha,
202
+ try_commit. parent_sha,
203
+ try_commit. comparison_url( ) ,
204
+ ) ) ;
205
+ }
140
206
}
207
+ main_client. post_comment ( pr_number, msg) . await ;
141
208
Ok ( ( ) )
142
209
}
143
210
0 commit comments