Skip to content
Open
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
15 changes: 7 additions & 8 deletions cfbs/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,23 +293,22 @@ def _localize_file_inputs(name, input_data, destination, build_modules):
module_dir_name = name[2:] if name.startswith("./") else name
module_dir_name = os.path.basename(module_dir_name.rstrip("/"))

def _localize(path):
if not path or not os.path.isfile(path):
return path
def _localize(rel_path):
if not rel_path or not os.path.isfile(rel_path):
return rel_path

already_shipped = _path_if_already_shipped(path, build_modules, destination)
already_shipped = _path_if_already_shipped(rel_path, build_modules, destination)
if already_shipped is not None:
return already_shipped

dest = os.path.join(
destination,
"services",
"cfbs",
"modules",
module_dir_name,
os.path.basename(path),
"modules" if rel_path.startswith(module_dir_name) else "",
rel_path,
)
cp(path, dest)
cp(rel_path, dest)
return "$(sys.inputdir)/" + os.path.relpath(dest, destination)

for element in input_data:
Expand Down
7 changes: 4 additions & 3 deletions cfbs/cfbs_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,13 @@ def _one_file():
if "while" not in input_data:
return _one_file()

result = [_one_file()]
result = {_one_file()}

while prompt_user_yesno(
self.non_interactive, input_data["while"], default="no"
):
result.append(_one_file())
return result
result.add(_one_file())
return list(result)

def _input_elements(subtype):
result = OrderedDict()
Expand Down
31 changes: 17 additions & 14 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,50 @@ def test_localize_file_inputs_copies_single_file(tmp_path, monkeypatch):

_localize_file_inputs("run-a-script", input_data, "out/masterfiles", [])

expected_dest = "out/masterfiles/services/cfbs/modules/run-a-script/deploy.sh"
expected_dest = "out/masterfiles/services/cfbs/deploy.sh"
assert os.path.isfile(expected_dest)
assert (
input_data[0]["response"]
== "$(sys.inputdir)/services/cfbs/modules/run-a-script/deploy.sh"
)
assert input_data[0]["response"] == "$(sys.inputdir)/services/cfbs/deploy.sh"


def test_localize_file_inputs_copies_list_of_files(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
os.makedirs("out/masterfiles")
os.makedirs("run-scripts-module")
with open("one.sh", "w") as f:
f.write("echo one\n")
with open("two.sh", "w") as f:
with open("run-scripts-module/two.sh", "w") as f:
f.write("echo two\n")

input_data = [
{
"type": "file",
"variable": "scripts",
"response": ["one.sh", "two.sh"],
"response": ["one.sh", "run-scripts-module/two.sh"],
}
]

_localize_file_inputs("run-scripts", input_data, "out/masterfiles", [])

assert input_data[0]["response"] == [
"$(sys.inputdir)/services/cfbs/modules/run-scripts/one.sh",
"$(sys.inputdir)/services/cfbs/modules/run-scripts/two.sh",
"$(sys.inputdir)/services/cfbs/one.sh",
"$(sys.inputdir)/services/cfbs/modules/run-scripts-module/two.sh",
]
assert os.path.isfile("out/masterfiles/services/cfbs/modules/run-scripts/one.sh")
assert os.path.isfile("out/masterfiles/services/cfbs/modules/run-scripts/two.sh")
assert os.path.isfile("out/masterfiles/services/cfbs/one.sh")
assert os.path.isfile(
"out/masterfiles/services/cfbs/modules/run-scripts-module/two.sh"
)


def test_localize_file_inputs_strips_local_module_prefix(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
os.makedirs("out/masterfiles")
with open("deploy.sh", "w") as f:
os.makedirs("run-a-script")
with open("run-a-script/deploy.sh", "w") as f:
f.write("echo hi\n")

input_data = [{"type": "file", "variable": "script", "response": "deploy.sh"}]
input_data = [
{"type": "file", "variable": "script", "response": "run-a-script/deploy.sh"}
]

_localize_file_inputs("./run-a-script", input_data, "out/masterfiles", [])

Expand Down Expand Up @@ -152,7 +155,7 @@ def test_localize_file_inputs_ignores_non_directory_steps(tmp_path, monkeypatch)
}
]
input_data = [
{"type": "file", "variable": "script", "response": "./run-scripts/deploy.sh"}
{"type": "file", "variable": "script", "response": "run-scripts/deploy.sh"}
]

_localize_file_inputs("run-scripts", input_data, "out/masterfiles", build_modules)
Expand Down
Loading