ops_team 0.11.0.pre → 0.12.3

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
  SHA256:
3
- metadata.gz: d3a9e4bdba561a28f5b282b09ab717b8445053d68ba715337df0bf7bd294abec
4
- data.tar.gz: 7fc1110839291c7912c376597d32a4fcb048952e734dc586c2bf40476a53ec93
3
+ metadata.gz: 444384ee0931455838357c9bc2f720534e8fbda90d5d27a15c35b313cf676b4e
4
+ data.tar.gz: 03ff8c264a9083987aac65d9a7ba78fdb8d118e757599c66267725178b8fc809
5
5
  SHA512:
6
- metadata.gz: 97707fa40c98bae65bc8919da37fd2a366090213fb8fd260339c9489da725779f3d763e06f708d51f70fb03273fa99cb4596f44d663c935515f4b82d3a9d94cf
7
- data.tar.gz: 9907f1bcc2b41a4ec0b5e119ffad24c443d76e726b6aca9bec1529d8be6576889a362fd8f56d9cc123fcca8bbe242f30c17b6bf39fb4684e7b745b716532cc28
6
+ metadata.gz: f596c660d5b7943258c3615a603f36f74ea5d98488d9171562c75593f3e5d5cbe93a349d687a417649dcb0be40de13c9c7d3c33c94b3d7686a43c3f2c94ea2cb
7
+ data.tar.gz: 486531d3b6c027986cde18d88f3d43e6ffc7db44b4688a8528ccd33b1b0dcb0b883ff6b8048f0b168d3b9fa3d58d8f018722c12a95cdb3edf3e8820c5c3e4b02
@@ -32,6 +32,10 @@ class Action
32
32
  @config["description"]
33
33
  end
34
34
 
35
+ def skip_hooks?(name)
36
+ @config["skip_#{name}_hooks"]
37
+ end
38
+
35
39
  private
36
40
 
37
41
  def load_secrets?
@@ -1,13 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rubygems"
4
-
5
3
  require "output"
4
+ require "version"
6
5
 
7
6
  module Builtins
8
7
  class Version < Builtin
9
- GEMSPEC_FILE = "#{__dir__}/../../ops_team.gemspec"
10
-
11
8
  class << self
12
9
  def description
13
10
  "prints the version of ops that is running"
@@ -15,18 +12,7 @@ module Builtins
15
12
  end
16
13
 
17
14
  def run
18
- unless gemspec
19
- Output.error("Unable to load gemspec at '#{GEMSPEC_FILE}")
20
- return false
21
- end
22
-
23
- Output.out(gemspec.version)
24
- end
25
-
26
- private
27
-
28
- def gemspec
29
- @gemspec ||= Gem::Specification.load(GEMSPEC_FILE)
15
+ Output.out(::Version.version)
30
16
  end
31
17
  end
32
18
  end
@@ -46,7 +46,7 @@ class Dependency
46
46
  end
47
47
 
48
48
  def success?
49
- @executor&.success?
49
+ @executor.nil? ? true : @executor.success?
50
50
  end
51
51
 
52
52
  def output
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'version'
4
+
3
5
  class Environment
4
6
  def initialize(env_hash)
5
7
  @env_hash = env_hash
@@ -21,6 +23,7 @@ class Environment
21
23
 
22
24
  def set_ops_variables
23
25
  ENV["OPS_YML_DIR"] = Dir.pwd
26
+ ENV["OPS_VERSION"] = Version.version.to_s
24
27
  end
25
28
 
26
29
  def set_environment_aliases
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'output'
4
+
3
5
  class HookHandler
4
6
  class HookConfigError < StandardError; end
5
7
  class HookExecError < StandardError; end
@@ -22,6 +24,7 @@ class HookHandler
22
24
 
23
25
  def execute_hooks(name)
24
26
  hooks(name).each do |hook|
27
+ Output.notice("Running #{name} hook: #{hook}")
25
28
  output, exit_code = Executor.execute(hook)
26
29
 
27
30
  next if exit_code.zero?
data/lib/ops.rb CHANGED
@@ -3,12 +3,14 @@
3
3
 
4
4
  require 'yaml'
5
5
  require 'require_all'
6
+ require "rubygems"
6
7
 
7
8
  require 'hook_handler'
8
9
  require 'action'
9
10
  require 'output'
10
11
  require 'options'
11
12
  require 'environment'
13
+ require 'version'
12
14
  require_rel "builtins"
13
15
 
14
16
  # executes commands based on local `ops.yml`
@@ -20,6 +22,7 @@ class Ops
20
22
  INVALID_SYNTAX_EXIT_CODE = 64
21
23
  UNKNOWN_ACTION_EXIT_CODE = 65
22
24
  ERROR_LOADING_APP_CONFIG_EXIT_CODE = 66
25
+ MIN_VERSION_NOT_MET_EXIT_CODE = 67
23
26
 
24
27
  class << self
25
28
  def project_name
@@ -35,7 +38,9 @@ class Ops
35
38
  end
36
39
 
37
40
  def run
41
+ # "return" is here to allow specs to stub "exit"
38
42
  return exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
43
+ return exit(MIN_VERSION_NOT_MET_EXIT_CODE) unless min_version_met?
39
44
 
40
45
  run_action
41
46
  rescue UnknownActionError => e
@@ -54,11 +59,28 @@ class Ops
54
59
  end
55
60
  end
56
61
 
62
+ def min_version_met?
63
+ return true unless min_version
64
+
65
+ if Version.min_version_met?(min_version)
66
+ true
67
+ else
68
+ Output.error("ops.yml specifies minimum version of #{min_version}, but ops version is #{Version.version}")
69
+ false
70
+ end
71
+ end
72
+
73
+ def min_version
74
+ config["min_version"]
75
+ end
76
+
57
77
  def run_action
58
- do_before_run_action
78
+ do_before_all
59
79
 
60
80
  return builtin.run if builtin
61
81
 
82
+ do_before_action
83
+
62
84
  Output.notice("Running '#{action}' from #{CONFIG_FILE} in environment '#{ENV['environment']}'...")
63
85
  action.run
64
86
  rescue AppConfig::ParsingError => e
@@ -66,10 +88,16 @@ class Ops
66
88
  exit(ERROR_LOADING_APP_CONFIG_EXIT_CODE)
67
89
  end
68
90
 
69
- def do_before_run_action
91
+ def do_before_all
70
92
  environment.set_variables
71
93
  AppConfig.load
72
- hook_handler.do_hooks("before")
94
+ end
95
+
96
+ def do_before_action
97
+ hook_handler.do_hooks("before") unless ENV["OPS_RUNNING"] || action.skip_hooks?("before")
98
+
99
+ # this prevents before hooks from running in ops executed by ops
100
+ ENV["OPS_RUNNING"] = "1"
73
101
  end
74
102
 
75
103
  def hook_handler
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems"
4
+
5
+ class Version
6
+ GEMSPEC_FILE = "#{__dir__}/../ops_team.gemspec"
7
+
8
+ class << self
9
+ # these class methods exist because I don't want to have to call `Version.new.version` elsewhere
10
+ def version
11
+ new.send(:version)
12
+ end
13
+
14
+ def min_version_met?(min_version)
15
+ new.send(:min_version_met?, min_version)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ # these instance methods exist so that I don't have to clear class variables between tests
22
+ def version
23
+ unless gemspec
24
+ Output.error("Unable to load gemspec at '#{GEMSPEC_FILE}")
25
+ return nil
26
+ end
27
+
28
+ gemspec.version
29
+ end
30
+
31
+ def min_version_met?(min_version)
32
+ Gem::Version.new(version) >= Gem::Version.new(min_version)
33
+ end
34
+
35
+ def gemspec
36
+ @gemspec ||= Gem::Specification.load(GEMSPEC_FILE)
37
+ end
38
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.11.0.pre'
5
+ s.version = '0.12.3'
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.11.0.pre
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com
@@ -176,6 +176,7 @@ files:
176
176
  - lib/options.rb
177
177
  - lib/output.rb
178
178
  - lib/secrets.rb
179
+ - lib/version.rb
179
180
  - loader.rb
180
181
  - ops_team.gemspec
181
182
  homepage: https://github.com/nickthecook/ops
@@ -193,9 +194,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
194
  version: '2.5'
194
195
  required_rubygems_version: !ruby/object:Gem::Requirement
195
196
  requirements:
196
- - - ">"
197
+ - - ">="
197
198
  - !ruby/object:Gem::Version
198
- version: 1.3.1
199
+ version: '0'
199
200
  requirements: []
200
201
  rubygems_version: 3.0.3
201
202
  signing_key: