15
15
"""
16
16
17
17
from typing import Optional
18
+ import argparse
18
19
from github .Repository import Repository
19
20
from github .Workflow import Workflow
20
21
from github .GithubException import GithubException
21
- from tools . library_functions import StrPath
22
- from tools . iterate_libraries import (
22
+ from library_functions import StrPath
23
+ from iterate_libraries import (
23
24
iter_remote_bundle_with_func ,
24
25
RemoteLibFunc_IterResult ,
25
26
)
28
29
def run_gh_rest_check (
29
30
lib_repo : Repository ,
30
31
user : Optional [str ] = None ,
32
+ branch : Optional [str ] = None ,
31
33
workflow_filename : Optional [str ] = "build.yml" ,
32
34
) -> str :
33
35
"""Uses ``PyGithub`` to check the CI status of a repository
34
36
35
37
:param Repository lib_repo: The repo as a github.Repository.Repository object
36
38
:param str|None user: The user that triggered the run; if `None` is
37
39
provided, any user is acceptable
40
+ :param str|None branch: The branch name to specifically check; if `None` is
41
+ provided, all branches are allowed; this is the default
38
42
:param str|None workflow_filename: The filename of the workflow; if `None` is
39
- provided, any workflow name is acceptable; the default is `"build.yml"`
43
+ provided, any workflow name is acceptable; the default is `` "build.yml"` `
40
44
:return: The requested runs conclusion
41
45
:rtype: str
42
46
"""
43
47
44
48
arg_dict = {}
45
49
if user is not None :
46
50
arg_dict ["actor" ] = user
51
+ if branch is not None :
52
+ arg_dict ["branch" ] = branch
47
53
48
54
workflow : Workflow = lib_repo .get_workflow (workflow_filename )
49
55
workflow_runs = workflow .get_runs (** arg_dict )
@@ -53,6 +59,7 @@ def run_gh_rest_check(
53
59
def check_build_status (
54
60
lib_repo : Repository ,
55
61
user : Optional [str ] = None ,
62
+ branch : Optional [str ] = None ,
56
63
workflow_filename : Optional [str ] = "build.yml" ,
57
64
debug : bool = False ,
58
65
) -> Optional [str ]:
@@ -62,6 +69,8 @@ def check_build_status(
62
69
:param Repository lib_repo: The repo as a github.Repository.Repository object
63
70
:param str|None user: The user that triggered the run; if `None` is
64
71
provided, any user is acceptable
72
+ :param str|None branch: The branch name to specifically check; if `None` is
73
+ provided, all branches are allowed; this is the default
65
74
:param str|None workflow_filename: The filename of the workflow; if `None`
66
75
is provided, any workflow name is acceptable; the defail is `"build.yml"`
67
76
:param bool debug: Whether debug statements should be printed to the standard
@@ -74,8 +83,13 @@ def check_build_status(
74
83
if debug :
75
84
print ("Checking" , lib_repo .name )
76
85
86
+ if lib_repo .archived :
87
+ return True
88
+
77
89
try :
78
- result = run_gh_rest_check (lib_repo , user , workflow_filename ) == "success"
90
+ result = (
91
+ run_gh_rest_check (lib_repo , user , branch , workflow_filename ) == "success"
92
+ )
79
93
if debug and not result :
80
94
print ("***" , "Library" , lib_repo .name , "failed the patch!" , "***" )
81
95
return result
@@ -94,6 +108,7 @@ def check_build_status(
94
108
def check_build_statuses (
95
109
gh_token : str ,
96
110
user : Optional [str ] = None ,
111
+ branch : Optional [str ] = "main" ,
97
112
workflow_filename : Optional [str ] = "build.yml" ,
98
113
* ,
99
114
debug : bool = False ,
@@ -104,6 +119,8 @@ def check_build_statuses(
104
119
:param str gh_token: The Github token to be used for with the Github API
105
120
:param str|None user: The user that triggered the run; if `None` is
106
121
provided, any user is acceptable
122
+ :param str|None branch: The branch name to specifically check; if `None` is
123
+ provided, all branches are allowed; this is the default
107
124
:param str|None workflow_filename: The filename of the workflow; if `None` is
108
125
provided, any workflow name is acceptable; the defail is `"build.yml"`
109
126
:param bool debug: Whether debug statements should be printed to
@@ -113,9 +130,10 @@ def check_build_statuses(
113
130
:rtype: list
114
131
"""
115
132
116
- args = (user , workflow_filename )
117
- kwargs = {"debug" : debug }
118
- return iter_remote_bundle_with_func (gh_token , [(check_build_status , args , kwargs )])
133
+ return iter_remote_bundle_with_func (
134
+ gh_token ,
135
+ [(check_build_status , (user , branch , workflow_filename ), {"debug" : debug })],
136
+ )
119
137
120
138
121
139
def save_build_statuses (
@@ -138,3 +156,60 @@ def save_build_statuses(
138
156
with open (failures_filepath , mode = "w" , encoding = "utf-8" ) as outputfile :
139
157
for build in bad_builds :
140
158
outputfile .write (build + "\n " )
159
+
160
+
161
+ if __name__ == "__main__" :
162
+
163
+ parser = argparse .ArgumentParser (
164
+ description = "Check the CI status of the Bundle libraries"
165
+ )
166
+ parser .add_argument (
167
+ "gh_token" , metavar = "GH_TOKEN" , type = str , help = "GitHub token with proper scopes"
168
+ )
169
+ parser .add_argument (
170
+ "--user" ,
171
+ metavar = "U" ,
172
+ type = str ,
173
+ dest = "user" ,
174
+ default = None ,
175
+ help = "Select a specific user that triggered the workflow" ,
176
+ )
177
+ parser .add_argument (
178
+ "--branch" ,
179
+ metavar = "B" ,
180
+ type = str ,
181
+ dest = "branch" ,
182
+ default = None ,
183
+ help = 'Branch name; default is "main"' ,
184
+ )
185
+ parser .add_argument (
186
+ "--workflow" ,
187
+ metavar = "W" ,
188
+ type = str ,
189
+ dest = "workflow" ,
190
+ default = "build.yml" ,
191
+ help = 'Workflow name; default is "build.yml"' ,
192
+ )
193
+ parser .add_argument (
194
+ "--debug" , action = "store_true" , help = "Print debug text during execution"
195
+ )
196
+
197
+ args = parser .parse_args ()
198
+
199
+ results = check_build_statuses (
200
+ args .gh_token , args .user , args .branch , args .workflow , debug = args .debug
201
+ )
202
+ fail_list = [
203
+ repo_name .name for repo_name , repo_results in results if not repo_results [0 ]
204
+ ]
205
+
206
+ if fail_list :
207
+ print (f'Failures for CI workflow "{ args .workflow } ":' )
208
+ for failure in fail_list :
209
+ print (failure )
210
+ RETURN_CODE = 1
211
+ else :
212
+ print (f"No failures for CI workflow: { args .workflow } !" )
213
+ RETURN_CODE = 0
214
+
215
+ raise SystemExit (RETURN_CODE )
0 commit comments