ops_team 0.10.4 → 0.11.0.pre
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 +4 -4
- data/lib/dependency.rb +14 -5
- data/lib/executor.rb +29 -0
- data/lib/hook_handler.rb +32 -0
- data/lib/ops.rb +12 -2
- data/ops_team.gemspec +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3a9e4bdba561a28f5b282b09ab717b8445053d68ba715337df0bf7bd294abec
|
4
|
+
data.tar.gz: 7fc1110839291c7912c376597d32a4fcb048952e734dc586c2bf40476a53ec93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97707fa40c98bae65bc8919da37fd2a366090213fb8fd260339c9489da725779f3d763e06f708d51f70fb03273fa99cb4596f44d663c935515f4b82d3a9d94cf
|
7
|
+
data.tar.gz: 9907f1bcc2b41a4ec0b5e119ffad24c443d76e726b6aca9bec1529d8be6576889a362fd8f56d9cc123fcca8bbe242f30c17b6bf39fb4684e7b745b716532cc28
|
data/lib/dependency.rb
CHANGED
@@ -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
|
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
|
-
@
|
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
|
-
@
|
55
|
-
@
|
63
|
+
@executor = Executor.new(cmd)
|
64
|
+
@executor.execute
|
56
65
|
|
57
|
-
success?
|
66
|
+
@executor.success?
|
58
67
|
end
|
59
68
|
end
|
data/lib/executor.rb
ADDED
@@ -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
|
data/lib/hook_handler.rb
ADDED
@@ -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
|
-
|
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
|
data/ops_team.gemspec
CHANGED
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.
|
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:
|
198
|
+
version: 1.3.1
|
197
199
|
requirements: []
|
198
200
|
rubygems_version: 3.0.3
|
199
201
|
signing_key:
|