42
42
all_ports_all_boards ,
43
43
)
44
44
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" ,
47
51
"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
+ }
52
54
53
55
PATTERN_DOCS = (
54
56
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)$|"
56
58
r"(?:-stubs|\.(?:md|MD|rst|RST))$"
57
59
)
58
60
59
- PATTERN_WINDOWS = [
61
+ PATTERN_WINDOWS = {
60
62
".github/" ,
61
63
"extmod/" ,
62
64
"lib/" ,
63
65
"mpy-cross/" ,
64
66
"ports/unix/" ,
65
- "ports/windows/" ,
66
67
"py/" ,
67
- "requirements" ,
68
68
"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
+
70
84
71
85
if len (sys .argv ) > 1 :
72
86
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" ))
75
93
else :
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::" )
83
105
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 )
90
109
91
110
92
111
def set_output (name : str , value ):
@@ -155,11 +174,7 @@ def get_settings(board):
155
174
boards_to_build .update (port_to_boards [port ])
156
175
continue
157
176
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 ]):
163
178
continue
164
179
165
180
# 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):
269
284
else :
270
285
for file in changed_files :
271
286
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
+ ):
273
290
build_windows = True
274
291
break
275
292
else :
@@ -284,11 +301,7 @@ def set_windows(build_windows: bool):
284
301
def main ():
285
302
# Build all if no changed files
286
303
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" ))
292
305
293
306
# Set jobs
294
307
set_docs (build_all )
0 commit comments