12
12
13
13
if TYPE_CHECKING :
14
14
from github import WorkflowRun , Repository
15
-
15
+
16
16
17
17
script_path = Path (__file__ ).resolve ()
18
18
root_path = script_path .parent .parent .parent
@@ -30,7 +30,7 @@ def get_check_runs(self: Repository.Repository, ref: str, **kwargs: str) -> Pagi
30
30
f"{ self .url } /commits/{ ref } /check-runs" ,
31
31
firstParams = None ,
32
32
list_item = "check_runs" )
33
-
33
+
34
34
Repository .Repository = MyRepository
35
35
36
36
from github import WorkflowRun , Artifact
@@ -51,7 +51,7 @@ def download_logs(self, path: Path) -> None:
51
51
if self ._requester ._Requester__auth is not None : # type: ignore
52
52
headers ["Authorization" ] = f"{ self ._requester ._Requester__auth .token_type } { self ._requester ._Requester__auth .token } " # type: ignore
53
53
headers ["User-Agent" ] = self ._requester ._Requester__userAgent # type: ignore
54
-
54
+
55
55
resp = requests .get (url , headers = headers , allow_redirects = True )
56
56
57
57
if resp .status_code != 200 :
@@ -70,7 +70,7 @@ def download_artifacts(self, path: Path) -> None:
70
70
if self ._requester ._Requester__auth is not None : # type: ignore
71
71
headers ["Authorization" ] = f"{ self ._requester ._Requester__auth .token_type } { self ._requester ._Requester__auth .token } " # type: ignore
72
72
headers ["User-Agent" ] = self ._requester ._Requester__userAgent # type: ignore
73
-
73
+
74
74
resp = requests .get (artifact .archive_download_url , headers = headers , allow_redirects = True )
75
75
76
76
if resp .status_code != 200 :
@@ -93,15 +93,15 @@ def download_artifact(self, name: str, path: Path) -> None:
93
93
if self ._requester ._Requester__auth is not None : # type: ignore
94
94
headers ["Authorization" ] = f"{ self ._requester ._Requester__auth .token_type } { self ._requester ._Requester__auth .token } " # type: ignore
95
95
headers ["User-Agent" ] = self ._requester ._Requester__userAgent # type: ignore
96
-
96
+
97
97
resp = requests .get (artifact .archive_download_url , headers = headers , allow_redirects = True )
98
98
99
99
if resp .status_code != 200 :
100
100
raise Exception (f"Unable to download artifact ${ artifact .name } . Received status code { resp .status_code } { resp .reason } " )
101
101
102
102
with (path / f"{ artifact .name } .zip" ).open ("wb" ) as f :
103
103
f .write (resp .content )
104
-
104
+
105
105
106
106
WorkflowRun .WorkflowRun = MyWorkflowRun
107
107
@@ -133,7 +133,7 @@ def make(self, directory: Path, workflow_runs: List[WorkflowRun.WorkflowRun]) ->
133
133
actions .append (FileAction (action_args ))
134
134
else :
135
135
raise Exception (f"Unknown action type { action_type } " )
136
-
136
+
137
137
artifacts .append (ReleaseArtifact (artifact , actions , self .skip_checks ))
138
138
139
139
for artifact in artifacts :
@@ -157,7 +157,7 @@ def run(self) -> List[Path]:
157
157
print (f"Downloading logs for { workflow_run .name } " )
158
158
workflow_run .download_logs (Path (self .temp_workdir .name )) # type: ignore
159
159
return list (map (Path , Path (self .temp_workdir .name ).glob ("**/*" )))
160
-
160
+
161
161
class WorkflowArtifactAction ():
162
162
163
163
def __init__ (self , workflow_runs : List [WorkflowRun .WorkflowRun ], ** kwargs : str ) -> None :
@@ -180,7 +180,7 @@ def run(self) -> List[Path]:
180
180
print (f"Downloading artifacts for { workflow_run .name } to { self .temp_workdir .name } " )
181
181
workflow_run .download_artifacts (Path (self .temp_workdir .name )) # type: ignore
182
182
return list (map (Path , Path (self .temp_workdir .name ).glob ("**/*" )))
183
-
183
+
184
184
class ShellAction ():
185
185
def __init__ (self , command : str , ** kwargs : Any ) -> None :
186
186
self .command = command .strip ()
@@ -202,7 +202,7 @@ def run(self) -> List[Path]:
202
202
concrete_command = self ._rewrite_command ()
203
203
subprocess .run (concrete_command , cwd = self .temp_workdir .name , check = True , shell = True )
204
204
return list (map (Path , Path (self .temp_workdir .name ).glob ("**/*" )))
205
-
205
+
206
206
class FileAction ():
207
207
def __init__ (self , path : Path ) -> None :
208
208
self .path = path
@@ -228,8 +228,8 @@ def make(self, directory: Path) -> Path:
228
228
extension = "" .join (self .name .suffixes )[1 :]
229
229
if not extension in ["zip" , "tar" , "tar.gz" , "tar.bz2" , "tar.xz" ]:
230
230
raise Exception (f"Artifact { self .name } is not a support archive file, but has multiple files associated with it!" )
231
-
232
- ext_format_map = {
231
+
232
+ ext_format_map = {
233
233
"zip" : "zip" ,
234
234
"tar" : "tar" ,
235
235
"tar.gz" : "gztar" ,
@@ -241,7 +241,7 @@ def make(self, directory: Path) -> Path:
241
241
temp_dir_path = Path (temp_dir )
242
242
for file in files :
243
243
shutil .copy (file , temp_dir_path / file .name )
244
-
244
+
245
245
return Path (shutil .make_archive (str (directory / self .name .with_suffix ("" )), ext_format_map [extension ], root_dir = temp_dir_path ))
246
246
247
247
def main (args : 'argparse.Namespace' ) -> int :
@@ -264,13 +264,13 @@ def main(args: 'argparse.Namespace') -> int:
264
264
if len (pull_candidates ) != 1 :
265
265
print (f"Error: expected exactly one PR for SHA { args .head_sha } , but found { len (pull_candidates )} " , file = sys .stderr )
266
266
return 1
267
-
267
+
268
268
pull_request = pull_candidates [0 ]
269
269
270
270
if pull_request .state != "open" :
271
271
print (f"Error: PR { pull_request .url } is not open" , file = sys .stderr )
272
272
return 1
273
-
273
+
274
274
print (f"Found PR { pull_request .url } based on { pull_request .base .ref } " )
275
275
276
276
rc_branch_regex = r"^rc/(?P<version>.*)$"
@@ -302,7 +302,7 @@ def main(args: 'argparse.Namespace') -> int:
302
302
303
303
action_workflow_run_url_regex = r"^https://(?P<github_url>[^/]+)/(?P<owner>[^/]+)/(?P<repo>[^/]+)/actions/runs/(?P<run_id>\d+)$"
304
304
action_workflow_job_run_url_regex = r"^https://(?P<github_url>[^/]+)/(?P<owner>[^/]+)/(?P<repo>[^/]+)/actions/runs/(?P<run_id>\d+)/job/(?P<job_id>\d+)$"
305
-
305
+
306
306
workflow_runs : List [WorkflowRun .WorkflowRun ] = []
307
307
for check_run in check_runs : # type: ignore
308
308
check_run = cast (CheckRun .CheckRun , check_run )
@@ -322,7 +322,7 @@ def main(args: 'argparse.Namespace') -> int:
322
322
else :
323
323
print (f"Unable to handle checkrun { check_run .name } with id { check_run .id } with { check_run .details_url } " )
324
324
return 1
325
-
325
+
326
326
print ("Filtering workflow runs to only include the latest run for each workflow." )
327
327
workflow_runs_per_id : Dict [int , WorkflowRun .WorkflowRun ] = {}
328
328
for workflow_run in workflow_runs :
0 commit comments