evrone-ci-router 0.2.0.pre4 → 0.2.0.pre5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f07b623520997770118ec0c990da47e9307969f
4
- data.tar.gz: 3bd64424754d66dffb5f17e7340ddc632d003c33
3
+ metadata.gz: 8eaca86f6f37eb7af8d1e7817f99b833f5693d5c
4
+ data.tar.gz: a161f3bb1eb84f7e35647b5508e008528ca489cc
5
5
  SHA512:
6
- metadata.gz: ffefbb4db637a63ac918df5aa001988f677d38a60c9af4d6735bbf23ec025150353ece55b2803be93e2e11830e7969580aa98653b1567bddd8f7d7d2953c11b1
7
- data.tar.gz: 843ee07a50d637b045f38bcdf08621ab5dfc08991844e6fc6e5f3013a5e73e77c529e011af3b232b427790f6e089e674d821018c245cbc817ac04418c9c70d63
6
+ metadata.gz: 4512bb8e7d369c43a232945bcba2e1315f31aa53d5edda9acc27d87514e59d61710988e72243ce7f0114930a03f8e0527c84dc3d85b33334bd98fea39460822a
7
+ data.tar.gz: 206febdaae5c7ca4b9bf9300e0010c15edb6ce69f7d7a5ddf1ce67eae19d67d0e35ddc2962d0827c6500a3870cbc46248359245f7aebedfec75a560ac0799bbd
data/Rakefile CHANGED
@@ -23,3 +23,24 @@ end
23
23
 
24
24
  desc "run travis build"
25
25
  task :travis => :default
26
+
27
+ namespace :print do
28
+ task :script do
29
+ require 'evrone/ci/message/testing'
30
+ require File.expand_path("../spec/support/fixture", __FILE__)
31
+ require File.expand_path("../spec/support/create", __FILE__)
32
+
33
+ build = create :build
34
+ travis = create :travis
35
+
36
+ script_builder = travis.to_script_builder(build)
37
+
38
+ puts "\n#===> BEGIN BEFORE SCRIPT"
39
+ puts script_builder.to_before_script
40
+ puts "#===> END BEFORE SCRIPT\n"
41
+
42
+ puts "\n#===> BEGIN SCRIPT\n"
43
+ puts script_builder.to_script
44
+ puts "#===> END SCRIPT\n\n"
45
+ end
46
+ end
@@ -14,26 +14,27 @@ module Evrone
14
14
  include Router::Helper::Config
15
15
 
16
16
  attr_reader :message, :output, :output_counter
17
- attr_accessor :jobs_count, :commit_info
17
+ attr_accessor :jobs_count
18
18
 
19
19
  def initialize(perform_build_message)
20
20
  @output_counter = 0
21
- @output = ''
21
+ @output = Common::OutputBuffer.new(&method(:publish_build_log_message))
22
22
  @message = perform_build_message
23
23
  end
24
24
 
25
+ def release
26
+ output.close
27
+ end
28
+
25
29
  def to_perform_job_message(travis, job_id)
26
- script_builder = travis.to_script_builder
27
- sha = (commit_info && commit_info.sha) || message.sha
30
+ script_builder = travis.to_script_builder(self)
28
31
  job_message = Message::PerformJob.new(
29
32
  id: message.id,
30
33
  name: message.name,
31
- src: message.src,
32
- sha: sha,
33
- deploy_key: message.deploy_key,
34
34
  job_id: job_id,
35
35
  before_script: script_builder.to_before_script,
36
36
  script: script_builder.to_script,
37
+ after_script: script_builder.to_after_script,
37
38
  matrix_keys: travis.matrix_keys,
38
39
  )
39
40
  job_message
@@ -47,35 +48,31 @@ module Evrone
47
48
  tm: tm.to_i,
48
49
  jobs_count: jobs_count || 0,
49
50
  }
50
-
51
- if commit_info
52
- attributes.merge!(
53
- commit_author: commit_info.author,
54
- commit_author_email: commit_info.email,
55
- commit_sha: commit_info.sha,
56
- commit_message: commit_info.message
57
- )
58
- end
59
51
  Message::BuildStatus.new attributes
60
52
  end
61
53
 
62
54
  def add_to_output(str)
63
55
  output << str
64
56
  logger.debug str.strip if logger.level == 0
65
- BuildLogsConsumer.publish create_build_log_message(str)
66
57
  end
67
58
 
68
59
  def add_command_to_output(cmd)
69
60
  add_to_output "$ #{cmd}\n"
70
61
  end
71
62
 
72
- def create_build_log_message(data)
63
+ def publish_build_log_message(str)
73
64
  @output_counter += 1
74
- Message::BuildLog.new(
65
+ log = Message::BuildLog.new(
75
66
  build_id: message.id,
76
- tm: @output_counter,
77
- log: data
67
+ tm: output_counter,
68
+ log: str
78
69
  )
70
+ BuildLogsConsumer.publish log
71
+ log
72
+ end
73
+
74
+ def scm_class
75
+ Evrone::CI::SCM::Git
79
76
  end
80
77
 
81
78
  end
@@ -12,12 +12,14 @@ module Evrone
12
12
  self.env_namespace = 'ci_router'
13
13
  self.raise_missing_keys = true
14
14
 
15
- define amqp_url: nil,
16
- timeout: 30 * 60,
17
- logger: Common::TaggedLogging.new(Logger.new STDOUT),
18
- repo_dir_name: "repo",
19
- workers: 1,
20
- path_prefix: nil
15
+ define amqp_url: nil,
16
+ timeout: 30 * 60,
17
+ logger: Common::TaggedLogging.new(Logger.new STDOUT),
18
+ repo_dir_name: "repo",
19
+ workers: 1,
20
+ path_prefix: nil,
21
+ webdav_cache_url: nil
22
+
21
23
 
22
24
  def timeout
23
25
  self[:timeout].to_i
@@ -0,0 +1,26 @@
1
+ module Evrone
2
+ module CI
3
+ class Router
4
+ class ScriptBuilder
5
+
6
+ Databases = Struct.new(:app) do
7
+
8
+ include Helper::TraceShCommand
9
+
10
+ def call(env)
11
+ psql = []
12
+ psql << %{sudo -u postgres psql -q -h localhost -c "create role ci with login superuser password 'ci'" || true}
13
+ psql << %{sudo -u postgres psql -q -h localhost -c "create database ci" || true}
14
+ env.init.tap do |i|
15
+ i << psql
16
+ end
17
+ app.call(env)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+
@@ -12,7 +12,10 @@ module Evrone
12
12
  env.travis.global_env.each do |e|
13
13
  env.init << trace_sh_command("export #{e}")
14
14
  end
15
- env.before_install << trace_sh_command("env")
15
+ env.travis.matrix_env.each do |e|
16
+ env.init << trace_sh_command("export #{e}")
17
+ end
18
+ env.announce << trace_sh_command("env")
16
19
  app.call(env)
17
20
  end
18
21
 
@@ -0,0 +1,55 @@
1
+ module Evrone
2
+ module CI
3
+ class Router
4
+ class ScriptBuilder
5
+
6
+ Prepare = Struct.new(:app) do
7
+
8
+ include Helper::TraceShCommand
9
+ include Common::Helper::UploadShCommand
10
+
11
+ def call(env)
12
+ name = env.build.message.name
13
+ deploy_key = env.build.message.deploy_key
14
+
15
+ repo_path = "code/#{name}"
16
+ data_path = "data/#{name}"
17
+ key_file = "#{data_path}/key"
18
+ git_ssh_file = "#{data_path}/git_ssh"
19
+
20
+ sha = env.build.message.sha
21
+ scm = build_scm(env, sha, repo_path)
22
+ git_ssh = scm.git_ssh.class.template(deploy_key && "$PWD/#{key_file}")
23
+
24
+ env.init.tap do |i|
25
+ i << "mkdir -p #{data_path}"
26
+ i << "mkdir -p #{repo_path}"
27
+
28
+ if deploy_key
29
+ i << "echo instaling keys"
30
+ i << upload_sh_command(key_file, deploy_key)
31
+ i << "chmod 0600 #{key_file}"
32
+ end
33
+
34
+ i << upload_sh_command(git_ssh_file, git_ssh)
35
+ i << "chmod 0750 #{git_ssh_file}"
36
+
37
+ i << "export GIT_SSH=$PWD/#{git_ssh_file}"
38
+ i << scm.make_fetch_command
39
+ end
40
+
41
+ app.call env
42
+ end
43
+
44
+ private
45
+
46
+ def build_scm(env, sha, path)
47
+ SCM::Git.new(env.build.message.src, sha, "$PWD/#{path}")
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
@@ -9,22 +9,22 @@ module Evrone
9
9
 
10
10
  def call(env)
11
11
  if rvm env
12
- env.init.tap do |i|
12
+ env.before_install.tap do |i|
13
13
  i << 'eval "$(rbenv init -)" || true'
14
14
  i << "rbenv shell #{make_rbenv_version_command env}"
15
- i << 'export BUNDLE_GEMFILE=${PWD}/Gemfile'
16
- i << 'export GEM_HOME=$HOME/cached/rubygems'
15
+ i << trace_sh_command('export BUNDLE_GEMFILE=${PWD}/Gemfile')
16
+ i << trace_sh_command('export GEM_HOME=$HOME/cached/rubygems')
17
17
  end
18
18
 
19
- env.before_install.tap do |b|
20
- b << "gem query -q -in '^bundler$' > /dev/null || gem install bundler -q --no-rdoc --no-ri"
21
- b << trace_sh_command("ruby --version")
22
- b << trace_sh_command("gem --version")
23
- b << trace_sh_command("bundle --version")
19
+ env.announce.tap do |a|
20
+ a << trace_sh_command("ruby --version")
21
+ a << trace_sh_command("gem --version")
22
+ a << trace_sh_command("bundle --version")
24
23
  end
25
24
 
26
25
  env.install.tap do |i|
27
- i << trace_sh_command("bundle install && bundle clean --force")
26
+ i << trace_sh_command("bundle install")
27
+ i << trace_sh_command("bundle clean --force")
28
28
  end
29
29
  end
30
30
 
@@ -0,0 +1,72 @@
1
+ module Evrone
2
+ module CI
3
+ class Router
4
+ class ScriptBuilder
5
+
6
+ WebdavCache = Struct.new(:app) do
7
+
8
+ include Helper::Config
9
+ include Helper::Logger
10
+
11
+ CASHER_URL = "https://raw.github.com/travis-ci/casher/master/bin/casher"
12
+ CASHER_BIN = "$HOME/.casher/bin/casher"
13
+
14
+ def call(env)
15
+ if config.webdav_cache_url
16
+ assign_url_to_env(env)
17
+ prepare(env)
18
+ fetch(env)
19
+ add(env)
20
+ push(env)
21
+ end
22
+ app.call env
23
+ end
24
+
25
+ private
26
+
27
+ def assign_url_to_env(env)
28
+ name = []
29
+ name << env.build.message.name.dup
30
+
31
+ # convert keys from ["rvm:2.0.0"] to "rvm 2.0.0"
32
+ name += env.travis.matrix_keys.map{|i| i.split(":").join(" ") }
33
+ # replace non word chars to ' '
34
+ name = name.join("-").gsub(/[^a-z0-9_\-.]/, ' ')
35
+
36
+ name = name.strip().gsub(/ +/, '-').downcase
37
+ name << ".tgz"
38
+
39
+ env.webdav_cache_url = "#{config.webdav_cache_url}/#{name}"
40
+ end
41
+
42
+ def prepare(env)
43
+ cmd = %{
44
+ export CASHER_DIR=$HOME/.casher &&
45
+ ( mkdir -p $CASHER_DIR/bin &&
46
+ curl #{CASHER_URL} -s -o #{CASHER_BIN} &&
47
+ chmod +x #{CASHER_BIN} &&
48
+ echo casher successfuly downloaded ) ||
49
+ true
50
+ }.compact
51
+ env.init << cmd
52
+ end
53
+
54
+ def fetch(env)
55
+ env.init << "#{CASHER_BIN} fetch #{env.webdav_cache_url} || true"
56
+ end
57
+
58
+ def add(env)
59
+ env.init << "#{CASHER_BIN} add $HOME/cached || true"
60
+ env.init << "unset CASHER_DIR"
61
+ end
62
+
63
+ def push(env)
64
+ env.after_script << "#{CASHER_BIN} push #{env.webdav_cache_url}"
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+
@@ -6,36 +6,61 @@ module Evrone
6
6
  class Router
7
7
  class ScriptBuilder
8
8
 
9
- autoload :Env, File.expand_path("../script_builder/env", __FILE__)
10
- autoload :Ruby, File.expand_path("../script_builder/ruby", __FILE__)
11
- autoload :Script, File.expand_path("../script_builder/script", __FILE__)
9
+ autoload :Env, File.expand_path("../script_builder/env", __FILE__)
10
+ autoload :Ruby, File.expand_path("../script_builder/ruby", __FILE__)
11
+ autoload :Script, File.expand_path("../script_builder/script", __FILE__)
12
+ autoload :Prepare, File.expand_path("../script_builder/prepare", __FILE__)
13
+ autoload :Databases, File.expand_path("../script_builder/databases", __FILE__)
14
+ autoload :WebdavCache, File.expand_path("../script_builder/webdav_cache", __FILE__)
12
15
 
13
16
  include Common::Helper::Middlewares
14
17
 
15
18
  middlewares do
19
+ use ScriptBuilder::WebdavCache
16
20
  use ScriptBuilder::Env
21
+ use ScriptBuilder::Prepare
22
+ use ScriptBuilder::Databases
17
23
  use ScriptBuilder::Ruby
18
24
  use ScriptBuilder::Script
19
25
  end
20
26
 
21
- attr_reader :travis
27
+ attr_reader :travis, :build
22
28
 
23
- def initialize(travis)
29
+ def initialize(build, travis)
24
30
  @travis = travis
31
+ @build = build
25
32
  end
26
33
 
27
34
  def to_before_script
28
35
  a = []
36
+ a << "\n# init"
29
37
  a += env.init
38
+
39
+ a << "\n# before install"
30
40
  a += env.before_install
41
+
42
+ a << "\n# announce"
43
+ a += env.announce
44
+
45
+ a << "\n# install"
31
46
  a += env.install
47
+
48
+ a << "\n# before script"
32
49
  a += env.before_script
33
50
  a.join("\n")
34
51
  end
35
52
 
53
+ def to_after_script
54
+ a = []
55
+ a << "\n# after script"
56
+ a += env.after_script
57
+ a.join("\n")
58
+ end
59
+
36
60
  def to_script
37
61
  a = []
38
- a << env.script
62
+ a << "\n# script"
63
+ a += env.script
39
64
  a.join("\n")
40
65
  end
41
66
 
@@ -47,12 +72,24 @@ module Evrone
47
72
 
48
73
  def default_env
49
74
  OpenStruct.new(
75
+ # initialization, repo does not exists
50
76
  init: [],
77
+
78
+ # before instalation, using for system setup
51
79
  before_install: [],
80
+
81
+ # instalation, using for application setup
52
82
  install: [],
83
+
84
+ # announce software and services version
85
+ announce: [],
86
+
53
87
  before_script: [],
54
88
  script: [],
55
- travis: travis
89
+ after_script: [],
90
+
91
+ travis: travis,
92
+ build: build,
56
93
  )
57
94
  end
58
95
 
@@ -39,8 +39,8 @@ module Evrone
39
39
  @to_matrix_s ||= matrix_keys.join(", ")
40
40
  end
41
41
 
42
- def to_script_builder
43
- ScriptBuilder.new(self)
42
+ def to_script_builder(build)
43
+ ScriptBuilder.new(build, self)
44
44
  end
45
45
 
46
46
  def env
@@ -1,7 +1,7 @@
1
1
  module Evrone
2
2
  module CI
3
3
  class Router
4
- VERSION = "0.2.0.pre4"
4
+ VERSION = "0.2.0.pre5"
5
5
  end
6
6
  end
7
7
  end
@@ -70,26 +70,21 @@ module Evrone
70
70
  include Helper::Logger
71
71
  include Helper::Config
72
72
 
73
- attr_reader :build, :path_prefix, :repo_dir, :travis
73
+ attr_reader :build, :travis
74
74
 
75
- def initialize(build, path_prefix)
75
+ def initialize(build)
76
76
  @build = build
77
- @path_prefix = Pathname.new(path_prefix).expand_path
78
- @repo_dir = @path_prefix.join(config.repo_dir_name)
79
- .join(build.message.name)
80
77
  @travis = nil
81
78
  end
82
79
 
83
80
  def perform
84
81
  log_build do
85
82
  update_build_status do
86
- create_repo_dir &&
87
- fetch_repo &&
88
- assign_commit_info &&
89
- load_travis &&
83
+ load_travis &&
90
84
  create_and_delivery_build_matrix
91
85
  end
92
86
  end
87
+ build.release
93
88
  end
94
89
 
95
90
  def create_and_delivery_build_matrix
@@ -107,24 +102,10 @@ module Evrone
107
102
  end
108
103
 
109
104
  def load_travis
110
- @travis = Travis.from_file repo_dir.join(".travis.yml")
105
+ @travis = Travis.from_yaml build.message.travis
111
106
  @travis
112
107
  end
113
108
 
114
- def create_repo_dir
115
- FileUtils.mkdir_p(repo_dir) unless repo_dir.directory?
116
- true
117
- end
118
-
119
- def fetch_repo
120
- scm.fetch == 0
121
- end
122
-
123
- def assign_commit_info
124
- build.commit_info = scm.commit_info
125
- true
126
- end
127
-
128
109
  def log_build
129
110
  logger.tagged("BUILD #{build.message.id}") do
130
111
  logger.info "starting build"
@@ -8,13 +8,13 @@ describe Evrone::CI::Router::Build do
8
8
 
9
9
  context "just created" do
10
10
  its(:message) { should eq msg }
11
- its(:output) { should eq '' }
11
+ its(:output) { should be_an_instance_of(Evrone::CI::Common::OutputBuffer)}
12
12
  its(:output_counter) { should eq 0 }
13
13
  end
14
14
 
15
- context "create_build_log_message" do
15
+ context "publish_build_log_message" do
16
16
  let(:data) { 'log' }
17
- subject { build.create_build_log_message data }
17
+ subject { build.publish_build_log_message data }
18
18
 
19
19
  it { should be_an_instance_of(Evrone::CI::Message::BuildLog) }
20
20
  its(:build_id) { should eq build.message.id }
@@ -26,6 +26,13 @@ describe Evrone::CI::Router::Build do
26
26
  subject
27
27
  }.to change(build, :output_counter).by(1)
28
28
  end
29
+
30
+ it "should delivery message" do
31
+ expect {
32
+ subject
33
+ }.to change(Evrone::CI::Router::BuildLogsConsumer.messages, :count).by(1)
34
+ expect(last_build_log_message.log).to eq data
35
+ end
29
36
  end
30
37
 
31
38
  context "to_build_status_message" do
@@ -40,63 +47,53 @@ describe Evrone::CI::Router::Build do
40
47
  its(:status) { should eq 2 }
41
48
  its(:tm) { should be }
42
49
  its(:jobs_count) { should eq 1 }
43
-
44
- context "when commit_info exists" do
45
- before do
46
- build.commit_info = OpenStruct.new(
47
- author: "author",
48
- email: "email",
49
- sha: 'sha',
50
- message: "message"
51
- )
52
- end
53
-
54
- its(:commit_author) { should eq 'author' }
55
- its(:commit_author_email) { should eq 'email' }
56
- its(:commit_sha) { should eq 'sha' }
57
- its(:commit_message) { should eq 'message' }
58
- end
59
50
  end
60
51
 
61
52
  context "add_to_output" do
62
53
  let(:data) { 'data' }
63
54
  let(:messages) { Evrone::CI::Router::BuildLogsConsumer.messages }
64
- subject { build.add_to_output(data) ; build }
65
-
66
- its(:output) { should eq data }
55
+ subject do
56
+ build.add_to_output(data)
57
+ build.output.flush
58
+ build
59
+ end
67
60
 
68
61
  it "should delivery message" do
69
62
  expect {
70
63
  subject
71
64
  }.to change(messages, :size).by(1)
65
+ expect(last_build_log_message.log).to eq data
72
66
  end
73
67
 
74
68
  it "should increment output_counter" do
75
69
  expect {
76
70
  subject
77
71
  }.to change(build, :output_counter).by(1)
78
- expect(messages.first.tm).to eq 1
72
+ expect(last_build_log_message.tm).to eq 1
79
73
  end
80
74
  end
81
75
 
82
76
  context "add_command_to_output" do
83
77
  let(:data) { 'data' }
84
78
  let(:messages) { Evrone::CI::Router::BuildLogsConsumer.messages }
85
- subject { build.add_command_to_output(data) ; build }
86
-
87
- its(:output) { should eq "$ #{data}\n" }
79
+ subject do
80
+ build.add_command_to_output(data)
81
+ build.output.flush
82
+ build
83
+ end
88
84
 
89
85
  it "should delivery message" do
90
86
  expect {
91
87
  subject
92
88
  }.to change(messages, :size).by(1)
89
+ expect(last_build_log_message.log).to eq "$ #{data}\n"
93
90
  end
94
91
 
95
92
  it "should increment output_counter" do
96
93
  expect {
97
94
  subject
98
95
  }.to change(build, :output_counter).by(1)
99
- expect(messages.first.tm).to eq 1
96
+ expect(last_build_log_message.tm).to eq 1
100
97
  end
101
98
  end
102
99
 
@@ -108,25 +105,18 @@ describe Evrone::CI::Router::Build do
108
105
  it { should be_an_instance_of Evrone::CI::Message::PerformJob }
109
106
 
110
107
  context "created message" do
111
- its(:id) { should eq build.message.id }
112
- its(:name) { should eq build.message.name }
113
- its(:src) { should eq build.message.src }
114
- its(:sha) { should eq build.message.sha }
115
- its(:deploy_key) { should eq build.message.deploy_key }
116
-
117
- its(:job_id) { should eq job_id }
118
- its(:before_script) { should be }
119
- its(:script) { should be }
120
- its(:matrix_keys) { should eq ['rvm:2.0.0'] }
108
+ its(:id) { should eq build.message.id }
109
+ its(:name) { should eq build.message.name }
110
+ its(:job_id) { should eq job_id }
111
+ its(:before_script) { should be }
112
+ its(:script) { should be }
113
+ its(:after_script) { should be }
114
+ its(:matrix_keys) { should eq ['rvm:2.0.0'] }
121
115
  end
116
+ end
122
117
 
123
- context "when commit_info.sha exists" do
124
- before do
125
- build.commit_info = OpenStruct.new sha: "commit info sha"
126
- end
127
-
128
- its(:sha) { should eq 'commit info sha' }
129
-
130
- end
118
+ context "scm_class" do
119
+ subject { build.scm_class }
120
+ it { should eq ::Evrone::CI::SCM::Git }
131
121
  end
132
122
  end
@@ -4,22 +4,11 @@ require 'pathname'
4
4
 
5
5
  describe Evrone::CI::Router do
6
6
  let(:build) { create :build }
7
- let(:path_prefix) { '/tmp/.test' }
8
- let(:router) { described_class.new build, path_prefix }
7
+ let(:router) { described_class.new build }
9
8
  subject { router }
10
9
 
11
- before do
12
- FileUtils.rm_rf path_prefix
13
- end
14
-
15
- after do
16
- FileUtils.rm_rf path_prefix
17
- end
18
-
19
10
  context "just created" do
20
11
  its(:build) { should eq build }
21
- its("path_prefix.to_s") { should eq path_prefix }
22
- its("repo_dir.to_s") { should eq "/tmp/.test/repo/evrone/test-repo" }
23
12
  end
24
13
 
25
14
  context "#perform" do
@@ -54,41 +43,10 @@ describe Evrone::CI::Router do
54
43
  end
55
44
  end
56
45
 
57
- context "#create_repo_dir" do
58
- subject { router.create_repo_dir }
59
- it "should create directory inside path_prefix" do
60
- expect(subject).to be_true
61
- expect(router.repo_dir).to be_directory
62
- end
63
- end
64
-
65
- context "#fetch_repo" do
66
- subject { router.fetch_repo }
67
- it "should fetch repo" do
68
- expect(subject).to be_true
69
- expect(router.repo_dir.join(".git")).to be_directory
70
- end
71
- end
72
-
73
- context "#assign_commit_info" do
74
- subject { router.assign_commit_info }
75
- before { mock_repo_dir }
76
-
77
- it "should assign commit information to build" do
78
- expect(subject).to be_true
79
- expect(router.build.commit_info.marshal_dump).to eq(
80
- :sha=>"687753389908e70801dd4ff5448be908642055c6",
81
- :author=>"Dmitry Galinsky",
82
- :email=>"dima.exe@gmail.com",
83
- :message=>"test commit #3"
84
- )
85
- end
86
- end
87
-
88
46
  context "#load_travis" do
89
47
  subject { router.load_travis }
90
- before { mock_repo_dir }
91
- it "should build new travis instance from .travis.yml" do
48
+
49
+ it "should build new travis instance from message" do
92
50
  expect(subject).to be_true
93
51
  expect(router.travis).to be
94
52
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'evrone/common/spawn'
3
+ require 'fileutils'
4
+
5
+ describe Evrone::CI::Router::ScriptBuilder::Prepare do
6
+ let(:path) { '/tmp/.test' }
7
+ let(:app) { ->(_) { _ } }
8
+ let(:build) { create :build }
9
+ let(:env) { OpenStruct.new build: build, init: [] }
10
+ let(:mid) { described_class.new app }
11
+
12
+ subject { mid.call env }
13
+
14
+ before do
15
+ FileUtils.rm_rf path
16
+ FileUtils.mkdir_p path
17
+ end
18
+
19
+ after { FileUtils.rm_rf path }
20
+
21
+ it { should eq env }
22
+ its(:init) { should_not be_empty }
23
+
24
+ context "run compiled script" do
25
+ include Evrone::Common::Spawn
26
+
27
+ let(:script) { "set -e\nset -x\n" + env.init.join("\n") }
28
+ before { mid.call env }
29
+
30
+ it "should be success" do
31
+
32
+ code = spawn script, chdir: path do |out|
33
+ puts " ===> #{out}"
34
+ end
35
+
36
+ expect(code).to eq 0
37
+ expect(File).to be_readable("#{path}/data/evrone/test-repo/git_ssh")
38
+ expect(File).to be_readable("#{path}/data/evrone/test-repo/key")
39
+ expect(File).to be_directory("#{path}/code/evrone/test-repo/.git")
40
+ expect(File).to be_readable("#{path}/code/evrone/test-repo/Rakefile")
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'evrone/common/spawn'
3
+ require 'fileutils'
4
+
5
+ describe Evrone::CI::Router::ScriptBuilder::WebdavCache do
6
+ let(:path) { '/tmp/.test' }
7
+ let(:app) { ->(_) { _ } }
8
+ let(:build) { create :build }
9
+ let(:travis) { create :travis }
10
+ let(:env) { OpenStruct.new build: build, init: [], travis: travis, after_script: [] }
11
+ let(:mid) { described_class.new app }
12
+
13
+ subject { mid.call env }
14
+
15
+ before do
16
+ FileUtils.rm_rf path
17
+ FileUtils.mkdir_p path
18
+
19
+ Evrone::CI::Router.configure do |c|
20
+ c.webdav_cache_url = 'http://localhost:8080'
21
+ end
22
+ end
23
+
24
+ after { FileUtils.rm_rf path }
25
+
26
+ it { should eq env }
27
+ its(:init) { should_not be_empty }
28
+ its(:after_script) { should_not be_empty }
29
+ its(:webdav_cache_url) { should eq "http://localhost:8080/evrone-test-repo-rvm-2.0.0.tgz" }
30
+
31
+ context "execute command" do
32
+ include Evrone::Common::Spawn
33
+
34
+ let(:init_script) { env.init.join("\n") }
35
+ let(:after_script) { env.after_script.join("\n") }
36
+
37
+ before do
38
+ mid.call env
39
+ init_script.gsub!("$HOME/cached", path)
40
+ after_script.gsub!("$HOME/cached", path)
41
+ end
42
+
43
+ it "should be success" do
44
+ out = ""
45
+
46
+ code = spawn(init_script, chdir: path) do |o|
47
+ out << o
48
+ puts " ===> #{o}"
49
+ end
50
+ expect(code).to eq 0
51
+
52
+ code = spawn(after_script, chdir: path) do |o|
53
+ out << o
54
+ puts " ===> #{o}"
55
+ end
56
+ expect(code).to eq 0
57
+
58
+ #twice
59
+ code = spawn(after_script, chdir: path) do |o|
60
+ out << o
61
+ puts " ===> #{o}"
62
+ end
63
+ expect(code).to eq 0
64
+
65
+ expect(out).to match("adding /tmp/.test to cache")
66
+ expect(out).to match("casher successfuly downloaded")
67
+ end
68
+ end
69
+ end
70
+
@@ -1,51 +1,32 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Evrone::CI::Router::ScriptBuilder do
4
- let(:travis) { create :travis }
5
- let(:script_builder) { described_class.new travis }
6
- let(:expected_before_script) {
7
- s = []
8
- s << "export LC_ALL=en_US.UTF8"
9
- s << "eval \"$(rbenv init -)\" || true"
10
- s << %{
11
- rbenv shell
12
- $(rbenv versions |
13
- sed -e 's/^*/ /' |
14
- awk '{print $1}' |
15
- grep -v 'system' |
16
- grep '2.0.0' |
17
- tail -n1)
18
- }.compact
19
- s << 'export BUNDLE_GEMFILE=${PWD}/Gemfile'
20
- s << "export GEM_HOME=$HOME/cached/rubygems"
21
- trace s, "env"
22
- s << "gem query -q -in '^bundler$' > /dev/null || gem install bundler -q --no-rdoc --no-ri"
23
- trace s, "ruby --version"
24
- trace s, "gem --version"
25
- trace s, "bundle --version"
26
- trace s, "bundle install && bundle clean --force"
27
- trace s, "echo before_script"
28
- s.join("\n")
29
- }
30
- let(:expected_script) {
31
- s = []
32
- trace s, "RAILS_ENV=test ls -1 && echo DONE!"
33
- s.join("\n")
34
- }
4
+ let(:build) { create :build }
5
+ let(:travis) { create :travis }
6
+ let(:script_builder) { described_class.new build, travis }
35
7
  subject { script_builder }
36
8
 
37
- its(:travis) { should eq travis }
9
+ context "just created" do
10
+ its(:travis) { should eq travis }
11
+ its(:build) { should eq build }
12
+ end
38
13
 
39
14
  context "to_before_script" do
40
15
  subject { script_builder.to_before_script }
41
16
 
42
- it { should eq expected_before_script }
17
+ it { should_not be_empty }
43
18
  end
44
19
 
45
20
  context "to_script" do
46
21
  subject { script_builder.to_script }
47
22
 
48
- it { should eq expected_script }
23
+ it { should_not be_empty }
24
+ end
25
+
26
+ context "to_after_script" do
27
+ subject { script_builder.to_after_script }
28
+
29
+ it { should_not be_empty }
49
30
  end
50
31
 
51
32
  def trace(s, cmd)
@@ -64,7 +64,8 @@ describe Evrone::CI::Router::Travis do
64
64
  end
65
65
 
66
66
  context "to_script_builder" do
67
- subject { travis.to_script_builder }
67
+ let(:build) { create :build }
68
+ subject { travis.to_script_builder build }
68
69
  it { should be }
69
70
  end
70
71
 
@@ -35,13 +35,6 @@ def create(who, *args)
35
35
  path = args.shift
36
36
  Evrone::CI::SCM::Git.new build.src, build.sha, path, deploy_key: build.deploy_key, &build.method(:add_to_output)
37
37
 
38
- when :commit_info
39
- OpenStruct.new(
40
- sha: "sha",
41
- author: "author",
42
- email: "email",
43
- message: "message"
44
- )
45
38
  end
46
39
 
47
40
  end
@@ -0,0 +1,3 @@
1
+ def last_build_log_message
2
+ Evrone::CI::Router::BuildLogsConsumer.messages.last
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evrone-ci-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre4
4
+ version: 0.2.0.pre5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-05 00:00:00.000000000 Z
11
+ date: 2013-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evrone-ci-common
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0.pre4
19
+ version: 0.2.0.pre5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0.pre4
26
+ version: 0.2.0.pre5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: evrone-ci-message
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.0.pre4
33
+ version: 0.2.0.pre5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.0.pre4
40
+ version: 0.2.0.pre5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: evrone-common-amqp
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -155,9 +155,12 @@ files:
155
155
  - lib/evrone/ci/router/helper/trace_sh_command.rb
156
156
  - lib/evrone/ci/router/initializers/amqp.rb
157
157
  - lib/evrone/ci/router/script_builder.rb
158
+ - lib/evrone/ci/router/script_builder/databases.rb
158
159
  - lib/evrone/ci/router/script_builder/env.rb
160
+ - lib/evrone/ci/router/script_builder/prepare.rb
159
161
  - lib/evrone/ci/router/script_builder/ruby.rb
160
162
  - lib/evrone/ci/router/script_builder/script.rb
163
+ - lib/evrone/ci/router/script_builder/webdav_cache.rb
161
164
  - lib/evrone/ci/router/travis.rb
162
165
  - lib/evrone/ci/router/travis/serializable.rb
163
166
  - lib/evrone/ci/router/version.rb
@@ -165,11 +168,14 @@ files:
165
168
  - spec/lib/build_spec.rb
166
169
  - spec/lib/configuration_spec.rb
167
170
  - spec/lib/router_spec.rb
171
+ - spec/lib/script_builder/prepare_spec.rb
172
+ - spec/lib/script_builder/webdav_cache_spec.rb
168
173
  - spec/lib/script_builder_spec.rb
169
174
  - spec/lib/travis_spec.rb
170
175
  - spec/spec_helper.rb
171
176
  - spec/support/create.rb
172
177
  - spec/support/fixture.rb
178
+ - spec/support/last_build_log_message.rb
173
179
  - spec/support/shared_examples/update_build_status_message.rb
174
180
  homepage: ''
175
181
  licenses:
@@ -200,9 +206,12 @@ test_files:
200
206
  - spec/lib/build_spec.rb
201
207
  - spec/lib/configuration_spec.rb
202
208
  - spec/lib/router_spec.rb
209
+ - spec/lib/script_builder/prepare_spec.rb
210
+ - spec/lib/script_builder/webdav_cache_spec.rb
203
211
  - spec/lib/script_builder_spec.rb
204
212
  - spec/lib/travis_spec.rb
205
213
  - spec/spec_helper.rb
206
214
  - spec/support/create.rb
207
215
  - spec/support/fixture.rb
216
+ - spec/support/last_build_log_message.rb
208
217
  - spec/support/shared_examples/update_build_status_message.rb