only compute final_script and validation hashes once
This commit is contained in:
@@ -172,7 +172,7 @@ class StoreBase(ABC):
|
|||||||
-> this provides backward and forward compatibility
|
-> this provides backward and forward compatibility
|
||||||
"""
|
"""
|
||||||
stored_hash = self.get_validation(generator)
|
stored_hash = self.get_validation(generator)
|
||||||
target_hash = generator.validation
|
target_hash = generator.validation()
|
||||||
# if the hash is neither set in nix nor on disk, it is considered valid (provides backwards compat)
|
# if the hash is neither set in nix nor on disk, it is considered valid (provides backwards compat)
|
||||||
if target_hash is None and stored_hash is None:
|
if target_hash is None and stored_hash is None:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ class Generator:
|
|||||||
prompts=[Prompt.from_json(p) for p in data["prompts"].values()],
|
prompts=[Prompt.from_json(p) for p in data["prompts"].values()],
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def final_script(self) -> Path:
|
def final_script(self) -> Path:
|
||||||
assert self._machine is not None
|
assert self._machine is not None
|
||||||
final_script = self._machine.build_nix(
|
final_script = self._machine.build_nix(
|
||||||
@@ -74,7 +73,6 @@ class Generator:
|
|||||||
)
|
)
|
||||||
return final_script
|
return final_script
|
||||||
|
|
||||||
@property
|
|
||||||
def validation(self) -> str | None:
|
def validation(self) -> str | None:
|
||||||
assert self._machine is not None
|
assert self._machine is not None
|
||||||
return self._machine.eval_nix(
|
return self._machine.eval_nix(
|
||||||
@@ -208,10 +206,12 @@ def execute_generator(
|
|||||||
prompt_file.write_text(value)
|
prompt_file.write_text(value)
|
||||||
from clan_cli import bwrap
|
from clan_cli import bwrap
|
||||||
|
|
||||||
|
final_script = generator.final_script()
|
||||||
|
|
||||||
if sys.platform == "linux" and bwrap.bubblewrap_works():
|
if sys.platform == "linux" and bwrap.bubblewrap_works():
|
||||||
cmd = bubblewrap_cmd(str(generator.final_script), tmpdir)
|
cmd = bubblewrap_cmd(str(final_script), tmpdir)
|
||||||
else:
|
else:
|
||||||
cmd = ["bash", "-c", str(generator.final_script)]
|
cmd = ["bash", "-c", str(final_script)]
|
||||||
run(cmd, RunOpts(env=env))
|
run(cmd, RunOpts(env=env))
|
||||||
files_to_commit = []
|
files_to_commit = []
|
||||||
# store secrets
|
# store secrets
|
||||||
@@ -222,7 +222,7 @@ def execute_generator(
|
|||||||
secret_file = tmpdir_out / file.name
|
secret_file = tmpdir_out / file.name
|
||||||
if not secret_file.is_file():
|
if not secret_file.is_file():
|
||||||
msg = f"did not generate a file for '{file.name}' when running the following command:\n"
|
msg = f"did not generate a file for '{file.name}' when running the following command:\n"
|
||||||
msg += str(generator.final_script)
|
msg += str(final_script)
|
||||||
raise ClanError(msg)
|
raise ClanError(msg)
|
||||||
if file.secret:
|
if file.secret:
|
||||||
file_path = secret_vars_store.set(
|
file_path = secret_vars_store.set(
|
||||||
@@ -240,18 +240,15 @@ def execute_generator(
|
|||||||
public_changed = True
|
public_changed = True
|
||||||
if file_path:
|
if file_path:
|
||||||
files_to_commit.append(file_path)
|
files_to_commit.append(file_path)
|
||||||
if generator.validation is not None:
|
validation = generator.validation()
|
||||||
|
if validation is not None:
|
||||||
if public_changed:
|
if public_changed:
|
||||||
files_to_commit.append(
|
files_to_commit.append(
|
||||||
public_vars_store.set_validation(
|
public_vars_store.set_validation(generator, validation)
|
||||||
generator, generator.validation
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
if secret_changed:
|
if secret_changed:
|
||||||
files_to_commit.append(
|
files_to_commit.append(
|
||||||
secret_vars_store.set_validation(
|
secret_vars_store.set_validation(generator, validation)
|
||||||
generator, generator.validation
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
commit_files(
|
commit_files(
|
||||||
files_to_commit,
|
files_to_commit,
|
||||||
|
|||||||
Reference in New Issue
Block a user