lib/evrone/ci/worker/middlewares/local_script.rb in evrone-ci-worker-0.2.0.pre0 vs lib/evrone/ci/worker/middlewares/local_script.rb in evrone-ci-worker-0.2.0.pre1

- old
+ new

@@ -7,20 +7,44 @@ LocalScript = Struct.new(:app) do include Common::Helper::Shell def call(env) - script = env.work_dir.join(".ci_script.sh") - write_file script, env.job.message.script, 0700 + script = env.tmp_dir.join("build.sh") + write_file script, content(env), 0700 code = bash file: script, chdir: env.work_dir, &env.job.method(:add_to_output) if code == 0 app.call env else - code + state = read_state(env) + case state + when "script" + code + else + code * -1 + end end end + + private + + def content(env) + buf = ["set -e"] + buf << "echo before_script > #{env.tmp_dir}/state" + buf << env.job.message.before_script + buf << "echo script > #{env.tmp_dir}/state" + buf << env.job.message.script + buf.join("\n") + end + + def read_state(env) + state_file = env.tmp_dir.join("state") + if File.readable? state_file + File.read(state_file).strip + end + end end end end end