@@ -82,10 +82,12 @@ def git_diff(pattern: str):
8282 )
8383
8484
85+ compute_diff = bool (os .environ .get ("BASE_SHA" ) and os .environ .get ("HEAD_SHA" ))
86+
8587if len (sys .argv ) > 1 :
8688 print ("Using files list on commandline" )
8789 changed_files = set (sys .argv [1 :])
88- elif os . environ . get ( "BASE_SHA" ) and os . environ . get ( "HEAD_SHA" ) :
90+ elif compute_diff :
8991 print ("Using files list by computing diff" )
9092 changed_files = git_diff ("$BASE_SHA...$HEAD_SHA" )
9193 if os .environ .get ("GITHUB_EVENT_NAME" ) == "pull_request" :
@@ -116,7 +118,7 @@ def set_output(name: str, value):
116118 print (f"Would set GitHub actions output { name } to '{ value } '" )
117119
118120
119- def set_boards (build_all = False ):
121+ def set_boards (build_all : bool ):
120122 all_board_ids = set ()
121123 boards_to_build = all_board_ids if build_all else set ()
122124
@@ -245,54 +247,62 @@ def get_settings(board):
245247 set_output ("ports" , json .dumps (port_to_boards_to_build ))
246248
247249
248- def set_docs (run = bool ( last_failed_jobs . get ( "docs" )) ):
250+ def set_docs (run : bool ):
249251 if not run :
250- pattern_doc = re .compile (PATTERN_DOCS )
251- github_workspace = os .environ .get ("GITHUB_WORKSPACE" ) or ""
252- github_workspace = github_workspace and github_workspace + "/"
253- for file in changed_files :
254- if pattern_doc .search (file ) and (
255- (
256- subprocess .run (
257- f"git diff -U0 $BASE_SHA...$HEAD_SHA { github_workspace + file } | grep -o -m 1 '^[+-]\/\/|'" ,
258- capture_output = True ,
259- shell = True ,
260- ).stdout
261- )
262- if file .endswith (".c" )
263- else True
264- ):
265- run = True
266- break
252+ if last_failed_jobs .get ("docs" ):
253+ run = True
254+ else :
255+ pattern_doc = re .compile (PATTERN_DOCS )
256+ github_workspace = os .environ .get ("GITHUB_WORKSPACE" ) or ""
257+ github_workspace = github_workspace and github_workspace + "/"
258+ for file in changed_files :
259+ if pattern_doc .search (file ) and (
260+ (
261+ subprocess .run (
262+ f"git diff -U0 $BASE_SHA...$HEAD_SHA { github_workspace + file } | grep -o -m 1 '^[+-]\/\/|'" ,
263+ capture_output = True ,
264+ shell = True ,
265+ ).stdout
266+ )
267+ if file .endswith (".c" )
268+ else True
269+ ):
270+ run = True
271+ break
267272
268273 # Set the step outputs
269274 print ("Building docs:" , run )
270275 set_output ("docs" , run )
271276
272277
273- def set_windows (run = bool ( last_failed_jobs . get ( "windows" )) ):
278+ def set_windows (run : bool ):
274279 if not run :
275- for file in changed_files :
276- for pattern in PATTERN_WINDOWS :
277- if file .startswith (pattern ) and not any (
278- [file .startswith (path ) for path in IGNORE_BOARD ]
279- ):
280- run = True
281- break
282- else :
283- continue
284- break
280+ if last_failed_jobs .get ("windows" ):
281+ run = True
282+ else :
283+ for file in changed_files :
284+ for pattern in PATTERN_WINDOWS :
285+ if file .startswith (pattern ) and not any (
286+ [file .startswith (path ) for path in IGNORE_BOARD ]
287+ ):
288+ run = True
289+ break
290+ else :
291+ continue
292+ break
285293
286294 # Set the step outputs
287295 print ("Building windows:" , run )
288296 set_output ("windows" , run )
289297
290298
291299def main ():
300+ run_all = not changed_files and not compute_diff
301+ print ("Running: " + ("all" if run_all else "conditionally" ))
292302 # Set jobs
293- set_docs ()
294- set_windows ()
295- set_boards ()
303+ set_docs (run_all )
304+ set_windows (run_all )
305+ set_boards (run_all )
296306
297307
298308if __name__ == "__main__" :
0 commit comments