Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/cijoe/core/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,18 @@ def dict_normalize(topic: dict):
)
return errors

step["with"]["commands"] = step["run"].splitlines()
# non-empty lines in "run"
lines: filter[str] = filter(
None, map(lambda s: s.strip(), step["run"].splitlines())
)
step["with"]["commands"] = []
buffer = []

for line in lines:
buffer.append(line)
if not line.strip().endswith("\\"):
step["with"]["commands"].append("\n".join(buffer))
buffer = []

del step["run"]

Expand Down
81 changes: 81 additions & 0 deletions tests/core/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,84 @@ def test_workflow_report_command_ordering(tmp_path):
):
val = int(Path(key).stem.split("_")[1])
assert count == val


def test_workflow_run(tmp_path):
config_path = (tmp_path / "test-config-empty.toml").resolve()
config_path.write_text("")

data = copy.deepcopy(WORKFLOW_SKELETON)
data["steps"].append(
{
"name": "cmdrunner",
"run": """
echo hello
echo world
""",
}
)

output_path = (tmp_path / "output").resolve()
workflow_file = (tmp_path / "workflow.yaml").resolve()
workflow_file.write_text(yaml.dump(data))

result = subprocess.run(
[
"cijoe",
str(workflow_file),
"--output",
str(output_path),
"--config",
str(config_path),
],
cwd=str(tmp_path),
)
assert result.returncode == 0

runlog = runlog_from_path(output_path / "002_cmdrunner")

assert len(runlog) == 2

for i, v in enumerate(runlog.values()):
if i == 0:
assert "hello" in v["output"]
elif i == 1:
assert "world" in v["output"]


def test_workflow_run_multiline(tmp_path):
config_path = (tmp_path / "test-config-empty.toml").resolve()
config_path.write_text("")

data = copy.deepcopy(WORKFLOW_SKELETON)
data["steps"].append(
{
"name": "cmdrunner",
"run": """
echo hello \
world
""",
}
)

output_path = (tmp_path / "output").resolve()
workflow_file = (tmp_path / "workflow.yaml").resolve()
workflow_file.write_text(yaml.dump(data))

result = subprocess.run(
[
"cijoe",
str(workflow_file),
"--output",
str(output_path),
"--config",
str(config_path),
],
cwd=str(tmp_path),
)
assert result.returncode == 0

runlog = runlog_from_path(output_path / "002_cmdrunner")

assert len(runlog) == 1
assert "hello world" in runlog["cmd_01"]["output"]
Loading