diff --git a/scripts/src/hwlab-node/source-workspace.ts b/scripts/src/hwlab-node/source-workspace.ts index c03b09b7..cc876bc4 100644 --- a/scripts/src/hwlab-node/source-workspace.ts +++ b/scripts/src/hwlab-node/source-workspace.ts @@ -363,7 +363,7 @@ function sourceWorkspaceStatusFromFields(fields: Record, exitCod } function sourceWorkspaceHostDependenciesStatusScript(hostDependencies: HwlabRuntimeSourceWorkspaceHostDependenciesSpec): string { - const checkCommands = hostDependencies.checkCommands.join("\n"); + const checkCommands = shellLinesText(hostDependencies.checkCommands); return [ "set +e", `state_dir=${shellQuote(hostDependencies.stateDir)}`, @@ -403,7 +403,7 @@ function sourceWorkspaceHostDependenciesSubmitScript( sourceWorkspace: HwlabRuntimeSourceWorkspaceSpec, hostDependencies: HwlabRuntimeSourceWorkspaceHostDependenciesSpec, ): string { - const checkCommands = hostDependencies.checkCommands.join("\n"); + const checkCommands = shellLinesText(hostDependencies.checkCommands); const noProxy = spec.networkProfile.proxy.noProxy.join(","); const commandSha = createHash("sha256").update(hostDependencies.install.command).digest("hex"); const requiredCommandsSha = createHash("sha256").update(sourceWorkspace.requiredCommands.join("\n")).digest("hex"); @@ -473,9 +473,9 @@ function sourceWorkspaceHostDependenciesSubmitScript( } function sourceWorkspaceStatusScript(spec: HwlabRuntimeLaneSpec, sourceWorkspace: HwlabRuntimeSourceWorkspaceSpec): string { - const requiredCommands = sourceWorkspace.requiredCommands.join("\n"); - const requiredFiles = sourceWorkspace.requiredFiles.join("\n"); - const remoteUrls = [spec.gitUrl, spec.gitReadUrl, spec.gitWriteUrl].join("\n"); + const requiredCommands = shellLinesText(sourceWorkspace.requiredCommands); + const requiredFiles = shellLinesText(sourceWorkspace.requiredFiles); + const remoteUrls = shellLinesText([spec.gitUrl, spec.gitReadUrl, spec.gitWriteUrl]); return [ "set +e", `workspace=${shellQuote(spec.workspace)}`, @@ -746,8 +746,8 @@ function sourceWorkspaceJobContainerScript( controlPlane: ReturnType, workspaceInContainer: string, ): string { - const requiredCommands = sourceWorkspace.requiredCommands.join("\n"); - const requiredFiles = sourceWorkspace.requiredFiles.join("\n"); + const requiredCommands = shellLinesText(sourceWorkspace.requiredCommands); + const requiredFiles = shellLinesText(sourceWorkspace.requiredFiles); return [ "set -eu", `workspace=${shellQuote(workspaceInContainer)}`, @@ -813,6 +813,10 @@ function sourceWorkspaceJobContainerScript( ].join("\n"); } +function shellLinesText(values: readonly string[]): string { + return values.length === 0 ? "" : `${values.join("\n")}\n`; +} + function sourceWorkspaceJobName(spec: HwlabRuntimeLaneSpec): string { return `hwlab-${spec.nodeId.toLowerCase()}-${spec.lane}-source-workspace`.slice(0, 63).replace(/-$/u, ""); }