Skip to content

Commit ec74be7

Browse files
committed
use set for changed_files and minor updates
1 parent 29cee60 commit ec74be7

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

tools/ci_set_matrix.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,36 @@
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

5355
PATTERN_DOCS = (
5456
r"^(?:\.github|docs|extmod\/ulab)|"
5557
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+
}
7071

7172

7273
def git_diff(pattern: str):
73-
return (
74+
return set(
7475
subprocess.run(
7576
f"git diff {pattern} --name-only",
7677
capture_output=True,
@@ -83,15 +84,15 @@ def git_diff(pattern: str):
8384

8485
if len(sys.argv) > 1:
8586
print("Using files list on commandline")
86-
changed_files = sys.argv[1:]
87+
changed_files = set(sys.argv[1:])
8788
elif os.environ.get("BASE_SHA") and os.environ.get("HEAD_SHA"):
8889
print("Using files list by computing diff")
8990
changed_files = git_diff("$BASE_SHA...$HEAD_SHA")
9091
if os.environ.get("GITHUB_EVENT_NAME") == "pull_request":
91-
changed_files = list(set(changed_files).intersection(git_diff("$HEAD_SHA~...$HEAD_SHA")))
92+
changed_files.intersection_update(git_diff("$HEAD_SHA~...$HEAD_SHA"))
9293
else:
9394
print("Using files list in CHANGED_FILES")
94-
changed_files = json.loads(os.environ.get("CHANGED_FILES") or "[]")
95+
changed_files = set(json.loads(os.environ.get("CHANGED_FILES") or "[]"))
9596

9697
print("Using jobs list in LAST_FAILED_JOBS")
9798
last_failed_jobs = json.loads(os.environ.get("LAST_FAILED_JOBS") or "{}")
@@ -103,8 +104,8 @@ def print_enclosed(title, content):
103104
print("::endgroup::")
104105

105106

106-
print_enclosed("LOG: changed_files", changed_files)
107-
print_enclosed("LOG: last_failed_jobs", last_failed_jobs)
107+
print_enclosed("Log: changed_files", changed_files)
108+
print_enclosed("Log: last_failed_jobs", last_failed_jobs)
108109

109110

110111
def set_output(name: str, value):
@@ -173,11 +174,7 @@ def get_settings(board):
173174
boards_to_build.update(port_to_boards[port])
174175
continue
175176

176-
# Check the ignore list to see if the file isn't used on board builds.
177-
if p in IGNORE:
178-
continue
179-
180-
if any([p.startswith(d) for d in IGNORE_DIRS]):
177+
if any([p.startswith(d) for d in IGNORE_BOARD]):
181178
continue
182179

183180
# As a (nearly) last resort, for some certain files, we compute the settings from the
@@ -287,7 +284,9 @@ def set_windows(build_windows: bool):
287284
else:
288285
for file in changed_files:
289286
for pattern in PATTERN_WINDOWS:
290-
if file.startswith(pattern):
287+
if file.startswith(pattern) and not any(
288+
[file.startswith(d) for d in IGNORE_BOARD]
289+
):
291290
build_windows = True
292291
break
293292
else:
@@ -302,11 +301,7 @@ def set_windows(build_windows: bool):
302301
def main():
303302
# Build all if no changed files
304303
build_all = not changed_files
305-
print(
306-
"Building all docs/boards"
307-
if build_all
308-
else "Adding docs/boards to build based on changed files"
309-
)
304+
print("Running: " + ("all" if build_all else "conditionally"))
310305

311306
# Set jobs
312307
set_docs(build_all)

0 commit comments

Comments
 (0)