ops_team 0.10.4 → 0.11.0.pre

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
  SHA256:
3
- metadata.gz: 6f2b052b1a1dfd1e4cc30acca43495993be28499f2b1fa9eb8e587da57931d3a
4
- data.tar.gz: 27b21a20f77b1a0bf416f3d3a56be4142baa0b7553b3161e0b916da61b0f3422
3
+ metadata.gz: d3a9e4bdba561a28f5b282b09ab717b8445053d68ba715337df0bf7bd294abec
4
+ data.tar.gz: 7fc1110839291c7912c376597d32a4fcb048952e734dc586c2bf40476a53ec93
5
5
  SHA512:
6
- metadata.gz: 67f1395a225c91a2ee619ecd1eb6eb26e16ca05bafb5f82916508875a7b58c0eafe40be120f83ec2b55a42aa3695bcb91cf1b1ca5973c521029bd377f9c02c86
7
- data.tar.gz: cf644c0878ce56c6f11c6e45719044a72aa71a566bca492c5f51966436ef25010ec19dd6c5d8f5a0f4cd408177a114975f4e3160b27977bda3360db4ce456282
6
+ metadata.gz: 97707fa40c98bae65bc8919da37fd2a366090213fb8fd260339c9489da725779f3d763e06f708d51f70fb03273fa99cb4596f44d663c935515f4b82d3a9d94cf
7
+ data.tar.gz: 9907f1bcc2b41a4ec0b5e119ffad24c443d76e726b6aca9bec1529d8be6576889a362fd8f56d9cc123fcca8bbe242f30c17b6bf39fb4684e7b745b716532cc28
@@ -4,11 +4,12 @@ require 'open3'
4
4
  require 'English'
5
5
 
6
6
  require 'output'
7
+ require 'executor'
7
8
 
8
9
  class Dependency
9
10
  DESCRIPTION_TYPE_WIDTH = 8
10
11
 
11
- attr_reader :name, :output, :exit_code
12
+ attr_reader :name
12
13
 
13
14
  def initialize(name)
14
15
  @name = name
@@ -45,15 +46,23 @@ class Dependency
45
46
  end
46
47
 
47
48
  def success?
48
- @exit_code.nil? ? true : @exit_code.zero?
49
+ @executor&.success?
50
+ end
51
+
52
+ def output
53
+ @executor&.output
54
+ end
55
+
56
+ def exit_code
57
+ @executor&.exit_code
49
58
  end
50
59
 
51
60
  private
52
61
 
53
62
  def execute(cmd)
54
- @output, status = Open3.capture2e(cmd)
55
- @exit_code = status.exitstatus
63
+ @executor = Executor.new(cmd)
64
+ @executor.execute
56
65
 
57
- success?
66
+ @executor.success?
58
67
  end
59
68
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Executor
4
+ attr_reader :output, :exit_code
5
+
6
+ class << self
7
+ def execute(command)
8
+ @output, status = Open3.capture2e(command)
9
+ @exit_code = status.exitstatus
10
+
11
+ [@output, @exit_code]
12
+ end
13
+ end
14
+
15
+ def initialize(command)
16
+ @command = command
17
+ end
18
+
19
+ def execute
20
+ @output, status = Open3.capture2e(@command)
21
+ @exit_code = status.exitstatus
22
+
23
+ success?
24
+ end
25
+
26
+ def success?
27
+ @exit_code.nil? ? true : @exit_code.zero?
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ class HookHandler
4
+ class HookConfigError < StandardError; end
5
+ class HookExecError < StandardError; end
6
+
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def do_hooks(name)
12
+ raise HookConfigError, "'hooks.#{name}' must be a list" unless hooks(name).is_a?(Array)
13
+
14
+ execute_hooks(name)
15
+ end
16
+
17
+ private
18
+
19
+ def hooks(name)
20
+ @config.dig("hooks", name) || []
21
+ end
22
+
23
+ def execute_hooks(name)
24
+ hooks(name).each do |hook|
25
+ output, exit_code = Executor.execute(hook)
26
+
27
+ next if exit_code.zero?
28
+
29
+ raise HookExecError, "#{name} hook '#{hook}' failed with exit code #{exit_code}:\n#{output}"
30
+ end
31
+ end
32
+ end
data/lib/ops.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  require 'yaml'
5
5
  require 'require_all'
6
6
 
7
+ require 'hook_handler'
7
8
  require 'action'
8
9
  require 'output'
9
10
  require 'options'
@@ -54,8 +55,7 @@ class Ops
54
55
  end
55
56
 
56
57
  def run_action
57
- environment.set_variables
58
- AppConfig.load
58
+ do_before_run_action
59
59
 
60
60
  return builtin.run if builtin
61
61
 
@@ -66,6 +66,16 @@ class Ops
66
66
  exit(ERROR_LOADING_APP_CONFIG_EXIT_CODE)
67
67
  end
68
68
 
69
+ def do_before_run_action
70
+ environment.set_variables
71
+ AppConfig.load
72
+ hook_handler.do_hooks("before")
73
+ end
74
+
75
+ def hook_handler
76
+ @hook_handler ||= HookHandler.new(config)
77
+ end
78
+
69
79
  def builtin
70
80
  @builtin ||= Builtin.class_for(name: @action_name).new(@args, config)
71
81
  rescue NameError
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.10.4'
5
+ s.version = '0.11.0.pre'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ops_team
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.11.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com
@@ -170,6 +170,8 @@ files:
170
170
  - lib/dependencies/sshkey.rb
171
171
  - lib/dependency.rb
172
172
  - lib/environment.rb
173
+ - lib/executor.rb
174
+ - lib/hook_handler.rb
173
175
  - lib/ops.rb
174
176
  - lib/options.rb
175
177
  - lib/output.rb
@@ -191,9 +193,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
193
  version: '2.5'
192
194
  required_rubygems_version: !ruby/object:Gem::Requirement
193
195
  requirements:
194
- - - ">="
196
+ - - ">"
195
197
  - !ruby/object:Gem::Version
196
- version: '0'
198
+ version: 1.3.1
197
199
  requirements: []
198
200
  rubygems_version: 3.0.3
199
201
  signing_key: