ci(molecule): run only the image-smoke scenario a pull request changes #301
No files matched your search
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -208,7 +208,8 @@ class SelectTest(unittest.TestCase):
|
||||
"galaxy.yml",
|
||||
"meta/runtime.yml",
|
||||
"plugins/modules/x.py",
|
||||
"extensions/molecule/image-smoke/molecule.yml",
|
||||
"extensions/molecule/requirements.yml",
|
||||
"extensions/molecule/gone/molecule.yml",
|
||||
".gitea/workflows/molecule.yml",
|
||||
"tests/unit/x.py",
|
||||
"new_top_level_file",
|
||||
@@ -217,6 +218,25 @@ class SelectTest(unittest.TestCase):
|
||||
chosen, _reason = self.select(["roles/docker/tasks/main.yml", path])
|
||||
self.assertEqual(chosen, ALL, path)
|
||||
|
||||
def test_image_smoke_change_selects_only_that_scenario(self):
|
||||
chosen, reason = self.select(
|
||||
["extensions/molecule/image-smoke-2604/verify.yml"]
|
||||
)
|
||||
self.assertEqual(chosen, ["extensions/molecule/image-smoke-2604"])
|
||||
self.assertIn("image-smoke-2604", reason)
|
||||
|
||||
def test_image_smoke_and_role_changes_combine(self):
|
||||
chosen, _reason = self.select(
|
||||
[
|
||||
"extensions/molecule/image-smoke/converge.yml",
|
||||
"roles/docker/tasks/main.yml",
|
||||
]
|
||||
)
|
||||
self.assertEqual(
|
||||
chosen,
|
||||
["extensions/molecule/image-smoke", "roles/docker/molecule/default"],
|
||||
)
|
||||
|
||||
def test_deleted_role_selects_nothing_of_its_own(self):
|
||||
chosen, _reason = self.select(["roles/gone/tasks/main.yml"])
|
||||
self.assertEqual(chosen, [])
|
||||
@@ -495,7 +515,7 @@ class MainTest(unittest.TestCase):
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
||||
def test_every_tracked_file_is_ignored_or_selects_everything_or_is_a_role_file(
|
||||
def test_every_tracked_file_is_ignored_or_selects_everything_or_its_own_scenario(
|
||||
self,
|
||||
):
|
||||
tracked = subprocess.run(
|
||||
@@ -512,7 +532,12 @@ class MainTest(unittest.TestCase):
|
||||
if sel.is_ignored(path) or path.startswith("roles/"):
|
||||
continue
|
||||
chosen, _reason = sel.select(scenarios, [path], str(REPO))
|
||||
self.assertEqual(chosen, scenarios, path)
|
||||
own = "/".join(path.split("/")[:3])
|
||||
if path.startswith("extensions/molecule/") and own in scenarios:
|
||||
# A file of one image-smoke scenario selects that scenario only.
|
||||
self.assertEqual(chosen, [own], path)
|
||||
else:
|
||||
self.assertEqual(chosen, scenarios, path)
|
||||
|
||||
def test_roles_call_each_other_by_full_name_only(self):
|
||||
# The selection finds a role's users by the text mortis.kamino.<role> (users()). A use
|
||||
|
||||
Reference in new issue
Block a user