Sha256: db4ea8d178ffd5b32cd4e535563fa4e2b5073ff14bf58264a472c69aaf9a97ec

Contents?: true

Size: 1.12 KB

Versions: 22

Compression:

Stored size: 1.12 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, &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

22 entries across 22 versions & 1 rubygems

Version Path
evrone-ci-worker-0.2.0.pre27 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre26 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre25 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre24 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre23 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre22 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre21 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre20 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre19 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre18 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre17 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre15 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre14 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre13 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre12 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre11 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre10 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre9 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre8 lib/evrone/ci/worker/middlewares/local_script.rb
evrone-ci-worker-0.2.0.pre7 lib/evrone/ci/worker/middlewares/local_script.rb