ci(molecule): run only the image-smoke scenario a pull request changes
Build / build (pull_request) Successful in 20s
Lint / lint (pull_request) Successful in 1m6s
Molecule / molecule (pull_request) Successful in 1s

A file under extensions/molecule/<name>/ ran every scenario, although
only that image-smoke scenario reads it: they test the images, not the
roles. It now selects that scenario only. A shared file such as
extensions/molecule/requirements.yml, or a name that is not a scenario,
still runs everything.

Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
Defame1297 committed 2026-11-22 21:14:45 +00:00
1 parent b49c953e8d
commit 5c8b8f5342
2 files changed
+56 -11

No files matched your search

+28 -8
View File
@@ -13,6 +13,9 @@ Only a pull request is narrowed, and only when <base-ref> is given and EVENT_NAM
* a file under roles/<role>/ selects that role's scenarios, and those of every role that
uses it (below);
* a file under extensions/molecule/<name>/, when that is a scenario, selects that scenario
only (the image-smoke scenarios test the images, not the roles); a shared file such as
extensions/molecule/requirements.yml is "any other file";
* a file on the IGNORED list (documentation, changelog, repository tooling that no
scenario reads) selects nothing;
* any other file selects every scenario.
@@ -193,6 +196,7 @@ def select(all_scenarios, changed, root="."):
Raises ValueError when a changed role still exists but has no scenario.
"""
roles = set()
extensions = set()
for path in changed:
if is_ignored(path):
continue
@@ -200,13 +204,23 @@ def select(all_scenarios, changed, root="."):
if len(parts) > 2 and parts[0] == "roles":
roles.add(parts[1])
continue
scenario = "/".join(parts[:3])
if (
len(parts) > 3
and parts[:2] == ["extensions", "molecule"]
and scenario in all_scenarios
):
extensions.add(scenario)
continue
return list(all_scenarios), f"{printable(path)} can affect every scenario"
changed_roles = roles
roles = with_users(changed_roles, users(root, changed_roles))
chosen = [
s for s in all_scenarios if s.startswith("roles/") and s.split("/")[1] in roles
s
for s in all_scenarios
if s in extensions or (s.startswith("roles/") and s.split("/")[1] in roles)
]
covered = {s.split("/")[1] for s in chosen}
covered = {s.split("/")[1] for s in chosen if s.startswith("roles/")}
bare = sorted(
r for r in roles - covered if os.path.isdir(os.path.join(root, "roles", r))
)
@@ -215,16 +229,22 @@ def select(all_scenarios, changed, root="."):
"role without a molecule scenario (changed, or a user of a changed role): "
+ ", ".join(printable(r) for r in bare)
)
notes = []
if roles:
reason = "only roles changed: " + ", ".join(
printable(r) for r in sorted(changed_roles)
notes.append(
"roles changed: " + ", ".join(printable(r) for r in sorted(changed_roles))
)
if roles - changed_roles:
reason += "; their users: " + ", ".join(
printable(r) for r in sorted(roles - changed_roles)
notes.append(
"their users: "
+ ", ".join(printable(r) for r in sorted(roles - changed_roles))
)
else:
reason = "no change that a scenario reads"
if extensions:
notes.append(
"image-smoke scenarios changed: "
+ ", ".join(printable(e.split("/")[2]) for e in sorted(extensions))
)
reason = "; ".join(notes) or "no change that a scenario reads"
return chosen, reason