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 {
func launchScript(withContent content: String, version: String?) throws -> String {
var contents: [String] = []
var runnableContent: String
if let version = version {
contents.append("export VERSION=\(version)")
}
contents.append(content)
let outputs = contents.map { run(bash: $0) }
if let errorString = outputs.lazy.filter({ $0.exitcode != 0 }).map({ $0.stderror }).first {
throw ScriptLauncherError(errorString: errorString)
runnableContent = "export VERSION=\(version) && \(content)"
} else {
return outputs.last?.stdout ?? ""
runnableContent = content
}
let output = run(bash: runnableContent)
if output.exitcode != 0 {
throw ScriptLauncherError(errorString: output.stdout)
} else {
return output.stdout
}
}
}