mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-29 09:10:58 +01:00
Component edits ran all backend race and benchmark shards even when the Go inputs were unchanged. Keep the frontend, embed and script checks, and run the Go suites that read components or browser evidence. Mixed changes and main pushes retain their existing coverage.
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
"""Select component PRs using the entire base-to-tested-tree diff."""
|
|
|
|
import argparse
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
from ci_browser_proof_only import COMMIT, RECEIPT
|
|
|
|
|
|
SOURCE_DIR = rb"frontend-modern/src/(?:components|features)/(?:[A-Za-z0-9_-]+/)*"
|
|
COMPONENT = re.compile(SOURCE_DIR + rb"[A-Z][A-Za-z0-9]*\.tsx")
|
|
TEST = re.compile(SOURCE_DIR + rb"[A-Za-z0-9_.-]+\.(?:test|spec)\.tsx?")
|
|
# Include both sides of every change. A symlink, submodule, executable or
|
|
# type change at a component-looking path is outside this contract.
|
|
REGULAR_CHANGE = re.compile(
|
|
rb":(?:100644 100644 [a-f0-9]+ [a-f0-9]+ M|"
|
|
rb"000000 100644 [a-f0-9]+ [a-f0-9]+ A|"
|
|
rb"100644 000000 [a-f0-9]+ [a-f0-9]+ D)"
|
|
)
|
|
|
|
|
|
def component_only_diff(base, head):
|
|
if not COMMIT.fullmatch(base) or not COMMIT.fullmatch(head):
|
|
return False
|
|
try:
|
|
raw = subprocess.check_output(
|
|
["git", "diff", "--raw", "--no-ext-diff", "--no-renames", "-z", base, head, "--"],
|
|
timeout=30,
|
|
)
|
|
except (OSError, subprocess.SubprocessError) as error:
|
|
print(f"Component diff unavailable: {error}", file=sys.stderr)
|
|
return False
|
|
records = raw.split(b"\0")
|
|
if records.pop() != b"" or len(records) % 2:
|
|
return False
|
|
has_component = False
|
|
for header, path in zip(records[::2], records[1::2]):
|
|
if not REGULAR_CHANGE.fullmatch(header):
|
|
return False
|
|
if COMPONENT.fullmatch(path) and b"/__tests__/" not in path:
|
|
has_component = True
|
|
elif not (TEST.fullmatch(path) or RECEIPT.fullmatch(path)):
|
|
return False
|
|
return has_component
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--base", required=True)
|
|
parser.add_argument("--head", required=True)
|
|
args = parser.parse_args()
|
|
print("true" if component_only_diff(args.base, args.head) else "false")
|