31
31
REDIS_SOCKET_TIMEOUT ,
32
32
REDIS_BINS_EXPIRE_SECS ,
33
33
)
34
+ from redis_benchmarks_specification .__common__ .github import (
35
+ check_github_available_and_actionable ,
36
+ generate_build_finished_pr_comment ,
37
+ update_comment_if_needed ,
38
+ create_new_pr_comment ,
39
+ )
34
40
from redis_benchmarks_specification .__common__ .package import (
35
41
populate_with_poetry_data ,
36
42
get_version_string ,
37
43
)
38
44
45
+ PERFORMANCE_GH_TOKEN = os .getenv ("PERFORMANCE_GH_TOKEN" , None )
46
+
39
47
40
48
class ZipFileWithPermissions (ZipFile ):
41
49
def _extract_member (self , member , targetpath , pwd ):
@@ -80,6 +88,8 @@ def main():
80
88
action = "store_true" ,
81
89
help = "Store the docker images in redis keys." ,
82
90
)
91
+ parser .add_argument ("--github_token" , type = str , default = PERFORMANCE_GH_TOKEN )
92
+ parser .add_argument ("--pull-request" , type = str , default = None , nargs = "?" , const = "" )
83
93
args = parser .parse_args ()
84
94
if args .logname is not None :
85
95
print ("Writting log to {}" .format (args .logname ))
@@ -138,7 +148,8 @@ def main():
138
148
build_spec_image_prefetch (builders_folder , different_build_specs )
139
149
140
150
builder_consumer_group_create (conn )
141
-
151
+ if args .github_token is not None :
152
+ logging .info ("detected a github token. will update as much as possible!!! =)" )
142
153
previous_id = args .consumer_start_id
143
154
while True :
144
155
previous_id , new_builds_count , _ = builder_process_stream (
@@ -148,6 +159,7 @@ def main():
148
159
previous_id ,
149
160
args .docker_air_gap ,
150
161
arch ,
162
+ args .github_token ,
151
163
)
152
164
153
165
@@ -172,15 +184,28 @@ def builder_consumer_group_create(conn, id="$"):
172
184
)
173
185
174
186
187
+ def check_benchmark_build_comment (comments ):
188
+ res = False
189
+ pos = - 1
190
+ for n , comment in enumerate (comments ):
191
+ body = comment .body
192
+ if "CE Performance Automation : step 1 of 2" in body :
193
+ res = True
194
+ pos = n
195
+ return res , pos
196
+
197
+
175
198
def builder_process_stream (
176
199
builders_folder ,
177
200
conn ,
178
201
different_build_specs ,
179
202
previous_id ,
180
203
docker_air_gap = False ,
181
204
arch = "amd64" ,
205
+ github_token = None ,
182
206
):
183
207
new_builds_count = 0
208
+ auto_approve_github_comments = True
184
209
build_stream_fields_arr = []
185
210
logging .info ("Entering blocking read waiting for work." )
186
211
consumer_name = "{}-proc#{}" .format (STREAM_GH_EVENTS_COMMIT_BUILDERS_CG , "1" )
@@ -197,7 +222,6 @@ def builder_process_stream(
197
222
else :
198
223
streamId , testDetails = newTestInfo [0 ][1 ][0 ]
199
224
logging .info ("Received work . Stream id {}." .format (streamId ))
200
- conn .lpush ("benchmarks:{streamId}" )
201
225
# commit = None
202
226
# commited_date = ""
203
227
# tag = ""
@@ -217,6 +241,12 @@ def builder_process_stream(
217
241
buffer = conn .get (binary_zip_key )
218
242
git_timestamp_ms = None
219
243
use_git_timestamp = False
244
+ commit_datetime = "n/a"
245
+ if b"commit_datetime" in testDetails :
246
+ commit_datetime = int (testDetails [b"commit_datetime" ].decode ())
247
+ commit_summary = "n/a"
248
+ if b"commit_summary" in testDetails :
249
+ commit_summary = int (testDetails [b"commit_summary" ].decode ())
220
250
git_branch , git_version = get_branch_version_from_test_details (testDetails )
221
251
if b"use_git_timestamp" in testDetails :
222
252
use_git_timestamp = bool (testDetails [b"use_git_timestamp" ])
@@ -239,6 +269,30 @@ def builder_process_stream(
239
269
if b"tests_groups_regexp" in testDetails :
240
270
tests_groups_regexp = testDetails [b"tests_groups_regexp" ].decode ()
241
271
272
+ # github updates
273
+ is_actionable_pr = False
274
+ contains_regression_comment = False
275
+ github_pr = None
276
+ old_regression_comment_body = ""
277
+ pr_link = ""
278
+ regression_comment = ""
279
+ pull_request = None
280
+ if b"pull_request" in testDetails :
281
+ pull_request = testDetails [b"pull_request" ].decode ()
282
+ logging .info (f"Detected PR info in builder. PR: { pull_request } " )
283
+ verbose = True
284
+
285
+ fn = check_benchmark_build_comment
286
+ (
287
+ contains_regression_comment ,
288
+ github_pr ,
289
+ is_actionable_pr ,
290
+ old_regression_comment_body ,
291
+ pr_link ,
292
+ regression_comment ,
293
+ ) = check_github_available_and_actionable (
294
+ fn , github_token , pull_request , "redis" , "redis" , verbose
295
+ )
242
296
for build_spec in different_build_specs :
243
297
build_config , id = get_build_config (builders_folder + "/" + build_spec )
244
298
build_config_metadata = get_build_config_metadata (build_config )
@@ -356,6 +410,8 @@ def builder_process_stream(
356
410
"tests_priority_lower_limit" : tests_priority_lower_limit ,
357
411
"tests_groups_regexp" : tests_groups_regexp ,
358
412
}
413
+ if pull_request is not None :
414
+ build_stream_fields ["pull_request" ] = pull_request
359
415
if git_branch is not None :
360
416
build_stream_fields ["git_branch" ] = git_branch
361
417
if git_version is not None :
@@ -389,12 +445,44 @@ def builder_process_stream(
389
445
id , git_hash , benchmark_stream_id
390
446
)
391
447
)
392
- builder_list_completed = f"builder:{ streamId } :builds_completed"
393
- conn .lpush (builder_list_completed , benchmark_stream_id )
448
+ streamId_decoded = streamId .decode ()
449
+ benchmark_stream_id_decoded = benchmark_stream_id .decode ()
450
+ builder_list_completed = (
451
+ f"builder:{ streamId_decoded } :builds_completed"
452
+ )
453
+ conn .lpush (builder_list_completed , benchmark_stream_id_decoded )
394
454
conn .expire (builder_list_completed , REDIS_BINS_EXPIRE_SECS )
395
455
logging .info (
396
- f"Adding information of build->benchmark stream info in list { builder_list_completed } . Adding benchmark stream id: { benchmark_stream_id } "
456
+ f"Adding information of build->benchmark stream info in list { builder_list_completed } . Adding benchmark stream id: { benchmark_stream_id_decoded } "
457
+ )
458
+ benchmark_stream_ids = [benchmark_stream_id_decoded ]
459
+ comment_body = generate_build_finished_pr_comment (
460
+ benchmark_stream_ids ,
461
+ commit_datetime ,
462
+ commit_summary ,
463
+ git_branch ,
464
+ git_hash ,
465
+ tests_groups_regexp ,
466
+ tests_priority_lower_limit ,
467
+ tests_priority_upper_limit ,
468
+ tests_regexp ,
397
469
)
470
+ if is_actionable_pr :
471
+ if contains_regression_comment :
472
+ update_comment_if_needed (
473
+ auto_approve_github_comments ,
474
+ comment_body ,
475
+ old_regression_comment_body ,
476
+ regression_comment ,
477
+ verbose ,
478
+ )
479
+ else :
480
+ create_new_pr_comment (
481
+ auto_approve_github_comments ,
482
+ comment_body ,
483
+ github_pr ,
484
+ pr_link ,
485
+ )
398
486
shutil .rmtree (temporary_dir , ignore_errors = True )
399
487
new_builds_count = new_builds_count + 1
400
488
build_stream_fields_arr .append (build_stream_fields )
0 commit comments