ci(molecule): fail the run when a scenario has molecule's prerun on
Build / build (pull_request) Successful in 37s
Lint / lint (pull_request) Successful in 5m15s
Molecule / molecule (pull_request) Successful in 36m0s

check_scenarios_load_checkout.py now merges the base config the way
molecule's CLI does (its own lookup of .config/molecule/config.yml) and
fails a scenario whose merged prerun is not false, naming the base
config. Before, it built Config with no base config, so a scenario that
turned prerun back on, or a moved base config, slowed every run and
nothing failed.

Closes #452

Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-11-29 16:56:29 +00:00
1 parent 0173f6f226
commit 49afd900dc
4 files changed
+59 -12

No files matched your search

+25 -8
View File
@@ -5,8 +5,10 @@
python3 -I scripts/check_scenarios_load_checkout.py < scenario-dirs
Checks the environment molecule hands ansible-playbook, not only the inherited one: a scenario's
own env can change it. The rule it holds is in .gitea/workflows/AGENTS.md (Molecule). Exit 1 when
a scenario would load another copy, or none.
own env can change it. Also checks that molecule's prerun, its install of the collection, is off
once the base config is merged as molecule's CLI merges it. The rule it holds is in
.gitea/workflows/AGENTS.md (Molecule). Exit 1 when a scenario would load another copy, or none,
or has prerun on.
"""
import json
@@ -16,6 +18,8 @@ import sys
import tempfile
from molecule.config import Config
from molecule.shell import LOCAL_CONFIG_SEARCH
from molecule.util import lookup_config_file
CHECKOUT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
RULE = (
@@ -23,20 +27,25 @@ RULE = (
" copy: the scenario selector ignores galaxy.yml on that rule"
" (.gitea/workflows/AGENTS.md, Molecule)"
)
PRERUN = (
"prerun must be off, so molecule does not install mortis.kamino again: set `prerun: false`"
" in the base config {base} and do not turn it on in the scenario (.gitea/workflows/AGENTS.md, Molecule)"
)
def playbook_env(scenario):
"""The environment molecule gives ansible-playbook in `scenario`, as a role scenario runs it."""
def scenario_config(scenario):
"""Molecule's config of `scenario` as `molecule converge` builds it there, and its base config."""
parts = scenario.split("/")
cwd = os.path.join(CHECKOUT, *parts[:2]) if parts[0] == "roles" else CHECKOUT
# molecule takes the project from the working directory; each call sets it afresh
# molecule takes the project and the base config from the working directory; set it afresh
os.chdir(cwd)
base = lookup_config_file(LOCAL_CONFIG_SEARCH)
config = Config(
os.path.relpath(os.path.join(CHECKOUT, scenario, "molecule.yml")),
args={},
args={"base_config": [base] if base else []},
command_args={"subcommand": "converge"},
)
return dict(config.provisioner.env)
return config, base
def collection_paths(env, cwd):
@@ -79,8 +88,16 @@ def main():
os.environ.setdefault("ANSIBLE_HOME", home)
for scenario in filter(None, sys.stdin.read().splitlines()):
scenario_dir = os.path.join(CHECKOUT, scenario)
config, base = scenario_config(scenario)
# molecule's worker reads this key to decide whether to install the collection
if config.config_data["prerun"] is not False:
failed = True
base = (
base or os.path.join(CHECKOUT, LOCAL_CONFIG_SEARCH) + " (not found)"
)
print(f"::error::{scenario}: " + PRERUN.format(base=base))
paths = [os.path.join(scenario_dir, "collections")]
paths += collection_paths(playbook_env(scenario), scenario_dir)
paths += collection_paths(dict(config.provisioner.env), scenario_dir)
found = loaded_copy(paths)
if found and os.path.realpath(found) == CHECKOUT:
continue