cilite 0.2.0 → 0.2.1
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.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/cilite +1 -1
- data/lib/cilite.rb +2 -0
- data/lib/cilite/{process.rb → build.rb} +6 -1
- data/lib/cilite/runner.rb +38 -19
- data/test/{tester/test_process.rb → cilite/test_build.rb} +2 -2
- data/test/{tester → cilite}/test_log.rb +0 -0
- data/test/cilite/test_runner.rb +32 -0
- metadata +18 -11
- data/lib/cilite/checker.rb +0 -27
- data/test/tester/test_checker.rb +0 -27
- data/test/tester/test_runner.rb +0 -28
data/Rakefile
CHANGED
@@ -15,6 +15,7 @@ begin
|
|
15
15
|
gem.add_dependency 'kvs'
|
16
16
|
gem.add_dependency 'sinatra'
|
17
17
|
gem.add_dependency 'choice'
|
18
|
+
gem.add_dependency 'termcolor', '>= 1.2.0'
|
18
19
|
end
|
19
20
|
rescue LoadError
|
20
21
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/bin/cilite
CHANGED
data/lib/cilite.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module CiLite
|
2
|
-
class
|
2
|
+
class Build < Struct.new(:status, :pid)
|
3
3
|
attr_reader :command, :status, :pid, :output
|
4
4
|
|
5
5
|
def initialize(command)
|
@@ -13,6 +13,11 @@ module CiLite
|
|
13
13
|
end
|
14
14
|
@status = $?.exitstatus.to_i
|
15
15
|
rescue Exception => e
|
16
|
+
@status = -1
|
17
|
+
end
|
18
|
+
|
19
|
+
def success?
|
20
|
+
status == 0
|
16
21
|
end
|
17
22
|
|
18
23
|
def to_hash
|
data/lib/cilite/runner.rb
CHANGED
@@ -4,12 +4,14 @@ module CiLite
|
|
4
4
|
self.new(options).start
|
5
5
|
end
|
6
6
|
|
7
|
-
attr_reader :
|
8
|
-
attr_accessor :
|
7
|
+
attr_reader :branch, :command, :interval
|
8
|
+
attr_accessor :started
|
9
9
|
|
10
10
|
def initialize(options)
|
11
|
-
|
12
|
-
@
|
11
|
+
options = (KVS['config'] || {}).merge(options)
|
12
|
+
@branch = options[:branch]
|
13
|
+
@command = options[:command]
|
14
|
+
@interval = options[:interval]
|
13
15
|
end
|
14
16
|
|
15
17
|
def start
|
@@ -19,9 +21,9 @@ module CiLite
|
|
19
21
|
begin
|
20
22
|
test_if_updated
|
21
23
|
rescue Exception => e
|
22
|
-
puts "
|
24
|
+
puts "<red>#{TermColor.escape(e.to_s)}</red>".termcolor
|
23
25
|
ensure
|
24
|
-
sleep
|
26
|
+
sleep interval
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
@@ -29,26 +31,43 @@ module CiLite
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def test_if_updated
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
hash = git_update
|
35
|
+
unless KVS[hash]
|
36
|
+
test(hash)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def git_update
|
41
|
+
if system("git fetch origin && git reset --hard origin/#{branch}")
|
42
|
+
hash = `git rev-parse origin/#{branch}`.chomp
|
43
|
+
raise "failed to get HEAD commit of origin/#{branch}" unless $? == 0
|
44
|
+
hash
|
45
|
+
else
|
46
|
+
raise "failed to update origin/#{branch}"
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
42
50
|
def test(hash)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
Log[hash] =
|
51
|
+
puts "start: #{hash}", command
|
52
|
+
|
53
|
+
build = Build.new(command)
|
54
|
+
build.start
|
55
|
+
Log[hash] = build.to_hash.merge(
|
48
56
|
:hash => hash,
|
49
57
|
:created_at => Time.now,
|
50
|
-
:branch =>
|
58
|
+
:branch => branch
|
51
59
|
)
|
60
|
+
|
61
|
+
output_result(hash, build)
|
62
|
+
end
|
63
|
+
|
64
|
+
def output_result(hash, build)
|
65
|
+
puts build.output
|
66
|
+
if build.success?
|
67
|
+
puts "<green>[Success!] #{hash}</green>".termcolor
|
68
|
+
else
|
69
|
+
puts "<red>[Failure!] #{hash}</red>".termcolor
|
70
|
+
end
|
52
71
|
end
|
53
72
|
end
|
54
73
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'helper'
|
2
2
|
require 'tmpdir'
|
3
3
|
|
4
|
-
class
|
4
|
+
class TestBuild < Test::Unit::TestCase
|
5
5
|
context 'main' do
|
6
6
|
setup do
|
7
|
-
@test = CiLite::
|
7
|
+
@test = CiLite::Build.new('foo')
|
8
8
|
end
|
9
9
|
|
10
10
|
should 'pass the test' do
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRunner < Test::Unit::TestCase
|
4
|
+
context 'main' do
|
5
|
+
setup do
|
6
|
+
@runner = CiLite::Runner.new({:branch => 'foo', :command => 'bar', :interval => 10})
|
7
|
+
end
|
8
|
+
|
9
|
+
should 'test if updated' do
|
10
|
+
test_build_stub = Object.new
|
11
|
+
mock(test_build_stub).start
|
12
|
+
stub(test_build_stub).to_hash { {:foo => :bar} }
|
13
|
+
stub(test_build_stub).status { 0 }
|
14
|
+
stub(test_build_stub).output { 'output' }
|
15
|
+
stub(test_build_stub).success? { true }
|
16
|
+
mock(CiLite::Build).new(@runner.command) { test_build_stub }
|
17
|
+
mock(CiLite::Log).[]=.with_any_args
|
18
|
+
stub(Time).now { 'now' }
|
19
|
+
|
20
|
+
$stdout = StringIO.new
|
21
|
+
@runner.test('XXXX')
|
22
|
+
$stdout = STDOUT
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'not test if not updated' do
|
26
|
+
KVS['foo'] = 'bar'
|
27
|
+
stub(@runner).git_update { 'foo' }
|
28
|
+
mock(@runner).test('foo').times(0)
|
29
|
+
@runner.test_if_updated
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cilite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jugyo
|
@@ -62,6 +62,16 @@ dependencies:
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: "0"
|
64
64
|
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: termcolor
|
67
|
+
type: :runtime
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 1.2.0
|
74
|
+
version:
|
65
75
|
description: CiLite is lite CI tool for project that use git.
|
66
76
|
email: jugyo.org@gmail.com
|
67
77
|
executables:
|
@@ -79,9 +89,8 @@ files:
|
|
79
89
|
- VERSION
|
80
90
|
- bin/cilite
|
81
91
|
- lib/cilite.rb
|
82
|
-
- lib/cilite/
|
92
|
+
- lib/cilite/build.rb
|
83
93
|
- lib/cilite/log.rb
|
84
|
-
- lib/cilite/process.rb
|
85
94
|
- lib/cilite/runner.rb
|
86
95
|
- lib/cilite/server.rb
|
87
96
|
- lib/cilite/views/index.haml
|
@@ -89,13 +98,12 @@ files:
|
|
89
98
|
- lib/cilite/views/show.haml
|
90
99
|
- lib/cilite/views/styles.css
|
91
100
|
- lib/cilite/views/styles.sass
|
101
|
+
- test/cilite/test_build.rb
|
102
|
+
- test/cilite/test_log.rb
|
103
|
+
- test/cilite/test_runner.rb
|
92
104
|
- test/helper.rb
|
93
105
|
- test/test_cilite.rb
|
94
106
|
- test/tester.ru
|
95
|
-
- test/tester/test_checker.rb
|
96
|
-
- test/tester/test_log.rb
|
97
|
-
- test/tester/test_process.rb
|
98
|
-
- test/tester/test_runner.rb
|
99
107
|
has_rdoc: true
|
100
108
|
homepage: http://github.com/jugyo/cilite
|
101
109
|
licenses: []
|
@@ -125,9 +133,8 @@ signing_key:
|
|
125
133
|
specification_version: 3
|
126
134
|
summary: CiLite is lite CI tool.
|
127
135
|
test_files:
|
136
|
+
- test/cilite/test_build.rb
|
137
|
+
- test/cilite/test_log.rb
|
138
|
+
- test/cilite/test_runner.rb
|
128
139
|
- test/helper.rb
|
129
140
|
- test/test_cilite.rb
|
130
|
-
- test/tester/test_checker.rb
|
131
|
-
- test/tester/test_log.rb
|
132
|
-
- test/tester/test_process.rb
|
133
|
-
- test/tester/test_runner.rb
|
data/lib/cilite/checker.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module CiLite
|
2
|
-
class Checker
|
3
|
-
attr_reader :branch
|
4
|
-
attr_accessor :last_hash
|
5
|
-
|
6
|
-
def initialize(branch)
|
7
|
-
@branch = branch
|
8
|
-
end
|
9
|
-
|
10
|
-
def if_updated(&block)
|
11
|
-
update
|
12
|
-
hash = head
|
13
|
-
if KVS['HEAD'] != hash
|
14
|
-
block.call(hash)
|
15
|
-
KVS['HEAD'] = self.last_hash = hash
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def update
|
20
|
-
`git fetch origin && git reset --hard origin/#{branch}`
|
21
|
-
end
|
22
|
-
|
23
|
-
def head
|
24
|
-
`git rev-parse origin/#{branch}`.chomp
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/test/tester/test_checker.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'fakefs'
|
3
|
-
|
4
|
-
class TestChecker < Test::Unit::TestCase
|
5
|
-
context 'main' do
|
6
|
-
setup do
|
7
|
-
KVS.dir = 'foo'
|
8
|
-
KVS['HEAD'] = ''
|
9
|
-
@checker = CiLite::Checker.new('master')
|
10
|
-
stub(@checker).update
|
11
|
-
end
|
12
|
-
|
13
|
-
should 'check updated' do
|
14
|
-
stub(@checker).head { 'foo' }
|
15
|
-
block = lambda {}
|
16
|
-
mock(block).call('foo')
|
17
|
-
# NOTE: rr が思ったような動作をしてくれないのでこんな書き方になってます...
|
18
|
-
@checker.if_updated do |hash|
|
19
|
-
block.call(hash)
|
20
|
-
end
|
21
|
-
mock(block).call('foo').times(0)
|
22
|
-
@checker.if_updated do |hash|
|
23
|
-
block.call(hash)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/test/tester/test_runner.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestRunner < Test::Unit::TestCase
|
4
|
-
context 'main' do
|
5
|
-
setup do
|
6
|
-
@runner = CiLite::Runner.new({:branch => 'foo', :test_command => 'bar', :interval => 10})
|
7
|
-
end
|
8
|
-
|
9
|
-
should 'Runner.new' do
|
10
|
-
assert_equal(@runner.config[:branch], @runner.checker.branch)
|
11
|
-
end
|
12
|
-
|
13
|
-
should 'test if updated' do
|
14
|
-
test_process_stub = Object.new
|
15
|
-
mock(test_process_stub).start
|
16
|
-
stub(test_process_stub).to_hash { {:foo => :bar} }
|
17
|
-
stub(test_process_stub).status { 0 }
|
18
|
-
stub(test_process_stub).output { 'output' }
|
19
|
-
mock(CiLite::Process).new(@runner.config[:test_command]) { test_process_stub }
|
20
|
-
mock(CiLite::Log).[]=.with_any_args
|
21
|
-
stub(Time).now { 'now' }
|
22
|
-
|
23
|
-
$stdout = StringIO.new
|
24
|
-
@runner.test('XXXX')
|
25
|
-
$stdout = STDOUT
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|