recap 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,3 +19,4 @@ set :repository, '/recap/share/<%= project.name %>'
19
19
  # which they can do when automated like this, we use a finer-grained release tag
20
20
 
21
21
  set(:release_tag) { Time.now.utc.strftime("%Y%m%d%H%M%S%L") }
22
+ set(:release_matcher) { /\A[0-9]{17}\Z/ }
@@ -19,3 +19,4 @@ set :repository, '/recap/share/projects/<%= project.name %>'
19
19
  # which they can do when automated like this, we use a finer-grained release tag
20
20
 
21
21
  set(:release_tag) { Time.now.utc.strftime("%Y%m%d%H%M%S%L") }
22
+ set(:release_matcher) { /\A[0-9]{17}\Z/ }
@@ -56,7 +56,7 @@ module Recap::Support::CapistranoExtensions
56
56
  # tags are timestamps, the latest tag will always be the last in the list.
57
57
  def latest_tag_from_repository
58
58
  tags = capture_git("tag").strip.split
59
- tags.grep(/^[0-9]{17}/).last
59
+ tags.grep(release_matcher).last
60
60
  end
61
61
 
62
62
  # Does the given file exist within the deployment directory?
@@ -37,6 +37,10 @@ module Recap::Tasks::Deploy
37
37
  # not be changed, as the format is matched in the list of tags to find deploy tags.
38
38
  set(:release_tag) { Time.now.utc.strftime("%Y%m%d%H%M%S") }
39
39
 
40
+ # If `release_tag` is changed, then `release_matcher` must be too, to a regular expression
41
+ # that will match all generated release tags. In general it's best to leave both unchanged.
42
+ set(:release_matcher) { /\A[0-9]{14}\Z/ }
43
+
40
44
  # On tagging a release, a message is also recorded alongside the tag. This message can contain
41
45
  # anything useful - its contents are not important for the recipe.
42
46
  set(:release_message, "Deployed at #{Time.now}")
@@ -97,6 +101,9 @@ module Recap::Tasks::Deploy
97
101
 
98
102
  # Tag `HEAD` with the release tag and message
99
103
  task :tag, :except => {:no_release => true} do
104
+ unless release_tag =~ release_matcher
105
+ abort "The release_tag must be matched by the release_matcher regex, #{release_tag} doesn't match #{release_matcher}"
106
+ end
100
107
  on_rollback { git "tag -d #{release_tag}" }
101
108
  git "tag #{release_tag} -m '#{release_message}'"
102
109
  end
data/lib/recap/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Recap
2
- VERSION = '1.0.7'
2
+ VERSION = '1.0.8'
3
3
  end
@@ -77,6 +77,24 @@ describe Recap::Tasks::Deploy do
77
77
  end
78
78
  end
79
79
 
80
+ describe '#release_matcher' do
81
+ it 'defaults to a matcher matching timestamps' do
82
+ ("20130908123422" =~ config.release_matcher).should be_true
83
+ end
84
+
85
+ it 'does not match timestamp-like numbers with too many digits' do
86
+ ("201309081234221" =~ config.release_matcher).should be_false
87
+ end
88
+
89
+ it 'does not match timestamp-like numbers with too few digits' do
90
+ ("2013090812342" =~ config.release_matcher).should be_false
91
+ end
92
+
93
+ it 'does not match strings with non-numeric characters' do
94
+ ("2013090a123421" =~ config.release_matcher).should be_false
95
+ end
96
+ end
97
+
80
98
  describe '#latest_tag' do
81
99
  it 'memoizes call to latest_tag_from_repository' do
82
100
  namespace.stubs(:latest_tag_from_repository).returns('abc123').then.returns('something-else')
@@ -182,12 +200,19 @@ describe Recap::Tasks::Deploy do
182
200
 
183
201
  describe 'deploy:tag' do
184
202
  before do
185
- config.set :release_tag, 'abcd1234'
203
+ config.set :release_tag, '20120101012034'
186
204
  config.set :release_message, 'Released into the wild'
187
205
  end
188
206
 
189
207
  it 'tags code with the release tag and release message' do
190
- namespace.expects(:git).with('tag abcd1234 -m \'Released into the wild\'')
208
+ namespace.expects(:git).with('tag 20120101012034 -m \'Released into the wild\'')
209
+ namespace.find_and_execute_task('deploy:tag')
210
+ end
211
+
212
+ it 'aborts if prospective release_tag does not match release_matcher' do
213
+ config.set :release_matcher, /abcd/
214
+ namespace.expects(:abort).with("The release_tag must be matched by the release_matcher regex, 20120101012034 doesn't match (?-mix:abcd)")
215
+ namespace.stubs(:git)
191
216
  namespace.find_and_execute_task('deploy:tag')
192
217
  end
193
218
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-16 00:00:00.000000000 Z
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -266,7 +266,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
266
  version: '0'
267
267
  segments:
268
268
  - 0
269
- hash: 1151781088408316006
269
+ hash: 2476123254273941007
270
270
  required_rubygems_version: !ruby/object:Gem::Requirement
271
271
  none: false
272
272
  requirements:
@@ -275,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
275
275
  version: '0'
276
276
  segments:
277
277
  - 0
278
- hash: 1151781088408316006
278
+ hash: 2476123254273941007
279
279
  requirements: []
280
280
  rubyforge_project:
281
281
  rubygems_version: 1.8.23