INNER CODE UNIT · Python

select_roles

spantaleev/matrix-docker-ansible-deploy · bin/molecule-select-roles.py:154

def select_roles(git, base, head="HEAD", role=""):
    # Failure to enumerate the head must fail the job, never report an empty gate.
    paths = git.run("ls-tree", "-rz", "--name-only", head, "--", "roles/custom").decode().split("\0")
    available = {match[1] for path in paths if (match := SCENARIO.fullmatch(path))}
    if role:
        if role not in available:
            raise ValueError(f"No scenario at roles/custom/{role}/molecule/default")
        return [role]
    if not base:
        print("No comparison requested or available; testing every scenario", file=sys.stderr)
        return sorted(available)

    try:
        # Disable rename detection so both old and new paths contribute consumers.
        diff = git.run("diff", "--no-renames", "--name-only", "-z", base, head, "--")
        changed = set(diff.decode().split("\0")) - {""}
        if changed & GLOBAL_FILES:
            raise Uncertain("Test infrastructure changed: " + ", ".join(sorted(changed & GLOBAL_FILES)))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…