step-up 0.2.1 → 0.3.0
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.
- data/lib/step-up/cli.rb +93 -8
- data/lib/step-up/config/step-up.yml +2 -3
- data/lib/step-up/driver/git.rb +8 -8
- data/lib/step-up/parser/version_mask.rb +12 -47
- data/spec/lib/config_spec.rb +1 -1
- data/spec/lib/step-up/driver/git_spec.rb +1 -1
- data/spec/lib/step-up/parser/version_mask_spec.rb +1 -1
- data/templates/default/Gemfile +1 -0
- data/templates/default/lib/tasks/versioning.rake +8 -0
- data/templates/default/lib/version.rb +15 -0
- metadata +8 -5
data/lib/step-up/cli.rb
CHANGED
@@ -11,6 +11,7 @@ module StepUp
|
|
11
11
|
desc "version ACTION [OPTIONS]", "manage versions of your project"
|
12
12
|
method_options %w(levels -L) => :boolean # $ stepup version [--levels|-L]
|
13
13
|
method_options %w(level -l) => :string, %w(steps -s) => :boolean, %w(message -m) => :string, :'no-editor' => :boolean # $ stepup version create [--level|-l <level-name>] [--steps|-s] [--message|-m <comment-string>] [--no-editor]
|
14
|
+
method_options %w(mask -M) => :string # stepup version show --mask development_hudson_build_0
|
14
15
|
VERSION_ACTIONS = %w[show create help]
|
15
16
|
def version(action = nil)
|
16
17
|
action = "show" unless VERSION_ACTIONS.include?(action)
|
@@ -24,13 +25,17 @@ module StepUp
|
|
24
25
|
desc "init", "adds .stepuprc to your project and prepare your local repository to use notes"
|
25
26
|
method_options :update => :boolean
|
26
27
|
def init
|
28
|
+
# creates .stepuprc file
|
27
29
|
content = File.read(File.expand_path("../config/step-up.yml", __FILE__))
|
28
30
|
if options[:update] || ! File.exists?(".stepuprc")
|
29
|
-
|
31
|
+
say_status File.exists?(".stepuprc") ? :update : :create, ".stepuprc", :green
|
30
32
|
File.open(".stepuprc", "w") do |f|
|
31
33
|
f.write content
|
32
34
|
end
|
35
|
+
else
|
36
|
+
say_status :skip, "Creating .stepuprc", :yellow
|
33
37
|
end
|
38
|
+
# add entry to .git/config
|
34
39
|
remotes_with_notes = driver.fetched_remotes('notes')
|
35
40
|
unfetched_remotes = driver.fetched_remotes - remotes_with_notes
|
36
41
|
unless remotes_with_notes.any? || unfetched_remotes.empty?
|
@@ -40,9 +45,66 @@ module StepUp
|
|
40
45
|
else
|
41
46
|
remote = unfetched_remotes.first
|
42
47
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
48
|
+
cmds = ["git config --add remote.#{ remote }.fetch +refs/notes/*:refs/notes/*"]
|
49
|
+
print_or_run(cmds, false)
|
50
|
+
end
|
51
|
+
# Changing Gemfile
|
52
|
+
if File.exists?("Gemfile")
|
53
|
+
gem_file = File.read("Gemfile")
|
54
|
+
if gem_file =~ /\bstep-up\b/
|
55
|
+
say_status :skip, "Adding dependency to step-up on Gemfile", :yellow
|
56
|
+
else
|
57
|
+
say_status :update, "Adding dependency to step-up on Gemfile", :green
|
58
|
+
content = File.read(File.expand_path(File.join(__FILE__, '..', '..', '..', 'templates', 'default', 'Gemfile')))
|
59
|
+
stepup_dependency = template_render(content)
|
60
|
+
File.open("Gemfile", "w") do |f|
|
61
|
+
f.write gem_file
|
62
|
+
f.write "\n" unless gem_file.end_with?("\n")
|
63
|
+
f.write stepup_dependency
|
64
|
+
end
|
65
|
+
end
|
66
|
+
else
|
67
|
+
say_status :skip, "Gemfile not found", :yellow
|
68
|
+
end
|
69
|
+
# Creating lib/version.rb
|
70
|
+
content = File.read(File.expand_path(File.join(__FILE__, '..', '..', '..', 'templates', 'default', 'lib', 'version.rb')))
|
71
|
+
new_version_rb = template_render(content)
|
72
|
+
Dir.mkdir('lib') unless File.exists?('lib')
|
73
|
+
if File.exists?("lib/version.rb")
|
74
|
+
version_rb = File.read("lib/version.rb")
|
75
|
+
if version_rb =~ /\bStepUp\b/
|
76
|
+
say_status :skip, "Creating lib/version.rb", :yellow
|
77
|
+
else
|
78
|
+
say_status :update, "Appending to lib/version.rb", :green
|
79
|
+
File.open("lib/version.rb", "w") do |f|
|
80
|
+
f.write version_rb
|
81
|
+
f.write "\n" unless version_rb.end_with?("\n")
|
82
|
+
f.write new_version_rb
|
83
|
+
end
|
84
|
+
end
|
85
|
+
else
|
86
|
+
say_status :create, "Creating lib/version.rb", :green
|
87
|
+
File.open("lib/version.rb", "w") do |f|
|
88
|
+
f.write new_version_rb
|
89
|
+
end
|
90
|
+
end
|
91
|
+
# Creating lib/tasks/versioning.rake
|
92
|
+
if File.exists?("lib/tasks/versioning.rake")
|
93
|
+
say_status :skip, "Creating lib/tasks/versioning.rake", :yellow
|
94
|
+
else
|
95
|
+
say_status :create, "Creating lib/tasks/versioning.rake", :green
|
96
|
+
content = File.read(File.expand_path(File.join(__FILE__, '..', '..', '..', 'templates', 'default', 'lib', 'tasks', 'versioning.rake')))
|
97
|
+
content = template_render(content)
|
98
|
+
Dir.mkdir('lib/tasks') unless File.exists?('lib/tasks')
|
99
|
+
File.open("lib/tasks/versioning.rake", "w") do |f|
|
100
|
+
f.write content
|
101
|
+
end
|
102
|
+
end
|
103
|
+
# Appending .gitignore
|
104
|
+
unless File.exists?(".gitignore") && File.read(".gitignore") =~ /^#{gsub_params['version_file']}$/
|
105
|
+
run "echo #{gsub_params['version_file']} >> .gitignore"
|
106
|
+
else
|
107
|
+
say_status :skip, "Adding #{gsub_params['version_file']} to .gitignore", :yellow
|
46
108
|
end
|
47
109
|
end
|
48
110
|
|
@@ -154,7 +216,9 @@ module StepUp
|
|
154
216
|
puts " - #{level}"
|
155
217
|
end
|
156
218
|
else
|
157
|
-
|
219
|
+
mask = options[:mask]
|
220
|
+
mask = nil if mask !~ /0/
|
221
|
+
puts driver(mask).last_version_tag("HEAD", true)
|
158
222
|
end
|
159
223
|
end
|
160
224
|
|
@@ -191,7 +255,8 @@ module StepUp
|
|
191
255
|
end
|
192
256
|
end
|
193
257
|
|
194
|
-
def driver
|
258
|
+
def driver(mask = nil)
|
259
|
+
return StepUp::Driver::Git.new mask unless mask.nil?
|
195
260
|
@driver ||= StepUp::Driver::Git.new
|
196
261
|
end
|
197
262
|
|
@@ -254,12 +319,20 @@ module StepUp
|
|
254
319
|
end
|
255
320
|
|
256
321
|
def print_or_run(steps, print)
|
322
|
+
opts = {:capture => false}
|
257
323
|
if print
|
258
|
-
|
324
|
+
steps.each{ |step| say_status :step, step, :green }
|
259
325
|
else
|
326
|
+
status = true
|
260
327
|
steps.each do |step|
|
261
|
-
|
328
|
+
if status
|
329
|
+
status = run(step, opts)
|
330
|
+
say_status(:fail, "Problems when running `#{step}` (exit status #{$?.exitstatus})", :red) unless status
|
331
|
+
else
|
332
|
+
say_status(:skip, step, :yellow)
|
333
|
+
end
|
262
334
|
end
|
335
|
+
exit(1) unless status
|
263
336
|
end
|
264
337
|
end
|
265
338
|
|
@@ -267,5 +340,17 @@ module StepUp
|
|
267
340
|
message = options[:message]
|
268
341
|
(message && !message.strip.empty?) ? message : nil
|
269
342
|
end
|
343
|
+
|
344
|
+
def gsub_params
|
345
|
+
@gsub_params ||= {
|
346
|
+
'stepup_version' => StepUp::VERSION,
|
347
|
+
'version_file' => "CURRENT_VERSION",
|
348
|
+
'version_blank' => driver.mask.blank
|
349
|
+
}
|
350
|
+
end
|
351
|
+
|
352
|
+
def template_render(tmpl)
|
353
|
+
tmpl.gsub(/\{\{(.*?)\}\}/){ |m| gsub_params[$1] || m }
|
354
|
+
end
|
270
355
|
end
|
271
356
|
end
|
data/lib/step-up/driver/git.rb
CHANGED
@@ -5,8 +5,8 @@ module StepUp
|
|
5
5
|
|
6
6
|
include GitExtensions::Notes
|
7
7
|
attr_reader :mask
|
8
|
-
def initialize
|
9
|
-
@mask = Parser::VersionMask.new(CONFIG.versioning.version_mask)
|
8
|
+
def initialize(mask = nil)
|
9
|
+
@mask = Parser::VersionMask.new(mask || CONFIG.versioning.version_mask)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.last_version
|
@@ -17,11 +17,11 @@ module StepUp
|
|
17
17
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
18
18
|
top = args.shift
|
19
19
|
top = "-n#{ top }" unless top.nil?
|
20
|
-
commits = `git log --pretty=oneline --no-color
|
20
|
+
commits = `git log --pretty=oneline --no-color #{ top } #{ commit_base }`
|
21
21
|
if options[:with_messages]
|
22
|
-
commits.
|
22
|
+
commits.scan(/^(\w+)\s+(.*)$/)
|
23
23
|
else
|
24
|
-
commits.
|
24
|
+
commits.scan(/^(\w+)\s/).flatten
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -30,8 +30,8 @@ module StepUp
|
|
30
30
|
commit_history(commit_base, *args)
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
`git tag -l
|
33
|
+
def tags
|
34
|
+
@tags ||= `git tag -l`
|
35
35
|
end
|
36
36
|
|
37
37
|
def objects_with_notes_of(ref)
|
@@ -47,7 +47,7 @@ module StepUp
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def all_version_tags
|
50
|
-
@version_tags ||=
|
50
|
+
@version_tags ||= tags.scan(mask.regex).map{ |tag| tag.collect(&:to_i) }.sort.map{ |tag| mask.format(tag) }.reverse
|
51
51
|
end
|
52
52
|
|
53
53
|
def version_tag_info(tag)
|
@@ -2,58 +2,29 @@ module StepUp
|
|
2
2
|
module Parser
|
3
3
|
class VersionMask
|
4
4
|
attr_reader :mask
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :to_regex, :regex
|
6
6
|
def initialize(mask)
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_regex
|
15
|
-
re = []
|
16
|
-
mask.each_with_index do |level, index|
|
17
|
-
re << "(?:#{ iterator[index].source })#{ '?' if level.end_with?('9') }"
|
18
|
-
end
|
19
|
-
re.join
|
7
|
+
raise ArgumentError if mask.nil? || mask =~ /[1-8]|[09][09]|9.+0/
|
8
|
+
@mask = mask.scan(/(\D*)([09])/)
|
9
|
+
@to_regex = ""
|
10
|
+
@mask.each { |level| @to_regex << "(?:#{level.first.gsub(/([\\\.\*\?\{\}\(\)\[\]])/, '\\\\\1')}(\\d+))#{'?' if level.last == '9'}" }
|
11
|
+
@regex = /^#{to_regex}$/
|
20
12
|
end
|
21
13
|
|
22
14
|
def parse(version)
|
23
15
|
return unless version.is_a?(String)
|
24
|
-
|
25
|
-
v
|
26
|
-
iterator.each_with_index do |pattern, index|
|
27
|
-
pos = version.index(pattern, i)
|
28
|
-
if pos.nil?
|
29
|
-
if mask[index] =~ /9$/
|
30
|
-
v << 0
|
31
|
-
else
|
32
|
-
return
|
33
|
-
end
|
34
|
-
else
|
35
|
-
if pos == i
|
36
|
-
n = $1
|
37
|
-
i += mask[index].size + n.size - 1
|
38
|
-
v << n.to_i
|
39
|
-
elsif mask[index] =~ /9$/
|
40
|
-
v << 0
|
41
|
-
else
|
42
|
-
return
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
v
|
16
|
+
v = version.scan(regex).first
|
17
|
+
v.nil? ? nil : v.collect(&:to_i)
|
47
18
|
end
|
48
19
|
|
49
20
|
def format(version)
|
50
21
|
raise ArgumentError unless version.is_a?(Array) && version.size == mask.size
|
51
22
|
v = []
|
52
|
-
|
23
|
+
mask.each_with_index do |part, index|
|
53
24
|
level = version[index] || 0
|
54
25
|
raise ArgumentError unless level.is_a?(Fixnum)
|
55
|
-
unless level.zero? &&
|
56
|
-
v <<
|
26
|
+
unless level.zero? && part.last == '9'
|
27
|
+
v << "#{part.first}#{level}"
|
57
28
|
end
|
58
29
|
end
|
59
30
|
v.join
|
@@ -61,7 +32,7 @@ module StepUp
|
|
61
32
|
|
62
33
|
def increase_version(version, level)
|
63
34
|
v = parse version
|
64
|
-
level = version_levels.index(level)
|
35
|
+
level = CONFIG.versioning.version_levels.index(level)
|
65
36
|
(v.size-level).times do |index|
|
66
37
|
v[level+index] = (index.zero? ? (v[level+index] || 0) + 1 : nil)
|
67
38
|
end
|
@@ -71,12 +42,6 @@ module StepUp
|
|
71
42
|
def blank
|
72
43
|
format mask.size.times.map{ 0 }
|
73
44
|
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def version_levels
|
78
|
-
CONFIG["versioning"]["version_levels"]
|
79
|
-
end
|
80
45
|
end
|
81
46
|
end
|
82
47
|
end
|
data/spec/lib/config_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe StepUp::Driver::Git do
|
|
34
34
|
context 'fetching all tags' do
|
35
35
|
it "should get tags sorted" do
|
36
36
|
tags = %w[note-v0.2.0-1 v0.1.0 v0.1.1 v0.1.10 v0.1.2 v0.1.1.rc3]
|
37
|
-
@driver.stubs(:
|
37
|
+
@driver.stubs(:tags).returns(tags.join("\n"))
|
38
38
|
@driver.all_version_tags.should be == %w[v0.1.10 v0.1.2 v0.1.1.rc3 v0.1.1 v0.1.0]
|
39
39
|
end
|
40
40
|
end
|
@@ -39,7 +39,7 @@ describe StepUp::Parser::VersionMask do
|
|
39
39
|
|
40
40
|
context "increasing version" do
|
41
41
|
before do
|
42
|
-
|
42
|
+
StepUp::CONFIG.versioning.stubs(:version_levels).returns(%w[major minor tiny patch build rc])
|
43
43
|
end
|
44
44
|
it "should increase by levels" do
|
45
45
|
version = "v2.3.1.6.4.rc5"
|
@@ -0,0 +1 @@
|
|
1
|
+
gem 'step-up', "~> {{stepup_version}}", :group => [:preparing]
|
@@ -0,0 +1,8 @@
|
|
1
|
+
namespace :stepup do
|
2
|
+
desc "Generates file with the latest version of the application"
|
3
|
+
task :version_file do
|
4
|
+
require 'step-up'
|
5
|
+
puts "Generating the version file {{version_file}} with the latest version of the application"
|
6
|
+
File.open('{{version_file}}', 'w') { |f| f.write StepUp::Driver::Git.new.last_version_tag("HEAD", true) }
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# created by StepUp
|
2
|
+
module Version
|
3
|
+
def self.to_s
|
4
|
+
unless defined? @version
|
5
|
+
txt = File.expand_path File.join(__FILE__, '..', '..', '{{version_file}}')
|
6
|
+
if File.exists?(txt)
|
7
|
+
@version = File.read(txt).chomp
|
8
|
+
else
|
9
|
+
@version = "{{version_blank}}+"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
@version
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: step-up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marcelo Manzan
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-02-04 00:00:00 -02:00
|
20
20
|
default_executable: stepup
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -87,6 +87,9 @@ files:
|
|
87
87
|
- lib/step-up/parser/version_mask.rb
|
88
88
|
- lib/step-up/ranged_notes.rb
|
89
89
|
- lib/step-up/version.rb
|
90
|
+
- templates/default/Gemfile
|
91
|
+
- templates/default/lib/tasks/versioning.rake
|
92
|
+
- templates/default/lib/version.rb
|
90
93
|
- spec/lib/config_spec.rb
|
91
94
|
- spec/lib/step-up/driver/git_spec.rb
|
92
95
|
- spec/lib/step-up/parser/version_mask_spec.rb
|