use set for changed_files and minor updates

This commit is contained in:
MicroDev 2023-03-11 14:00:29 +05:30
parent 29cee603d3
commit ec74be7cb4
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730

View File

@ -42,13 +42,15 @@ from shared_bindings_matrix import (
all_ports_all_boards, all_ports_all_boards,
) )
IGNORE = [ # Files that never influence board builds
"tools/ci_set_matrix.py", IGNORE_BOARD = {
".devcontainer",
"docs",
"tests",
"tools/ci_changes_per_commit.py",
"tools/ci_check_duplicate_usb_vid_pid.py", "tools/ci_check_duplicate_usb_vid_pid.py",
] "tools/ci_set_matrix.py",
}
# Files in these directories never influence board builds
IGNORE_DIRS = ["tests", "docs", ".devcontainer"]
PATTERN_DOCS = ( PATTERN_DOCS = (
r"^(?:\.github|docs|extmod\/ulab)|" r"^(?:\.github|docs|extmod\/ulab)|"
@ -56,21 +58,20 @@ PATTERN_DOCS = (
r"(?:-stubs|\.(?:md|MD|rst|RST))$" r"(?:-stubs|\.(?:md|MD|rst|RST))$"
) )
PATTERN_WINDOWS = [ PATTERN_WINDOWS = {
".github/", ".github/",
"extmod/", "extmod/",
"lib/", "lib/",
"mpy-cross/", "mpy-cross/",
"ports/unix/", "ports/unix/",
"ports/windows/",
"py/", "py/",
"requirements",
"tools/", "tools/",
] "requirements-dev.txt",
}
def git_diff(pattern: str): def git_diff(pattern: str):
return ( return set(
subprocess.run( subprocess.run(
f"git diff {pattern} --name-only", f"git diff {pattern} --name-only",
capture_output=True, capture_output=True,
@ -83,15 +84,15 @@ def git_diff(pattern: str):
if len(sys.argv) > 1: if len(sys.argv) > 1:
print("Using files list on commandline") print("Using files list on commandline")
changed_files = sys.argv[1:] changed_files = set(sys.argv[1:])
elif os.environ.get("BASE_SHA") and os.environ.get("HEAD_SHA"): elif os.environ.get("BASE_SHA") and os.environ.get("HEAD_SHA"):
print("Using files list by computing diff") print("Using files list by computing diff")
changed_files = git_diff("$BASE_SHA...$HEAD_SHA") changed_files = git_diff("$BASE_SHA...$HEAD_SHA")
if os.environ.get("GITHUB_EVENT_NAME") == "pull_request": if os.environ.get("GITHUB_EVENT_NAME") == "pull_request":
changed_files = list(set(changed_files).intersection(git_diff("$HEAD_SHA~...$HEAD_SHA"))) changed_files.intersection_update(git_diff("$HEAD_SHA~...$HEAD_SHA"))
else: else:
print("Using files list in CHANGED_FILES") print("Using files list in CHANGED_FILES")
changed_files = json.loads(os.environ.get("CHANGED_FILES") or "[]") changed_files = set(json.loads(os.environ.get("CHANGED_FILES") or "[]"))
print("Using jobs list in LAST_FAILED_JOBS") print("Using jobs list in LAST_FAILED_JOBS")
last_failed_jobs = json.loads(os.environ.get("LAST_FAILED_JOBS") or "{}") last_failed_jobs = json.loads(os.environ.get("LAST_FAILED_JOBS") or "{}")
@ -103,8 +104,8 @@ def print_enclosed(title, content):
print("::endgroup::") print("::endgroup::")
print_enclosed("LOG: changed_files", changed_files) print_enclosed("Log: changed_files", changed_files)
print_enclosed("LOG: last_failed_jobs", last_failed_jobs) print_enclosed("Log: last_failed_jobs", last_failed_jobs)
def set_output(name: str, value): def set_output(name: str, value):
@ -173,11 +174,7 @@ def set_boards(build_all: bool):
boards_to_build.update(port_to_boards[port]) boards_to_build.update(port_to_boards[port])
continue continue
# Check the ignore list to see if the file isn't used on board builds. if any([p.startswith(d) for d in IGNORE_BOARD]):
if p in IGNORE:
continue
if any([p.startswith(d) for d in IGNORE_DIRS]):
continue continue
# As a (nearly) last resort, for some certain files, we compute the settings from the # 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):
else: else:
for file in changed_files: for file in changed_files:
for pattern in PATTERN_WINDOWS: for pattern in PATTERN_WINDOWS:
if file.startswith(pattern): if file.startswith(pattern) and not any(
[file.startswith(d) for d in IGNORE_BOARD]
):
build_windows = True build_windows = True
break break
else: else:
@ -302,11 +301,7 @@ def set_windows(build_windows: bool):
def main(): def main():
# Build all if no changed files # Build all if no changed files
build_all = not changed_files build_all = not changed_files
print( print("Running: " + ("all" if build_all else "conditionally"))
"Building all docs/boards"
if build_all
else "Adding docs/boards to build based on changed files"
)
# Set jobs # Set jobs
set_docs(build_all) set_docs(build_all)