Fix variables export on scripts

This commit is contained in:
Franco Meloni 2019-02-10 17:17:24 +00:00
parent 639370fbb6
commit 858222e241
1 changed files with 8 additions and 7 deletions

View File

@ -13,19 +13,20 @@ protocol ScriptLaunching {
struct ScriptLauncher: ScriptLaunching { struct ScriptLauncher: ScriptLaunching {
func launchScript(withContent content: String, version: String?) throws -> String { func launchScript(withContent content: String, version: String?) throws -> String {
var contents: [String] = [] var runnableContent: String
if let version = version { 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 output.exitcode != 0 {
if let errorString = outputs.lazy.filter({ $0.exitcode != 0 }).map({ $0.stderror }).first { throw ScriptLauncherError(errorString: output.stdout)
throw ScriptLauncherError(errorString: errorString)
} else { } else {
return outputs.last?.stdout ?? "" return output.stdout
} }
} }
} }