Sha256: af943c08364def89e6335603c8f807766a7b8bd2675ace475f322699d6f547f3

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'evrone/ci/common'

module Evrone
  module CI
    module Worker

      LocalScript = Struct.new(:app) do

        include Common::Helper::Shell

        def call(env)
          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
            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


Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
evrone-ci-worker-0.2.0.pre4 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre3 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre1 lib/evrone/ci/worker/middlewares/local_script.rb