evrone-ci-common 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: 81ca8965c9dae40ab4566ba5d5c048a2a87b389e
4
- data.tar.gz: 4e6d92fed51fc19fcadc01aa927f1a34682d4add
3
+ metadata.gz: 4bf4a415c501a8ed67dfe244d27461497184022e
4
+ data.tar.gz: 043c7c33e4bac0a495bb96d7e5bf3b9d7c08d6a0
5
5
  SHA512:
6
- metadata.gz: ed9a28451eee34d32576499f36d9308b93b8e41b2a0e7f8dc54fb2df7faf6c06a76e1a2508fb248202388d62c80316e64867432fb81fed19d7701f1536ce735f
7
- data.tar.gz: 9633d1460ab29127d4a381917408f7bd4b20840b877a599dd4fd1fa515ae2bb72fdfb4579296be7ac82ab8dd59a8f684c3954dc9520ecf96e1bba3513ee93c64
6
+ metadata.gz: 788eefddbf3408645b46d6af40bc01352e56d1bc0b9df95700d225cdfb43f603ce192a4cba0f03fdede1b40018b40cf49ecc336b6c0c3b1e222a97d1e742dd2f
7
+ data.tar.gz: fdbabe1369b1cffc7e790d636b69a02e41b551c055bf4e6d9f407f48191ecf3f3a43341fbe157d1619cc21116b91d314b77d4298e8fba2caba2b25426bfca755
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency 'evrone-common-spawn', '0.0.4'
21
+ spec.add_runtime_dependency 'evrone-common-spawn', '0.0.6'
22
22
  spec.add_runtime_dependency 'evrone-common-rack-builder', '0.0.2'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -0,0 +1,25 @@
1
+ require 'base64'
2
+
3
+ module Evrone
4
+ module CI
5
+ module Common
6
+ module Helper
7
+ module UploadShCommand
8
+
9
+ def upload_sh_command(path, content, options = {})
10
+ encoded = ::Base64.encode64(content).gsub("\n", '')
11
+ "(echo #{encoded} | #{upload_sh_base64_command options}) > #{path}"
12
+ end
13
+
14
+ private
15
+
16
+ def upload_sh_base64_command(options)
17
+ %{base64 --decode}
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,76 @@
1
+ require 'thread'
2
+
3
+ module Evrone
4
+ module CI
5
+ module Common
6
+ class OutputBuffer
7
+
8
+ attr_reader :interval
9
+
10
+ def initialize(interval = 1, &block)
11
+ @interval = interval.to_f
12
+ @buffer = ""
13
+ @write = block
14
+ @mutex = Mutex.new
15
+ @closed = false
16
+
17
+ start_watching
18
+ end
19
+
20
+ def << (str)
21
+ closed!
22
+
23
+ @mutex.synchronize do
24
+ @buffer << str
25
+ end
26
+ end
27
+
28
+ def close
29
+ @closed = true
30
+ @thread.join
31
+ end
32
+
33
+ def flush
34
+ closed!
35
+ @mutex.synchronize { write }
36
+ end
37
+
38
+ def empty?
39
+ @buffer.size == 0
40
+ end
41
+
42
+ class ClosedBuffer < Exception ; end
43
+
44
+ private
45
+
46
+ def write
47
+ unless empty?
48
+ @write.call @buffer.dup
49
+ @buffer.clear
50
+ end
51
+ end
52
+
53
+ def closed!
54
+ raise ClosedBuffer if @closed
55
+ end
56
+
57
+ def start_watching
58
+ @thread = Thread.new do
59
+ loop do
60
+ sleep interval
61
+
62
+ unless empty?
63
+ @mutex.synchronize { write }
64
+ end
65
+
66
+ break if @closed
67
+ end
68
+ end
69
+ @thread.abort_on_exception = true
70
+ end
71
+
72
+ end
73
+ end
74
+ end
75
+ end
76
+
@@ -1,7 +1,7 @@
1
1
  module Evrone
2
2
  module CI
3
3
  module Common
4
- VERSION = "0.2.0.pre4"
4
+ VERSION = "0.2.0.pre5"
5
5
  end
6
6
  end
7
7
  end
@@ -4,20 +4,17 @@ module Evrone
4
4
  module CI
5
5
 
6
6
  module Common
7
-
8
7
  module Helper
9
- autoload :Shell, File.expand_path("../common/helper/shell", __FILE__)
10
- autoload :Middlewares, File.expand_path("../common/helper/middlewares", __FILE__)
8
+ autoload :Shell, File.expand_path("../common/helper/shell", __FILE__)
9
+ autoload :Middlewares, File.expand_path("../common/helper/middlewares", __FILE__)
10
+ autoload :UploadShCommand, File.expand_path("../common/helper/upload_sh_command", __FILE__)
11
11
  end
12
12
 
13
- autoload :PerformMessageWrapper, File.expand_path("../common/perform_message_wrapper", __FILE__)
14
-
13
+ autoload :OutputBuffer, File.expand_path("../common/output_buffer", __FILE__)
15
14
  end
16
15
 
17
16
  module SCM
18
-
19
17
  autoload :Git, File.expand_path("../scm/git", __FILE__)
20
-
21
18
  end
22
19
 
23
20
  end
@@ -35,7 +35,7 @@ module Evrone
35
35
  end
36
36
 
37
37
  def location
38
- @location ||= write_tmp_file 'git', template, 0700
38
+ @location ||= write_tmp_file 'git', self.class.template(key_location && key_location.path), 0700
39
39
  end
40
40
 
41
41
  def key_location
@@ -44,11 +44,13 @@ module Evrone
44
44
  end
45
45
  end
46
46
 
47
- def template
48
- key = key_location ? "-i #{key_location.path}" : ""
49
- out = ['#!/bin/sh']
50
- out << "exec /usr/bin/ssh -A -o StrictHostKeyChecking=no #{key} $@"
51
- out.join "\n"
47
+ class << self
48
+ def template(key_location)
49
+ key = key_location ? "-i #{key_location}" : ""
50
+ out = ['#!/bin/sh']
51
+ out << "exec /usr/bin/ssh -A -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null #{key} $@"
52
+ out.join "\n"
53
+ end
52
54
  end
53
55
 
54
56
  end
@@ -11,14 +11,13 @@ module Evrone
11
11
 
12
12
  COMMIT_RE = /^(.*) -:- (.*) \((.*)\) -:- (.*)$/
13
13
 
14
- attr_reader :src, :sha, :path, :logger, :git_ssh, :pull_request_id, :branch
14
+ attr_reader :src, :sha, :path, :logger, :git_ssh, :branch
15
15
 
16
16
  def initialize(src, sha, path, options = {}, &block)
17
17
  @src = src
18
18
  @sha = sha
19
19
  @path = path
20
20
  @branch = options[:branch]
21
- @pull_request_id = options[:pull_request_id]
22
21
  @git_ssh = GitSSH.new options[:deploy_key]
23
22
  @logger = block
24
23
  end
@@ -30,11 +29,9 @@ module Evrone
30
29
  end
31
30
 
32
31
  def fetch
33
- code = open do
34
- repo_exist? ? update : clone
32
+ open do
33
+ run_git make_fetch_command
35
34
  end
36
- code = checkout if code == 0
37
- code
38
35
  end
39
36
 
40
37
  def self.make_export_command(from, to)
@@ -42,10 +39,15 @@ module Evrone
42
39
  end
43
40
 
44
41
  def make_fetch_command
45
- clone_cmd = "git clone -q #{src} #{path}"
42
+ clone_cmd = "git clone -q #{src} #{path}"
46
43
  checkout_cmd = "git checkout -qf #{sha}"
44
+ fetch_cmd = "git fetch -q origin"
47
45
  cmd = %{
48
- if [ ! -d #{path} ] ; then
46
+ if [ -d #{path}/.git ] ; then
47
+ echo "$ #{fetch_cmd}" &&
48
+ cd #{path} &&
49
+ #{fetch_cmd} || exit $? ;
50
+ else
49
51
  echo "$ #{clone_cmd}" &&
50
52
  #{clone_cmd} || exit $? ;
51
53
  fi ;
@@ -89,27 +91,10 @@ module Evrone
89
91
  %{git log -1 --pretty=format:'%H -:- %cn (%ce) -:- %s'}
90
92
  end
91
93
 
92
- def repo_exist?
93
- File.directory?(path.to_s + "/.git")
94
- end
95
-
96
- def update
97
- run_git 'git fetch origin', chdir: path
98
- end
99
-
100
- def clone
101
- run_git "git clone -q #{src} #{path}"
102
- end
103
-
104
- def checkout
105
- run_git "git checkout -qf #{sha}", chdir: path
106
- end
107
-
108
94
  def run_git(cmd, options = {})
109
95
  env = {
110
96
  'GIT_SSH' => git_ssh.location.path
111
97
  }
112
- logger.call "$ #{cmd}\n"
113
98
  spawn(env, cmd, options, &logger)
114
99
  end
115
100
 
@@ -0,0 +1,39 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'evrone/common/spawn'
5
+ require 'fileutils'
6
+
7
+ describe Evrone::CI::Common::Helper::UploadShCommand do
8
+ let(:object) { Object.new }
9
+ subject { object }
10
+
11
+ before do
12
+ object.extend described_class
13
+ object.extend Evrone::Common::Spawn
14
+ end
15
+
16
+ it { should be_respond_to(:upload_sh_command) }
17
+
18
+ context "#upload_sh_command" do
19
+ let(:file) { '/tmp/.test' }
20
+ let(:content) { 'Дима' }
21
+ let(:cmd) { object.upload_sh_command file, content }
22
+
23
+ before { FileUtils.rm_rf file }
24
+ after { FileUtils.rm_rf file }
25
+
26
+ it "should be successful" do
27
+ object.spawn cmd do |out|
28
+ puts " ===> #{out}"
29
+ end
30
+
31
+ expect(File).to be_readable(file)
32
+ expect(File.read file).to eq content
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Evrone::CI::Common::OutputBuffer do
4
+ let(:collected) { "" }
5
+ let(:write) { ->(str) { collected << str } }
6
+ let(:buffer) { described_class.new(0.5, &write) }
7
+
8
+ after do
9
+ buffer.close
10
+ end
11
+
12
+ it { should be }
13
+
14
+ it "should add string to buffer" do
15
+ buffer << "1"
16
+ buffer << "2"
17
+ expect(collected).to eq ''
18
+ sleep 1
19
+ expect(collected).to eq '12'
20
+
21
+ buffer << '3'
22
+ expect(collected).to eq '12'
23
+ sleep 1
24
+ expect(collected).to eq '123'
25
+ end
26
+
27
+ it "should raise error when add to closed buffer" do
28
+ buffer.close
29
+ expect {
30
+ buffer << "1"
31
+ }.to raise_error
32
+ end
33
+
34
+ it "should flush buffer" do
35
+ buffer << "1"
36
+ sleep 0.1
37
+ expect(collected).to eq ''
38
+ buffer.flush
39
+ expect(collected).to eq '1'
40
+ end
41
+
42
+ end
@@ -15,7 +15,11 @@ describe Evrone::CI::SCM::Git do
15
15
 
16
16
  subject { git }
17
17
 
18
- before { FileUtils.rm_rf path }
18
+ before do
19
+ FileUtils.rm_rf path
20
+ FileUtils.mkdir_p path
21
+ end
22
+
19
23
  after { FileUtils.rm_rf path }
20
24
 
21
25
  context "just created" do
@@ -23,7 +27,6 @@ describe Evrone::CI::SCM::Git do
23
27
  its(:sha) { should eq sha }
24
28
  its(:path) { should eq path }
25
29
  its(:branch) { should be_nil }
26
- its(:pull_request_id) { should be_nil }
27
30
  its("git_ssh.deploy_key") { should be_nil }
28
31
  end
29
32
 
@@ -32,11 +35,6 @@ describe Evrone::CI::SCM::Git do
32
35
  its(:branch) { should eq 'master' }
33
36
  end
34
37
 
35
- context "assign pull_request_id" do
36
- let(:options) { { pull_request_id: 1} }
37
- its(:pull_request_id) { should eq 1 }
38
- end
39
-
40
38
  context "assign deploy_key" do
41
39
  let(:options) { { deploy_key: deploy_key } }
42
40
  its("git_ssh.deploy_key") { should eq deploy_key }
@@ -81,10 +79,9 @@ describe Evrone::CI::SCM::Git do
81
79
  include Evrone::Common::Spawn
82
80
 
83
81
  let(:options) { { deploy_key: deploy_key } }
84
- let(:env) { {'GIT_SSH' => git.git_ssh.location.path} }
85
82
  let(:run) do
86
83
  git.open do
87
- spawn(env, git.make_fetch_command, &method(:add_to_output))
84
+ spawn(git_ssh_env, git.make_fetch_command, &method(:add_to_output))
88
85
  end
89
86
  end
90
87
  subject { git.make_fetch_command }
@@ -109,8 +106,8 @@ describe Evrone::CI::SCM::Git do
109
106
 
110
107
  context "twice" do
111
108
  it "should be" do
112
- code = git.git_ssh.open do
113
- spawn(env, git.make_fetch_command, &method(:add_to_output))
109
+ code = git.open do
110
+ spawn(git_ssh_env, git.make_fetch_command, &method(:add_to_output))
114
111
  end
115
112
  expect(code).to eq 0
116
113
  end
@@ -123,6 +120,10 @@ describe Evrone::CI::SCM::Git do
123
120
  expect(run).to eq 128
124
121
  end
125
122
  end
123
+
124
+ def git_ssh_env
125
+ { 'GIT_SSH' => git.git_ssh.location.path }
126
+ end
126
127
  end
127
128
 
128
129
  context ".make_export_command" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evrone-ci-common
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-common-spawn
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.4
19
+ version: 0.0.6
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.0.4
26
+ version: 0.0.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: evrone-common-rack-builder
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -125,12 +125,16 @@ files:
125
125
  - lib/evrone/ci/common.rb
126
126
  - lib/evrone/ci/common/helper/middlewares.rb
127
127
  - lib/evrone/ci/common/helper/shell.rb
128
+ - lib/evrone/ci/common/helper/upload_sh_command.rb
129
+ - lib/evrone/ci/common/output_buffer.rb
128
130
  - lib/evrone/ci/common/tagged_logging.rb
129
131
  - lib/evrone/ci/common/version.rb
130
132
  - lib/evrone/ci/scm/git.rb
131
133
  - lib/evrone/ci/scm/git/git_ssh.rb
132
134
  - spec/lib/common/helper/middlewares_spec.rb
133
135
  - spec/lib/common/helper/shell_spec.rb
136
+ - spec/lib/common/helper/upload_sh_command_spec.rb
137
+ - spec/lib/common/output_buffer_spec.rb
134
138
  - spec/lib/scm/git_spec.rb
135
139
  - spec/spec_helper.rb
136
140
  homepage: ''
@@ -160,5 +164,7 @@ summary: Common code for ci
160
164
  test_files:
161
165
  - spec/lib/common/helper/middlewares_spec.rb
162
166
  - spec/lib/common/helper/shell_spec.rb
167
+ - spec/lib/common/helper/upload_sh_command_spec.rb
168
+ - spec/lib/common/output_buffer_spec.rb
163
169
  - spec/lib/scm/git_spec.rb
164
170
  - spec/spec_helper.rb