feat: add incoming ref data to non-flakes entrypoint
We can now implement a Nix library for Buildbot CI. :) Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
parent
b3a0b5a69e
commit
dadd3bf10d
|
@ -453,13 +453,21 @@ class NixEvalCommand(buildstep.ShellMixin, steps.BuildStep):
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def make_job_evaluator(name: str, settings: EvaluatorSettings, flake: bool) -> NixEvalCommand:
|
def make_job_evaluator(name: str, settings: EvaluatorSettings, flake: bool, incoming_ref_data: dict[str, Any]) -> NixEvalCommand:
|
||||||
actual_command = []
|
actual_command = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
eval_parameter_json_repr = json.dumps(incoming_ref_data)
|
||||||
|
except ValueError as e:
|
||||||
|
msg = f"Failed to serialize incoming ref data for {name}"
|
||||||
|
raise BuildbotNixError(msg) from e
|
||||||
|
|
||||||
if flake:
|
if flake:
|
||||||
actual_command += ["--flake", f".#{FLAKE_TARGET_ATTRIBUTE_FOR_JOBS}"]
|
actual_command += ["--flake", f".#{FLAKE_TARGET_ATTRIBUTE_FOR_JOBS}"]
|
||||||
else:
|
else:
|
||||||
actual_command += ["--expr", "import ./.ci/buildbot.nix"]
|
# TODO: escape for Nix the JSON…
|
||||||
|
actual_command += ["--expr",
|
||||||
|
f"import ./.ci/buildbot.nix {{ incoming_ref_data = ''{eval_parameter_json_repr}''; }}"]
|
||||||
|
|
||||||
return NixEvalCommand(
|
return NixEvalCommand(
|
||||||
env={},
|
env={},
|
||||||
|
@ -504,6 +512,14 @@ class NixConfigure(buildstep.CommandMixin, steps.BuildStep):
|
||||||
except Exception:
|
except Exception:
|
||||||
configure_log: Log = yield self.addLog("stdio")
|
configure_log: Log = yield self.addLog("stdio")
|
||||||
|
|
||||||
|
# This information can be passed at job evaluation time
|
||||||
|
# to skip some jobs, e.g. expensive jobs, etc.
|
||||||
|
incoming_ref_data = {
|
||||||
|
# TODO: please just denormalize it properly.
|
||||||
|
'event': {
|
||||||
|
key: value for key, (value, _) in self.getProperties().asDict() if key.startswith('event.')
|
||||||
|
}
|
||||||
|
}
|
||||||
# Takes precedence.
|
# Takes precedence.
|
||||||
configure_log.addStdout("checking if there's a .ci/buildbot.nix...\n")
|
configure_log.addStdout("checking if there's a .ci/buildbot.nix...\n")
|
||||||
ci_buildbot_defn_exists = yield self.pathExists('build/.ci/buildbot.nix')
|
ci_buildbot_defn_exists = yield self.pathExists('build/.ci/buildbot.nix')
|
||||||
|
@ -514,7 +530,8 @@ class NixConfigure(buildstep.CommandMixin, steps.BuildStep):
|
||||||
make_job_evaluator(
|
make_job_evaluator(
|
||||||
"evaluate `.ci/buildbot.nix` jobs",
|
"evaluate `.ci/buildbot.nix` jobs",
|
||||||
self.evaluator_settings,
|
self.evaluator_settings,
|
||||||
False
|
False,
|
||||||
|
incoming_ref_data
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -527,7 +544,8 @@ class NixConfigure(buildstep.CommandMixin, steps.BuildStep):
|
||||||
make_job_evaluator(
|
make_job_evaluator(
|
||||||
"evaluate `flake.nix` jobs",
|
"evaluate `flake.nix` jobs",
|
||||||
self.evaluator_settings,
|
self.evaluator_settings,
|
||||||
True
|
True,
|
||||||
|
incoming_ref_data
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue