capistrano-conditional 0.2.0 → 0.2.3

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: 342478e6b86a6640f3ef7e5e736106aa7bb0891d
4
- data.tar.gz: 9fe26b04628d6e5ca1449bdd2a82752eaa05c4d9
3
+ metadata.gz: 2e4da45f43ae67675bf6b34a22d8a6bf14c45289
4
+ data.tar.gz: 125f1a2195bcb43d155d55a5981501e0240f8a97
5
5
  SHA512:
6
- metadata.gz: d9d204061b4610bc21ea10ba28d48c7ffd0449db7c06ae9505594cbe0590a6c02fa02a63d5f9c89f86a1efe3eb26827f8e5b99614e0089133bb5ea70db31bb6d
7
- data.tar.gz: 6239ed308a07eef67539cf37a1fd21b97bd21b083e3edb3d7a290e81c93518d3eb654ec7f012c4856a56bed7c45f2f78ccca21abd6e77664082ae6b2e4b1db30
6
+ metadata.gz: 9d17e3f8a4549f215a820589a954fec5f056a13d0b31e069671305a4d897883ddf2d29941a8e19b79495d814dad54f41000d7e2416fbe5073ef5ee0f759749c7
7
+ data.tar.gz: 482b44246f54f56057a8fc3331c41a89674def23a1e133879d89dfeda2a1618fda3fa028071e37ca623f4ff82746b7006bfa2fa86f4e793d1d07c57930ec8b0e
@@ -1,5 +1,14 @@
1
1
  # changelog
2
2
 
3
+ ## 0.2.3 -- July 10, 2014
4
+ * Added ability to specify default tasks in case git diff can't be found
5
+
6
+ ## 0.2.0 -- July 1, 2014
7
+ * Updated to support capistrano v3, support for v2 dropped
8
+
9
+ ## 0.1.0 -- June 25, 2014
10
+ * No longer requires deploying from working directory
11
+
3
12
  ## 0.0.4 -- December 20, 2013
4
13
  * Updated dependecy - does not work with capistrano 3+
5
14
  * Updated README examples
data/README.md CHANGED
@@ -69,7 +69,6 @@ For instance, using [whenever](https://github.com/javan/whenever), to only run t
69
69
  end
70
70
  end
71
71
 
72
-
73
72
  ### Example Usage - Asset Precompilation
74
73
 
75
74
  ConditionalDeploy.configure(self) do |conditional|
@@ -95,6 +94,18 @@ For instance, using [whenever](https://github.com/javan/whenever), to only run t
95
94
 
96
95
  If you need to force a particular conditional to run, you can do so via the environment. Given the examples above, if you want to run the conditional named <code>whenever</code> even though config/schedule.rb hasn't been changed, just run <code>cap deploy RUN_WHENEVER=1</code>. Similarly, if you needed to skip the <code>whenever</code> conditional which would otherwise be run, you can use <code>cap deploy SKIP_WHENEVER=1</code>.
97
96
 
97
+ ### Handling rebases and other git failures
98
+
99
+ Normal functioning of this library depends upon git being able to identify the currently deployed revision, the revision to be deployed, and the history between them. With workflows that allow rebasing after branches have already been deployed (e.g. in staging environments), however, these requirements are often not met. To work around this, you can specify certain tasks as default, to be run whenever capistrano conditional can't figure out the git history. This allows you to have a fallback where a deploy may be less efficient, but will still go through regardless. For example, to default compiling assets locally even if we can't tell if any assets changed:
100
+
101
+ ConditionalDeploy.configure(self) do |conditional|
102
+ asset_paths = ['/assets', 'Gemfile.lock', 'config/environments']
103
+ conditional.register :local_asset_precompilation, none_match: asset_paths, default: true do |c|
104
+ # ... implementing code ...
105
+ end
106
+
107
+ Note the addition of `default: true` to the `register` call.
108
+
98
109
  ### Setting branches
99
110
 
100
111
  By default, capistrano-conditional pics up the branch-to-be-deployed from the `:branch` setting used by capistrano multistage, or defaults to `HEAD`. To specify a different branch manually: `set :git_deploying, 'some/other/branch/name'`.
@@ -6,12 +6,17 @@
6
6
  class ConditionalDeploy
7
7
 
8
8
  @@conditionals = []
9
+ @@run_without_git_diff = false
9
10
 
10
11
  def self.register(name, opts, &block)
11
12
  raise("Already added a conditional with that name") if @@conditionals.any?{|c| c.name == name}
12
13
  @@conditionals << Capistrano::Conditional::Unit.new(name, opts, block)
13
14
  end
14
15
 
16
+ def self.in_default_mode?
17
+ @@run_without_git_diff
18
+ end
19
+
15
20
  def skip_task(name, opts={})
16
21
  method = opts[:clear_hooks] ? :clear : :clear_actions
17
22
  msg = opts[:message] || "Skipping #{name} as preconditions to require it were not met"
@@ -32,15 +37,15 @@ class ConditionalDeploy
32
37
  def initialize(context, current, deploying)
33
38
  @context = context
34
39
  @log_method = :info # TODO: make this configurable
40
+ @to_run = []
35
41
 
36
42
  @git = Git.open('.')
37
- @working = get_object 'HEAD'
38
43
  @current = get_object current, 'currently deployed'
39
44
  @deploying = get_object deploying, 'about to be deployed'
45
+ return if @@run_without_git_diff
40
46
 
41
47
  @diff = @git.diff(current, deploying)
42
48
  @changed = @diff.stats[:files].keys.compact.sort
43
- @to_run = []
44
49
  end
45
50
 
46
51
  def apply_conditions!
@@ -55,14 +60,25 @@ class ConditionalDeploy
55
60
  @git.object(name)
56
61
  rescue Git::GitExecuteError => e
57
62
  msg = desc ? "(#{desc}) #{name}" : name
58
- abort "Unable to find git object for #{msg}. Is your local repository up to date?\n\n"
63
+
64
+ if @@conditionals.any? {|job| job.default? }
65
+ warn "Unable to find git object for #{msg}. Running with default jobs enabled."
66
+ @@run_without_git_diff = true
67
+ else
68
+ abort "Unable to find git object for #{msg}. Is your local repository up to date?\n\n"
69
+ end
59
70
  end
60
71
 
61
72
  def report_plan
62
73
  @plan = []
63
- set_report_header
64
- set_report_files
65
- set_report_runlist
74
+ if @@run_without_git_diff
75
+ set_report_header_without_git
76
+ set_report_runlist
77
+ else
78
+ set_report_header
79
+ set_report_files
80
+ set_report_runlist
81
+ end
66
82
  log @plan
67
83
  end
68
84
 
@@ -70,7 +86,7 @@ class ConditionalDeploy
70
86
  @@conditionals.each do |job|
71
87
  force = job.name && ENV["RUN_#{job.name.to_s.upcase}"]
72
88
  skip = job.name && ENV["SKIP_#{job.name.to_s.upcase}"]
73
- next unless force || job.applies?(@changed)
89
+ next unless force || job.applies?(@changed) || (@@run_without_git_diff && job.default?)
74
90
  next if skip
75
91
  @to_run << job
76
92
  end
@@ -82,6 +98,15 @@ class ConditionalDeploy
82
98
  end
83
99
  end
84
100
 
101
+ def set_report_header_without_git
102
+ @plan << ''
103
+ @plan << 'Conditional Deployment Report:'
104
+ @plan << ''
105
+ @plan << "\tUNABLE TO IDENTIFY THE GIT HISTORY BETWEEN DEPLOYED AND DEPLOYING BRANCHES."
106
+ @plan << "\tFalling back to running only conditionals marked as :default"
107
+ @plan << ''
108
+ end
109
+
85
110
  def set_report_header
86
111
  @plan << ''
87
112
  @plan << 'Conditional Deployment Report:'
@@ -7,53 +7,66 @@ module Capistrano
7
7
  # Created from <em>ConditionalDeploy.register</em>, the end user should
8
8
  # never need to interact with it directly.
9
9
  class Unit
10
+ VALID_CONDITIONS = [:any_match, :none_match, :if, :unless, :watchlist]
11
+
10
12
  attr_accessor :name, :message, :conditions, :block
11
13
 
12
14
  def initialize(name, opts, block)
13
- @name = name
14
- @message = opts.delete(:msg)
15
- @block = block
15
+ @name = name
16
+ @message = opts.delete(:msg)
17
+ @block = block
16
18
  @conditions = {}
19
+ @options = {}
20
+
17
21
  opts.each do |k,v|
18
- @conditions[k] = v
22
+ if VALID_CONDITIONS.include?(k)
23
+ @conditions[k] = v
24
+ else
25
+ @options[k] = v
26
+ end
19
27
  end
20
28
  end
21
29
 
22
- # Currently supported options: any_match (aliased to watchlist), none_match, if, unless
23
30
  def applies?(changed)
24
31
  @changed = changed
32
+ return default? if ConditionalDeploy.in_default_mode?
33
+
25
34
  any_match_applies? && none_match_applies? && if_applies? && unless_applies?
26
- end
35
+ end
36
+
37
+ def default?
38
+ !!@options[:default]
39
+ end
27
40
 
28
41
  protected
29
-
42
+
30
43
  def any_match_applies?
31
44
  any_files_match?(:any_match) && any_files_match?(:watchlist)
32
45
  end
33
-
46
+
34
47
  def none_match_applies?
35
- Array(conditions[:none_match]).all? do |watched|
48
+ Array(conditions[:none_match]).all? do |watched|
36
49
  !@changed.any? { |path| path[watched] }
37
50
  end
38
51
  end
39
-
52
+
40
53
  def if_applies?
41
- return true if conditions[:if].nil?
54
+ return true if conditions[:if].nil?
42
55
  condition_true?(:if)
43
56
  end
44
-
57
+
45
58
  def unless_applies?
46
59
  return true if conditions[:unless].nil?
47
60
  !condition_true?(:unless)
48
61
  end
49
-
62
+
50
63
  def any_files_match?(key)
51
64
  return true unless conditions[key]
52
- Array(conditions[key]).any? do |watched|
65
+ Array(conditions[key]).any? do |watched|
53
66
  @changed.any? { |path| path[watched] }
54
67
  end
55
68
  end
56
-
69
+
57
70
  def condition_true?(label)
58
71
  c = conditions[label]
59
72
  case c.arity
@@ -62,8 +75,8 @@ module Capistrano
62
75
  else
63
76
  c.call(@changed, @git)
64
77
  end
65
- end
66
-
67
- end
78
+ end
79
+
80
+ end
68
81
  end
69
82
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Conditional
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-conditional
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kali Donovan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-01 00:00:00.000000000 Z
11
+ date: 2014-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git