2323 print_console_tail ,
2424 require_sha ,
2525 start_file_job ,
26+ start_files_job ,
2627 stop_build ,
2728 wait_build ,
2829 wait_workflow_job_artifact ,
@@ -121,6 +122,10 @@ def set_status(args, suite, state, target, description):
121122 commit_status (REPO , args .sha , args .github_token , f"jenkins/path-tracer-{ suite } " , state , target , description )
122123
123124
125+ def set_compare_status (args , suite , state , target , description ):
126+ commit_status (REPO , args .sha , args .github_token , f"jenkins/path-tracer-compare-{ suite } " , state , target , description )
127+
128+
124129def start_suite (args , headers , suite ):
125130 job = f"ci/ditt/real/ex40-{ suite } "
126131 set_status (args , suite , "pending" , f"https://github.com/{ REPO } /actions/runs/{ args .source_run_id } " , f"Waiting for Jenkins { suite } path tracer run." )
@@ -157,6 +162,45 @@ def start_suite(args, headers, suite):
157162 return job , number , result , build_url
158163
159164
165+ def start_compare_suite (args , headers , suite ):
166+ job = f"ci/ditt/compare/o1experimental-vs-o3-{ suite } "
167+ set_compare_status (args , suite , "pending" , f"https://github.com/{ REPO } /actions/runs/{ args .source_run_id } " , f"Waiting for Jenkins { suite } O1experimental vs O3 comparison." )
168+ cancel_superseded (args .jenkins_url , headers , job , {"SOURCE_REPOSITORY" : REPO , "SOURCE_BRANCH" : BRANCH }, {
169+ "SOURCE_RUN_ID" : args .source_run_id ,
170+ "SOURCE_RUN_ATTEMPT" : args .source_run_attempt ,
171+ })
172+ fields = {
173+ "PUBLISH" : args .publish ,
174+ "SOURCE_REPOSITORY" : REPO ,
175+ "SOURCE_BRANCH" : BRANCH ,
176+ "SOURCE_SHA" : args .sha ,
177+ "SOURCE_RUN_ID" : args .source_run_id ,
178+ "SOURCE_RUN_ATTEMPT" : args .source_run_attempt ,
179+ "SOURCE_WORKFLOW" : args .source_workflow ,
180+ }
181+ files = [
182+ ("EX40_RELEASE_PACKAGE_FILE" , args .release_package_path ),
183+ ("EX40_O1_PACKAGE_FILE" , args .o1_package_path ),
184+ ]
185+ number = start_files_job (args .jenkins_url , headers , job , fields , files )
186+ build_url = f"{ args .jenkins_url .rstrip ('/' )} /{ job_path (job )} /{ number } /"
187+ set_compare_status (args , suite , "pending" , build_url , f"Jenkins { suite } O1experimental vs O3 build #{ number } is running." )
188+ print (f"Started Jenkins { job } #{ number } : { build_url } " )
189+ try :
190+ result = wait_build (args .jenkins_url , headers , job , number , int (args .jenkins_timeout_minutes ) * 60 )
191+ except CiError :
192+ stop_build (args .jenkins_url , headers , job , number )
193+ print_console_tail (args .jenkins_url , headers , job , number )
194+ set_compare_status (args , suite , "failure" , build_url , f"Jenkins { suite } comparison did not complete." )
195+ raise
196+ if result not in {"SUCCESS" , "UNSTABLE" }:
197+ print_console_tail (args .jenkins_url , headers , job , number )
198+ set_compare_status (args , suite , "failure" , build_url , f"Jenkins { suite } comparison finished with { result } ." )
199+ raise CiError (f"Jenkins { job } #{ number } finished with { result } ." )
200+ set_compare_status (args , suite , "success" , build_url , f"Jenkins { suite } O1experimental vs O3 { result .lower ()} ." )
201+ return job , number , result , build_url
202+
203+
160204def trigger (args ):
161205 if args .repository != REPO or choice (args .branch , {BRANCH }, "branch" ) != BRANCH :
162206 raise CiError ("Invalid source repository or branch." )
@@ -179,6 +223,28 @@ def trigger(args):
179223 print (f"{ result [0 ]} #{ result [1 ]} { result [2 ]} { result [3 ]} " )
180224
181225
226+ def trigger_compare (args ):
227+ if args .repository != REPO or choice (args .branch , {BRANCH }, "branch" ) != BRANCH :
228+ raise CiError ("Invalid source repository or branch." )
229+ args .sha = require_sha (args .sha )
230+ args .scene_set = choice (args .scene_set , SCENES , "scene set" )
231+ args .publish = bool_text (args .publish )
232+ if not args .jenkins_url .startswith ("https://" ) or not args .jenkins_user or not args .jenkins_token :
233+ raise CiError ("Invalid Jenkins connection settings." )
234+ if not args .source_run_id .isdigit () or not args .source_run_attempt .isdigit ():
235+ raise CiError ("Invalid source run metadata." )
236+ if not args .jenkins_timeout_minutes .isdigit () or not 10 <= int (args .jenkins_timeout_minutes ) <= 720 :
237+ raise CiError ("Invalid Jenkins timeout." )
238+ for path in [Path (args .release_package_path ), Path (args .o1_package_path )]:
239+ if not path .is_file () or path .stat ().st_size > MAX_PACKAGE_BYTES :
240+ raise CiError ("Invalid compare package path or size." )
241+ headers = basic_headers (args .jenkins_user , args .jenkins_token )
242+ add_jenkins_crumb (args .jenkins_url , headers )
243+ suites = ["public" , "private" ] if args .scene_set == "both" else [args .scene_set ]
244+ for result in [start_compare_suite (args , headers , suite ) for suite in suites ]:
245+ print (f"{ result [0 ]} #{ result [1 ]} { result [2 ]} { result [3 ]} " )
246+
247+
182248def parser ():
183249 parser = argparse .ArgumentParser ()
184250 sub = parser .add_subparsers (dest = "cmd" , required = True )
@@ -196,6 +262,10 @@ def parser():
196262 add_args (trigger_parser , ["jenkins-url" , "jenkins-user" , "jenkins-token" , "github-token" , "package-path" , "repository" , "branch" , "sha" , "source-run-id" , "source-run-attempt" , "source-workflow" , "scene-set" , "publish" ])
197263 trigger_parser .add_argument ("--jenkins-timeout-minutes" , default = "300" )
198264 trigger_parser .set_defaults (func = trigger )
265+ compare_parser = sub .add_parser ("trigger-compare" )
266+ add_args (compare_parser , ["jenkins-url" , "jenkins-user" , "jenkins-token" , "github-token" , "release-package-path" , "o1-package-path" , "repository" , "branch" , "sha" , "source-run-id" , "source-run-attempt" , "source-workflow" , "scene-set" , "publish" ])
267+ compare_parser .add_argument ("--jenkins-timeout-minutes" , default = "420" )
268+ compare_parser .set_defaults (func = trigger_compare )
199269 return parser
200270
201271
0 commit comments