Fix variables export on scripts
This commit is contained in:
parent
639370fbb6
commit
858222e241
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue