44
44
45
45
DEPLOY_BRANCHES = ["main" , "master" ]
46
46
47
+
47
48
class Config :
48
49
"""
49
50
Global configuration, for users of the library to modify.
@@ -102,8 +103,12 @@ def index_path(self):
102
103
def commit_message (self ):
103
104
if self ._commit_message is None :
104
105
print ("Getting commit message" )
105
- print (f"https://github.com/{ os .environ ['REPO_FULL_NAME' ]} /commit/{ self .git_sha } .patch" )
106
- commit = requests .get (f"https://github.com/{ os .environ ['REPO_FULL_NAME' ]} /commit/{ self .git_sha } .patch" ).text
106
+ print (
107
+ f"https://github.com/{ os .environ ['REPO_FULL_NAME' ]} /commit/{ self .git_sha } .patch"
108
+ )
109
+ commit = requests .get (
110
+ f"https://github.com/{ os .environ ['REPO_FULL_NAME' ]} /commit/{ self .git_sha } .patch"
111
+ ).text
107
112
print (commit )
108
113
self ._commit_message = commit .split ("diff --git a/" )[0 ]
109
114
print (self ._commit_message )
@@ -140,7 +145,6 @@ def task_root_for(self, platform):
140
145
raise NotImplementedError
141
146
142
147
143
-
144
148
CONFIG = Config ()
145
149
SHARED = Shared ()
146
150
@@ -234,9 +238,10 @@ def get_proxy_url(self) -> str:
234
238
235
239
def with_script (self , * script : str , as_gha = False ):
236
240
if as_gha :
237
- self .with_gha ("script_%s" % len (self .gh_actions ), gha .GithubActionScript (
238
- "\n " .join (script )
239
- ))
241
+ self .with_gha (
242
+ "script_%s" % len (self .gh_actions ),
243
+ gha .GithubActionScript ("\n " .join (script )),
244
+ )
240
245
else :
241
246
self .scripts .extend (script )
242
247
return self
@@ -345,7 +350,15 @@ def find(index_path: str) -> str:
345
350
346
351
def create_index_at (self , index_path : str , task_id : str ):
347
352
full_index_path = "%s.%s" % (CONFIG .index_prefix , index_path )
348
- SHARED .index_service .insertTask (full_index_path , { "taskId" : task_id , "data" : {}, "expires" : SHARED .from_now_json (self .index_and_artifacts_expire_in ), "rank" : 0 })
353
+ SHARED .index_service .insertTask (
354
+ full_index_path ,
355
+ {
356
+ "taskId" : task_id ,
357
+ "data" : {},
358
+ "expires" : SHARED .from_now_json (self .index_and_artifacts_expire_in ),
359
+ "rank" : 0 ,
360
+ },
361
+ )
349
362
350
363
def find_or_create (self , index_path : str ) -> str :
351
364
"""
@@ -381,7 +394,9 @@ def find_or_create(self, index_path: str) -> str:
381
394
SHARED .found_or_created_indexed_tasks [index_path ] = task_id
382
395
return task_id
383
396
384
- def with_additional_repo (self , repo_url : str , target : str , enabled = True , branch = None ):
397
+ def with_additional_repo (
398
+ self , repo_url : str , target : str , enabled = True , branch = None
399
+ ):
385
400
if not enabled :
386
401
return self
387
402
@@ -402,7 +417,7 @@ def with_curl_script(self, url: str, file_path: str, as_gha=False):
402
417
curl --compressed --ssl-no-revoke --retry 5 --connect-timeout 10 -Lf "%s" -o "%s"
403
418
"""
404
419
% (url , file_path ),
405
- as_gha = as_gha
420
+ as_gha = as_gha ,
406
421
)
407
422
408
423
def with_curl_artifact_script (
@@ -413,27 +428,30 @@ def with_curl_artifact_script(
413
428
directory = "public" ,
414
429
rename = None ,
415
430
extract = False ,
416
- as_gha = False
431
+ as_gha = False ,
417
432
):
418
433
queue_service = self .get_proxy_url () + "/api/queue"
419
434
ret = self .with_dependencies (task_id ).with_curl_script (
420
435
queue_service
421
436
+ "/v1/task/%s/artifacts/%s/%s" % (task_id , directory , artifact_name ),
422
437
os .path .join (out_directory , rename or url_basename (artifact_name )),
423
- as_gha = as_gha
438
+ as_gha = as_gha ,
424
439
)
425
440
if extract :
426
441
ret = self .with_script (
427
442
"tar xvf %s"
428
443
% os .path .join (out_directory , rename or url_basename (artifact_name )),
429
- as_gha = as_gha
444
+ as_gha = as_gha ,
430
445
)
431
446
432
447
return ret
433
448
434
449
def with_repo_bundle (self , name , dest , ** kwargs ):
435
450
return self .with_curl_artifact_script (
436
- CONFIG .decision_task_id , f"{ name } .bundle" , "$HOME/tasks/$TASK_ID" , directory = "private"
451
+ CONFIG .decision_task_id ,
452
+ f"{ name } .bundle" ,
453
+ "$HOME/tasks/$TASK_ID" ,
454
+ directory = "private" ,
437
455
).with_repo (
438
456
"$HOME/tasks/$TASK_ID/" + dest ,
439
457
f"$HOME/tasks/$TASK_ID/{ name } .bundle" ,
@@ -452,10 +470,15 @@ def with_gha(self, name: str, gha: gha.GithubAction, enabled=True):
452
470
return self
453
471
454
472
if gha .git_fetch_url and gha .git_fetch_url not in self .action_paths :
455
- self .with_additional_repo (gha .git_fetch_url , os .path .join (SHARED .task_root_for (self .platform ()), gha .repo_name ))
473
+ self .with_additional_repo (
474
+ gha .git_fetch_url ,
475
+ os .path .join (SHARED .task_root_for (self .platform ()), gha .repo_name ),
476
+ )
456
477
self .action_paths .add (gha .git_fetch_url )
457
478
458
- if not any (CONFIG .git_ref == "refs/heads/%s" % branch for branch in DEPLOY_BRANCHES ) and not CONFIG .git_ref .startswith ("refs/tags/" ):
479
+ if not any (
480
+ CONFIG .git_ref == "refs/heads/%s" % branch for branch in DEPLOY_BRANCHES
481
+ ) and not CONFIG .git_ref .startswith ("refs/tags/" ):
459
482
gha = gha .with_env ("PAHKAT_NO_DEPLOY" , "true" )
460
483
461
484
if "[no deploy]" in CONFIG .commit_message :
@@ -641,6 +664,7 @@ class WindowsGenericWorkerTask(GenericWorkerTask):
641
664
642
665
Scripts are written as `.bat` files executed with `cmd.exe`.
643
666
"""
667
+
644
668
def platform (self ):
645
669
return "win"
646
670
@@ -673,7 +697,11 @@ def build_worker_payload(self):
673
697
)
674
698
675
699
def build_command (self ):
676
- return ['cmd.exe /C "{}"' .format (deindent ("\n " .join (self .scripts + self .late_scripts )))]
700
+ return [
701
+ 'cmd.exe /C "{}"' .format (
702
+ deindent ("\n " .join (self .scripts + self .late_scripts ))
703
+ )
704
+ ]
677
705
678
706
def with_path_from_homedir (self , * paths : str ):
679
707
"""
@@ -760,10 +788,11 @@ def with_git(self):
760
788
)
761
789
762
790
def with_cmake (self ):
763
- return (
764
- self
765
- .with_path_from_homedir ("cmake\\ cmake-3.23.1-windows-x86_64\\ bin" )
766
- .with_directory_mount ("https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-windows-x86_64.zip" , path = "cmake" )
791
+ return self .with_path_from_homedir (
792
+ "cmake\\ cmake-3.23.1-windows-x86_64\\ bin"
793
+ ).with_directory_mount (
794
+ "https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-windows-x86_64.zip" ,
795
+ path = "cmake" ,
767
796
)
768
797
769
798
def with_curl_script (self , url , file_path , as_gha = False ):
@@ -1078,7 +1107,9 @@ def make_repo_bundle(path: str, bundle_name: str, sha: str, *, shallow=True):
1078
1107
if shallow :
1079
1108
subprocess .check_call (["git" , "config" , "user.name" , "Decision task" ])
1080
1109
subprocess .
check_call ([
"git" ,
"config" ,
"user.email" ,
"[email protected] " ])
1081
- tree = subprocess .check_output (["git" , "show" , sha , "--pretty=%T" , "--no-patch" ])
1110
+ tree = subprocess .check_output (
1111
+ ["git" , "show" , sha , "--pretty=%T" , "--no-patch" ]
1112
+ )
1082
1113
message = "Shallow version of commit " + sha
1083
1114
commit = subprocess .check_output (
1084
1115
["git" , "commit-tree" , tree .strip (), "-m" , message ]
@@ -1094,19 +1125,11 @@ def make_repo_bundle(path: str, bundle_name: str, sha: str, *, shallow=True):
1094
1125
"create" ,
1095
1126
f"../{ bundle_name } " ,
1096
1127
CONFIG .git_bundle_shallow_ref ,
1097
- ]
1128
+ ]
1098
1129
else :
1099
1130
subprocess .check_call (["git" , "fetch" , "--unshallow" , CONFIG .git_url ])
1100
- subprocess .check_call (
1101
- ["git" , "update-ref" , CONFIG .git_bundle_shallow_ref , sha ]
1102
- )
1103
- create = [
1104
- "git" ,
1105
- "bundle" ,
1106
- "create" ,
1107
- f"../{ bundle_name } " ,
1108
- "--all"
1109
- ]
1131
+ subprocess .check_call (["git" , "update-ref" , CONFIG .git_bundle_shallow_ref , sha ])
1132
+ create = ["git" , "bundle" , "create" , f"../{ bundle_name } " , "--all" ]
1110
1133
1111
1134
with subprocess .Popen (create ) as p :
1112
1135
os .chdir (cwd )
0 commit comments