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