tinyci 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47b37576bb6ac9c337d92fa29e1967320e9ca355
4
- data.tar.gz: 3e68ee67c57669dcc988ebc90e68a0788661fffc
3
+ metadata.gz: 5531654099be53cbad1500af1c180555e4453396
4
+ data.tar.gz: 4f90146f6f2aaf50b78fa162a363a8d80666f810
5
5
  SHA512:
6
- metadata.gz: 38eebd3406dfc95334e81af417ceeb5d0cf1e3d5b20c3122a038ba53d11fc6f2425e169f94ce7e28b64fee00ed31d65e33a238eb4772523457324efd82646e03
7
- data.tar.gz: a0a96088a883f5f7d8a5d9f93e7aaa7ede84b7419215e1bf6e85459e6e59b1f54c72bc272274edf477461e1cbcf1c9d05953e08cf838b109b49171136d9bff73
6
+ metadata.gz: 697dbb6e5e32e9bede86917e1466093180c87a0a327946ffcc12fab7fcc7c06aad91be64d11004cccef9f127a96dd892bdfbaf1783dce2ca233eb5b779efd355
7
+ data.tar.gz: 48097b1dc7213415c2d462dc055beb50ab77b6467f71f488dd12e34870ec59f7e2ce4abb41e00d5a135b2c8a0eafff37b69221c409c39aef2058448c67f9d17b
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ spec/support/repos/*
5
5
  spec/examples.txt
6
6
  tmp
7
7
  pkg
8
+ coverage
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Metrics/LineLength:
5
+ Max: 100
6
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ 0.2.0 - October 13, 2018
2
+ Add hooks
3
+ 0.1.2 - August 16, 2018
4
+ Make runner tests platform independent
5
+ Remove unneccesary concurrency from Subprocesses#execute_stream
6
+ 0.1.1 - May 09, 2018
7
+ Update executors to use the shell so relative paths are resolved properly
8
+ 0.1.0 - May 01, 2018
9
+ Initial release
data/Gemfile CHANGED
@@ -1,13 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  source "https://rubygems.org"
3
3
 
4
- gem 'pry-byebug'
5
- # gem 'byebug'
6
- # gem 'pry-doc'
7
- gem 'pry'
8
- gem 'guard-rspec'
9
- gem 'fuubar'
10
- gem 'rspec-nc'
11
- gem 'terminal-notifier', '1.7.1'
12
-
13
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,16 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tinyci (0.1.2)
4
+ tinyci (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ast (2.4.0)
9
10
  awesome_print (1.8.0)
10
11
  barrier (1.0.2)
11
12
  byebug (9.1.0)
12
13
  coderay (1.1.2)
13
14
  diff-lcs (1.3)
15
+ docile (1.3.1)
14
16
  ffi (1.9.18)
15
17
  formatador (0.2.5)
16
18
  fuubar (2.2.0)
@@ -30,6 +32,8 @@ GEM
30
32
  guard (~> 2.1)
31
33
  guard-compat (~> 1.1)
32
34
  rspec (>= 2.99.0, < 4.0)
35
+ jaro_winkler (1.5.1)
36
+ json (2.1.0)
33
37
  listen (3.1.5)
34
38
  rb-fsevent (~> 0.9, >= 0.9.4)
35
39
  rb-inotify (~> 0.9, >= 0.9.7)
@@ -40,38 +44,57 @@ GEM
40
44
  notiffany (0.1.1)
41
45
  nenv (~> 0.1)
42
46
  shellany (~> 0.0)
47
+ parallel (1.12.1)
48
+ parser (2.5.1.2)
49
+ ast (~> 2.4.0)
50
+ powerpack (0.1.2)
43
51
  pry (0.11.1)
44
52
  coderay (~> 1.1.0)
45
53
  method_source (~> 0.9.0)
46
54
  pry-byebug (3.5.0)
47
55
  byebug (~> 9.1)
48
56
  pry (~> 0.10)
57
+ rainbow (3.0.0)
49
58
  rake (12.1.0)
50
59
  rb-fsevent (0.10.2)
51
60
  rb-inotify (0.9.10)
52
61
  ffi (>= 0.5.0, < 2)
53
62
  redcarpet (3.4.0)
54
- rspec (3.6.0)
55
- rspec-core (~> 3.6.0)
56
- rspec-expectations (~> 3.6.0)
57
- rspec-mocks (~> 3.6.0)
58
- rspec-core (3.6.0)
59
- rspec-support (~> 3.6.0)
60
- rspec-expectations (3.6.0)
63
+ rspec (3.8.0)
64
+ rspec-core (~> 3.8.0)
65
+ rspec-expectations (~> 3.8.0)
66
+ rspec-mocks (~> 3.8.0)
67
+ rspec-core (3.8.0)
68
+ rspec-support (~> 3.8.0)
69
+ rspec-expectations (3.8.1)
61
70
  diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.6.0)
63
- rspec-mocks (3.6.0)
71
+ rspec-support (~> 3.8.0)
72
+ rspec-mocks (3.8.0)
64
73
  diff-lcs (>= 1.2.0, < 2.0)
65
- rspec-support (~> 3.6.0)
74
+ rspec-support (~> 3.8.0)
66
75
  rspec-nc (0.3.0)
67
76
  rspec (>= 3)
68
77
  terminal-notifier (>= 1.4)
69
- rspec-support (3.6.0)
78
+ rspec-support (3.8.0)
79
+ rubocop (0.59.2)
80
+ jaro_winkler (~> 1.5.1)
81
+ parallel (~> 1.10)
82
+ parser (>= 2.5, != 2.5.1.1)
83
+ powerpack (~> 0.1)
84
+ rainbow (>= 2.2.2, < 4.0)
85
+ ruby-progressbar (~> 1.7)
86
+ unicode-display_width (~> 1.0, >= 1.0.1)
70
87
  ruby-progressbar (1.8.1)
71
88
  ruby_dep (1.5.0)
72
89
  shellany (0.0.1)
90
+ simplecov (0.16.1)
91
+ docile (~> 1.1)
92
+ json (>= 1.8, < 3)
93
+ simplecov-html (~> 0.10.0)
94
+ simplecov-html (0.10.2)
73
95
  terminal-notifier (1.7.1)
74
96
  thor (0.20.0)
97
+ unicode-display_width (1.4.0)
75
98
  yard (0.9.12)
76
99
 
77
100
  PLATFORMS
@@ -89,9 +112,11 @@ DEPENDENCIES
89
112
  redcarpet
90
113
  rspec
91
114
  rspec-nc
115
+ rubocop
116
+ simplecov
92
117
  terminal-notifier (= 1.7.1)
93
118
  tinyci!
94
119
  yard
95
120
 
96
121
  BUNDLED WITH
97
- 1.16.2
122
+ 1.16.3
data/Guardfile CHANGED
@@ -2,6 +2,6 @@ interactor :off
2
2
 
3
3
  guard :rspec, cmd: "bundle exec rspec", all_after_pass: true, all_on_start: true do
4
4
  watch(%r{^lib\/tinyci\/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
5
- # watch(%r{spec\/support\/.+}) { "spec" }
5
+ watch(%r{spec\/support\/.+}) { "spec" }
6
6
  watch(%r{^spec\/.+_spec\.rb$})
7
7
  end
data/README.md CHANGED
@@ -69,6 +69,44 @@ It is of course possible that commits might be pushed consistently faster than t
69
69
 
70
70
  If you look in the source code you will also find `RktBuilder` and `RktTester`, these were experimental attempts to integrate the Rkt container runtime. They are not recommended for use but are left for users to examine.
71
71
 
72
+ #### Hooks
73
+
74
+ TinyCI supports hooks/callbacks, much like git itself. Here is the order of execution:
75
+
76
+ ```
77
+ * clean
78
+ * export
79
+
80
+ before_build
81
+
82
+ * build
83
+
84
+ after_build
85
+ after_build_success
86
+ after_build_failure
87
+
88
+ before_test
89
+
90
+ * test
91
+
92
+ after_test
93
+ after_test_success
94
+ after_test_failure
95
+ ```
96
+
97
+ `*` indicates an actual phase of TinyCI's execution, the rest are callbacks.
98
+
99
+ Note that the `before_build` and `before_test` hooks will halt the processing of the commit completely if they fail (ie. return a status > 0)
100
+
101
+ To setup hooks, define a section like this in your config file:
102
+
103
+ ```
104
+ hooker:
105
+ class: ScriptHooker
106
+ config:
107
+ after_build: ./after_build.sh
108
+ ```
109
+
72
110
  #### Logging/Output
73
111
 
74
112
  TinyCI is executed in a `post-update` git hook. As such, the output is shown to the user as part of the local call to `git push`. Once the TinyCI hook is running, the local git process can be freely killed if the user does not wish to watch the output - this will not affect the remote execution of TinyCI.
@@ -77,8 +115,6 @@ As well as logging to stdout, the TinyCI process writes a `tinyci.log` file in e
77
115
 
78
116
  #### Limitations/TODO
79
117
 
80
- * TinyCI currently has no support for running a script on success or failure of the test script. This feature would allow for notifications to be sent, eg. slack bots, email, etc. It would also enable TinyCI to act as part of an automated deployment system.
81
-
82
118
  * As mentioned above, when TinyCI is executed against a commit without a configuration file, it exports the whole directory, finds the config file to be missing, then deletes the export. As such, when TinyCI installed against an existing project with many commits, this process will happen for every commit, wasting a lot of time and churning the disk.
83
119
  Instead, it would be preferable to check for the config file before doing the export, with a call to `git-cat-file`. An additional way to handle this would be to prevent the processing of commits created prior to the installation of TinyCI, perhaps by marking them with git-notes at install time, or by checking the creation date of the hook file.
84
120
 
@@ -0,0 +1,59 @@
1
+ require 'tinyci/executor'
2
+
3
+ module TinyCI
4
+ module Hookers
5
+ class ScriptHooker < TinyCI::Executor
6
+ # All the hooks
7
+ HOOKS = %w{
8
+ before_build
9
+
10
+ after_build
11
+ after_build_success
12
+ after_build_failure
13
+
14
+ before_test
15
+
16
+ after_test
17
+ after_test_success
18
+ after_test_failure
19
+ }
20
+
21
+ # Those hooks that will halt exectution if they fail
22
+ BLOCKING_HOOKS = %w{
23
+ before_build
24
+ before_test
25
+ }
26
+
27
+ HOOKS.each do |hook|
28
+ define_method hook+"_present?" do
29
+ @config.key? hook.to_sym
30
+ end
31
+
32
+ define_method hook+"!" do
33
+ return unless send("#{hook}_present?")
34
+
35
+ log_info "executing #{hook} hook..."
36
+ begin
37
+ execute_stream(script_location(hook), label: hook, pwd: @config[:target])
38
+
39
+ return true
40
+ rescue SubprocessError => e
41
+ if BLOCKING_HOOKS.include? hook
42
+ raise e if ENV['TINYCI_ENV'] == 'test'
43
+
44
+ log_error e
45
+
46
+ return false
47
+ else
48
+ return true
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ def script_location(hook)
55
+ ['/bin/sh', '-c', "'#{@config[hook.to_sym]}'"]
56
+ end
57
+ end
58
+ end
59
+ end
data/lib/tinyci/runner.rb CHANGED
@@ -11,6 +11,7 @@ require 'tinyci/testers/rkt_tester'
11
11
 
12
12
  require 'tinyci/builders/script_builder'
13
13
  require 'tinyci/testers/script_tester'
14
+ require 'tinyci/hookers/script_hooker'
14
15
 
15
16
  require 'fileutils'
16
17
 
@@ -24,7 +25,7 @@ module TinyCI
24
25
  include GitUtils
25
26
  include Logging
26
27
 
27
- attr_accessor :builder, :tester
28
+ attr_accessor :builder, :tester, :hooker
28
29
 
29
30
  # Constructor, allows injection of generic configuration params.
30
31
  #
@@ -69,29 +70,77 @@ module TinyCI
69
70
  end
70
71
  @builder ||= instantiate_builder
71
72
  @tester ||= instantiate_tester
73
+ @hooker ||= instantiate_hooker
72
74
 
73
75
  log_info "Building..."
74
- @builder.build
76
+ run_hook! :before_build
77
+ begin
78
+ @builder.build
79
+ run_hook! :after_build_success
80
+ rescue => e
81
+ run_hook! :after_build_failure
82
+
83
+ raise e if ENV['TINYCI_ENV'] == 'test'
84
+
85
+ log_error e
86
+ log_error e.backtrace
87
+
88
+ return false
89
+ ensure
90
+ run_hook! :after_build
91
+ end
75
92
 
76
- log_info "Testing..."
77
- @tester.test
78
93
 
79
- log_info "Finished #{@commit}"
80
- rescue => e
94
+ log_info "Testing..."
95
+ run_hook! :before_test
96
+ begin
97
+ @tester.test
98
+ rescue => e
99
+ run_hook! :after_test_failure
100
+
81
101
  raise e if ENV['TINYCI_ENV'] == 'test'
82
102
 
83
103
  log_error e
84
104
  log_error e.backtrace
105
+
106
+ return false
107
+ ensure
108
+ run_hook! :after_test
109
+ end
110
+
111
+ run_hook! :after_test_success
112
+
113
+
114
+ log_info "Finished #{@commit}"
115
+ rescue => e
116
+ raise e if ENV['TINYCI_ENV'] == 'test'
117
+
118
+ log_error e
119
+ log_error e.backtrace
85
120
  return false
86
- ensure
87
-
88
121
  end
89
122
 
90
123
  true
91
124
  end
92
125
 
126
+ # Build the absolute target path
127
+ def target_path
128
+ File.absolute_path("#{@working_dir}/builds/#{@time.to_i}_#{@commit}/")
129
+ end
130
+
131
+ # Build the export path
132
+ def export_path
133
+ File.join(target_path, 'export')
134
+ end
135
+
93
136
  private
94
137
 
138
+ def run_hook!(name)
139
+ return unless @hooker
140
+
141
+ @hooker.send("#{name}!")
142
+ end
143
+
95
144
  # Creates log file if it doesnt exist
96
145
  def setup_log
97
146
  return unless @logger.is_a? MultiLogger
@@ -115,6 +164,14 @@ module TinyCI
115
164
  klass.new(@config[:tester][:config].merge(target: export_path), logger: @logger)
116
165
  end
117
166
 
167
+ # Instantiate the Hooker object according to the class named in the config
168
+ def instantiate_hooker
169
+ return nil unless @config[:hooker].is_a? Hash
170
+
171
+ klass = TinyCI::Hookers.const_get(@config[:hooker][:class])
172
+ klass.new(@config[:hooker][:config].merge(target: export_path), logger: @logger)
173
+ end
174
+
118
175
  # Instantiate the {Config} object from the `.tinyci.yml` file in the exported directory
119
176
  def load_config
120
177
  @config ||= Config.new(working_dir: export_path)
@@ -125,16 +182,6 @@ module TinyCI
125
182
  Time.at execute(git_cmd('show', '-s', '--format=%ct', @commit)).to_i
126
183
  end
127
184
 
128
- # Build the absolute target path
129
- def target_path
130
- File.absolute_path("#{@working_dir}/builds/#{@time.to_i}_#{@commit}/")
131
- end
132
-
133
- # Build the export path
134
- def export_path
135
- File.join(target_path, 'export')
136
- end
137
-
138
185
  def ensure_path(path)
139
186
  execute 'mkdir', '-p', path
140
187
  end
@@ -89,7 +89,7 @@ module TinyCI
89
89
  attr_reader :status
90
90
  attr_reader :command
91
91
 
92
- def initialize(label, command, status, message = "`#{label || command}` failed with code #{status.to_i}")
92
+ def initialize(label, command, status, message = "`#{label || command}` failed with status #{status.exitstatus}")
93
93
  @status = status
94
94
  @command = command
95
95
  super(message)
@@ -1,3 +1,3 @@
1
1
  module TinyCI
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/tinyci.gemspec CHANGED
@@ -29,9 +29,9 @@ Gem::Specification.new do |spec|
29
29
  end
30
30
  spec.executables = ["tinyci"]
31
31
  spec.require_paths = ["lib"]
32
-
32
+
33
33
  LOGO = File.read(File.expand_path('lib/tinyci/logo.txt', __dir__))
34
-
34
+
35
35
  spec.post_install_message = (LOGO % TinyCI::VERSION) + "\n"
36
36
 
37
37
  spec.add_development_dependency "bundler", "~> 1.14"
@@ -41,4 +41,12 @@ Gem::Specification.new do |spec|
41
41
  spec.add_development_dependency 'rake'
42
42
  spec.add_development_dependency 'yard'
43
43
  spec.add_development_dependency 'redcarpet'
44
+ spec.add_development_dependency 'pry-byebug'
45
+ spec.add_development_dependency 'pry'
46
+ spec.add_development_dependency 'guard-rspec'
47
+ spec.add_development_dependency 'fuubar'
48
+ spec.add_development_dependency 'simplecov'
49
+ spec.add_development_dependency 'rspec-nc'
50
+ spec.add_development_dependency 'terminal-notifier', '1.7.1'
51
+ spec.add_development_dependency 'rubocop'
44
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinyci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Davies
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-16 00:00:00.000000000 Z
11
+ date: 2018-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,118 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: fuubar
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rspec-nc
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: terminal-notifier
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '='
200
+ - !ruby/object:Gem::Version
201
+ version: 1.7.1
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '='
207
+ - !ruby/object:Gem::Version
208
+ version: 1.7.1
209
+ - !ruby/object:Gem::Dependency
210
+ name: rubocop
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
111
223
  description: A minimal Continuous Integration system, written in ruby, powered by
112
224
  git
113
225
  email:
@@ -119,8 +231,10 @@ extra_rdoc_files: []
119
231
  files:
120
232
  - ".gitignore"
121
233
  - ".rspec"
234
+ - ".rubocop.yml"
122
235
  - ".ruby-version"
123
236
  - ".yardopts"
237
+ - CHANGELOG.md
124
238
  - Gemfile
125
239
  - Gemfile.lock
126
240
  - Guardfile
@@ -136,6 +250,7 @@ files:
136
250
  - lib/tinyci/config.rb
137
251
  - lib/tinyci/executor.rb
138
252
  - lib/tinyci/git_utils.rb
253
+ - lib/tinyci/hookers/script_hooker.rb
139
254
  - lib/tinyci/installer.rb
140
255
  - lib/tinyci/logging.rb
141
256
  - lib/tinyci/logo.txt
@@ -156,7 +271,7 @@ metadata:
156
271
  allowed_push_host: https://rubygems.org
157
272
  post_install_message: " _____ _ _____ _____\n/__ (_)_ __ _ _ /
158
273
  ___/ /_ _/\n | || | '_ \\| | | |/ / / /\n | || | | | | |_| / /___/\\/ /_
159
- \ \n |_||_|_| |_|\\__, \\____/\\____/ 0.1.2\n |___/\n\n"
274
+ \ \n |_||_|_| |_|\\__, \\____/\\____/ 0.2.0\n |___/\n\n"
160
275
  rdoc_options: []
161
276
  require_paths:
162
277
  - lib