From 858222e2417de1194fb8c5d7c6de9c14d9f164a5 Mon Sep 17 00:00:00 2001 From: Franco Meloni Date: Sun, 10 Feb 2019 17:17:24 +0000 Subject: [PATCH] Fix variables export on scripts --- Sources/RocketLib/Executors/ScriptLauncher.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Sources/RocketLib/Executors/ScriptLauncher.swift b/Sources/RocketLib/Executors/ScriptLauncher.swift index 65974d6..022ea48 100644 --- a/Sources/RocketLib/Executors/ScriptLauncher.swift +++ b/Sources/RocketLib/Executors/ScriptLauncher.swift @@ -13,19 +13,20 @@ protocol ScriptLaunching { struct ScriptLauncher: ScriptLaunching { func launchScript(withContent content: String, version: String?) throws -> String { - var contents: [String] = [] + var runnableContent: String if let version = version { - contents.append("export VERSION=\(version)") + runnableContent = "export VERSION=\(version) && \(content)" + } else { + runnableContent = content } - contents.append(content) + let output = run(bash: runnableContent) - let outputs = contents.map { run(bash: $0) } - if let errorString = outputs.lazy.filter({ $0.exitcode != 0 }).map({ $0.stderror }).first { - throw ScriptLauncherError(errorString: errorString) + if output.exitcode != 0 { + throw ScriptLauncherError(errorString: output.stdout) } else { - return outputs.last?.stdout ?? "" + return output.stdout } } }