4242 all_ports_all_boards ,
4343)
4444
45- IGNORE = [
46- "tools/ci_set_matrix.py" ,
45+ # Files that never influence board builds
46+ IGNORE_BOARD = {
47+ ".devcontainer" ,
48+ "docs" ,
49+ "tests" ,
50+ "tools/ci_changes_per_commit.py" ,
4751 "tools/ci_check_duplicate_usb_vid_pid.py" ,
48- ]
49-
50- # Files in these directories never influence board builds
51- IGNORE_DIRS = ["tests" , "docs" , ".devcontainer" ]
52+ "tools/ci_set_matrix.py" ,
53+ }
5254
5355PATTERN_DOCS = (
5456 r"^(?:\.github|docs|extmod\/ulab)|"
55- r"^(?:(?:ports\/\w+\/bindings|shared-bindings)\S+\.c|tools\/extract_pyi\.py|conf\.py|requirements-doc\.txt)$|"
57+ r"^(?:(?:ports\/\w+\/bindings|shared-bindings)\S+\.c|tools\/extract_pyi\.py|\.readthedocs\.yml| conf\.py|requirements-doc\.txt)$|"
5658 r"(?:-stubs|\.(?:md|MD|rst|RST))$"
5759)
5860
59- PATTERN_WINDOWS = [
61+ PATTERN_WINDOWS = {
6062 ".github/" ,
6163 "extmod/" ,
6264 "lib/" ,
6365 "mpy-cross/" ,
6466 "ports/unix/" ,
65- "ports/windows/" ,
6667 "py/" ,
67- "requirements" ,
6868 "tools/" ,
69- ]
69+ "requirements-dev.txt" ,
70+ }
71+
72+
73+ def git_diff (pattern : str ):
74+ return set (
75+ subprocess .run (
76+ f"git diff { pattern } --name-only" ,
77+ capture_output = True ,
78+ shell = True ,
79+ )
80+ .stdout .decode ("utf-8" )
81+ .split ("\n " )[:- 1 ]
82+ )
83+
7084
7185if len (sys .argv ) > 1 :
7286 print ("Using files list on commandline" )
73- changed_files = sys .argv [1 :]
74- last_failed_jobs = {}
87+ changed_files = set (sys .argv [1 :])
88+ elif os .environ .get ("BASE_SHA" ) and os .environ .get ("HEAD_SHA" ):
89+ print ("Using files list by computing diff" )
90+ changed_files = git_diff ("$BASE_SHA...$HEAD_SHA" )
91+ if os .environ .get ("GITHUB_EVENT_NAME" ) == "pull_request" :
92+ changed_files .intersection_update (git_diff ("$GITHUB_SHA~...$GITHUB_SHA" ))
7593else :
76- c = os .environ ["CHANGED_FILES" ]
77- if c == "" :
78- print ("CHANGED_FILES is in environment, but value is empty" )
79- changed_files = []
80- else :
81- print ("Using files list in CHANGED_FILES" )
82- changed_files = json .loads (c .replace ("\\ " , "" ))
94+ print ("Using files list in CHANGED_FILES" )
95+ changed_files = set (json .loads (os .environ .get ("CHANGED_FILES" ) or "[]" ))
96+
97+ print ("Using jobs list in LAST_FAILED_JOBS" )
98+ last_failed_jobs = json .loads (os .environ .get ("LAST_FAILED_JOBS" ) or "{}" )
99+
100+
101+ def print_enclosed (title , content ):
102+ print ("::group::" + title )
103+ print (content )
104+ print ("::endgroup::" )
83105
84- j = os .environ ["LAST_FAILED_JOBS" ]
85- if j == "" :
86- print ("LAST_FAILED_JOBS is in environment, but value is empty" )
87- last_failed_jobs = {}
88- else :
89- last_failed_jobs = json .loads (j )
106+
107+ print_enclosed ("Log: changed_files" , changed_files )
108+ print_enclosed ("Log: last_failed_jobs" , last_failed_jobs )
90109
91110
92111def set_output (name : str , value ):
@@ -155,11 +174,7 @@ def get_settings(board):
155174 boards_to_build .update (port_to_boards [port ])
156175 continue
157176
158- # Check the ignore list to see if the file isn't used on board builds.
159- if p in IGNORE :
160- continue
161-
162- if any ([p .startswith (d ) for d in IGNORE_DIRS ]):
177+ if any ([p .startswith (d ) for d in IGNORE_BOARD ]):
163178 continue
164179
165180 # As a (nearly) last resort, for some certain files, we compute the settings from the
@@ -269,7 +284,9 @@ def set_windows(build_windows: bool):
269284 else :
270285 for file in changed_files :
271286 for pattern in PATTERN_WINDOWS :
272- if file .startswith (pattern ):
287+ if file .startswith (pattern ) and not any (
288+ [file .startswith (d ) for d in IGNORE_BOARD ]
289+ ):
273290 build_windows = True
274291 break
275292 else :
@@ -284,11 +301,7 @@ def set_windows(build_windows: bool):
284301def main ():
285302 # Build all if no changed files
286303 build_all = not changed_files
287- print (
288- "Building all docs/boards"
289- if build_all
290- else "Adding docs/boards to build based on changed files"
291- )
304+ print ("Running: " + ("all" if build_all else "conditionally" ))
292305
293306 # Set jobs
294307 set_docs (build_all )
0 commit comments