thor-scmversion 0.2.4 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Thorfile CHANGED
@@ -18,8 +18,8 @@ class ThorSCMVersion < Thor
18
18
  system("gem install pkg/thor-scmversion-#{current_version}.gem")
19
19
  end
20
20
 
21
- desc "release TYPE", "Bump version, make a build, and push to Rubygems"
22
- def release(type)
21
+ desc "release [TYPE]", "Bump version, make a build, and push to Rubygems"
22
+ def release(type='auto')
23
23
  @current_version = nil
24
24
  invoke "version:bump", [type]
25
25
  invoke "build", []
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.push File.expand_path("../../lib", __FILE__)
4
+ require 'thor-scmversion'
5
+
6
+ ThorSCMVersion::Tasks.start
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+ require 'tmpdir'
1
3
  require 'thor'
2
4
  require 'thor-scmversion/scm_version'
3
5
  require 'thor-scmversion/git_version'
@@ -24,9 +26,13 @@ module ThorSCMVersion
24
26
  end
25
27
  end
26
28
 
29
+ method_option :version_file_path,
30
+ :type => :string,
31
+ :default => nil,
32
+ :desc => "An additional path to copy a VERSION file to on the file system."
27
33
  desc "current", "Show current SCM tagged version"
28
34
  def current
29
- write_version
35
+ write_version(options[:version_file_path])
30
36
  say current_version.to_s
31
37
  end
32
38
 
@@ -35,14 +41,10 @@ module ThorSCMVersion
35
41
  @current_version ||= ThorSCMVersion.versioner.from_path
36
42
  end
37
43
 
38
- def write_version
39
- ver = current_version.to_s
40
- version_files.each do |ver_file|
41
- File.open(ver_file, 'w+') do |f|
42
- f.write ver
43
- end
44
- end
45
- ver
44
+ def write_version(version_file_path=nil)
45
+ files_to_write = version_files
46
+ files_to_write << File.join(File.expand_path(version_file_path), 'VERSION') if version_file_path
47
+ current_version.write_version(files_to_write)
46
48
  end
47
49
 
48
50
  eval "def source_root ; Pathname.new File.dirname(__FILE__) ; end"
@@ -47,25 +47,105 @@ module ThorSCMVersion
47
47
  class P4Version < ScmVersion
48
48
  class << self
49
49
  def all_from_path(path)
50
- file_path = File.expand_path(File.join(path, 'VERSION'))
51
- version = new(*File.read(file_path).strip.split("."))
52
- version.version_file_path = file_path
53
- [version]
50
+ Dir.chdir(path) do
51
+ all_labels_array = `p4 labels -e \"#{module_name(path)}*\"`.split("\n")
52
+ thor_scmversion_labels = get_thor_scmversion_labels(all_labels_array, module_name(path))
53
+
54
+ current_versions = thor_scmversion_labels.collect do |label|
55
+ new_instance = new(*parse_label(label, module_name(path)))
56
+ end.sort.reverse
57
+
58
+ if current_versions.empty?
59
+ first_instance = new(0, 0, 0)
60
+ end
61
+
62
+ current_versions << first_instance if current_versions.empty?
63
+ current_versions
64
+ end
54
65
  end
66
+
67
+ def depot_path(path)
68
+ `p4 dirs #{File.expand_path(path)}`.chomp
69
+ end
70
+
71
+ def module_name(path)
72
+ File.expand_path(path).split("/").last
73
+ end
74
+
75
+ def parse_label(label, p4_module_name)
76
+ label.split(" ")[1].gsub("#{p4_module_name}-", "").split('.')
77
+ end
78
+
79
+ def get_thor_scmversion_labels(labels, p4_module_name)
80
+ labels.select{|label| label.split(" ")[1].gsub("#{p4_module_name}-", "").match(ScmVersion::VERSION_FORMAT)}
81
+ end
82
+ end
83
+
84
+ def initialize(major=0, minor=0, patch=0)
85
+ self.p4_depot_path = self.class.depot_path('.')
86
+ self.p4_module_name = self.class.module_name('.')
87
+ super(major, minor, patch)
55
88
  end
56
89
 
57
90
  attr_accessor :version_file_path
91
+ attr_accessor :p4_depot_path
92
+ attr_accessor :p4_module_name
93
+
94
+ def retrieve_tags
95
+ # noop
96
+ # p4 always has labels available, you just have to ask the server for them.
97
+ end
58
98
 
59
99
  def tag
60
- description = "Bump version to #{to_s}."
61
- `p4 edit -c default "#{self.version_file_path}"`
62
- File.open(self.version_file_path, 'w') { |f| f.write to_s }
63
- `p4 submit -d "#{description}"`
100
+ if windows?
101
+ `type #{File.expand_path(get_p4_label_file).gsub(File::Separator, File::ALT_SEPARATOR)} | p4 label -i`
102
+ else
103
+ `cat #{File.expand_path(get_p4_label_file)} | p4 label -i`
104
+ end
64
105
  end
65
106
 
66
107
  def auto_bump
67
108
  # TODO: actually implement this
68
109
  bump!(:patch)
69
110
  end
111
+
112
+ private
113
+
114
+ def get_label_name
115
+ "#{p4_module_name}-#{self}"
116
+ end
117
+
118
+ def get_p4_label_template
119
+ %{
120
+ Label: #{get_label_name}
121
+
122
+ Description:
123
+ Created by thor-scmversion.
124
+
125
+ Owner: #{ENV["P4USER"]}
126
+
127
+ Options: unlocked
128
+
129
+ Revision: @#{get_last_submitted_p4_changelist}
130
+
131
+ View:
132
+ #{p4_depot_path}/...}
133
+ end
134
+
135
+ def get_last_submitted_p4_changelist
136
+ `p4 changes -s submitted -m 1 #{p4_depot_path}/...`.split(' ')[1]
137
+ end
138
+
139
+ def get_p4_label_file
140
+ tmp_dir = Dir.mktmpdir
141
+ File.open(File.join(tmp_dir, "p4_label.tmp"), "w") do |file|
142
+ file.write(get_p4_label_template)
143
+ file
144
+ end
145
+ end
146
+
147
+ def windows?
148
+ RbConfig::CONFIG["arch"] =~ /cygwin|mswin|mingw|bccwin|wince|emx/
149
+ end
70
150
  end
71
151
  end
@@ -14,6 +14,7 @@ module ThorSCMVersion
14
14
  include Comparable
15
15
 
16
16
  VERSION_FORMAT = /^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)$/
17
+ VERSION_FILENAME = 'VERSION'
17
18
  class << self
18
19
  def from_path(path = '.')
19
20
  retrieve_tags
@@ -53,7 +54,16 @@ module ThorSCMVersion
53
54
  raise "Version: #{self.to_s} is less than or equal to the existing version." if self <= self.class.from_path
54
55
  self
55
56
  end
56
-
57
+
58
+ def write_version(files = [ScmVersion::VERSION_FILENAME])
59
+ files.each do |ver_file|
60
+ File.open(ver_file, 'w+') do |f|
61
+ f.write self.to_s
62
+ end
63
+ end
64
+ self
65
+ end
66
+
57
67
  def tag
58
68
  raise NotImplementedError
59
69
  end
@@ -24,4 +24,13 @@ here
24
24
  ENV["P4USER"].should == "kallan"
25
25
  end
26
26
  end
27
- end
27
+
28
+ describe P4Version do
29
+ it 'should parse labels correctly' do
30
+ described_class.parse_label("Label testing-1.0.0 2012/10/01 'Created by kallan. '", "testing").should eq(["1","0","0"])
31
+ described_class.parse_label("Label testing-1.0.1 2012/10/01 'Created by kallan. '", "testing").should eq(["1","0","1"])
32
+ described_class.parse_label("Label testing-2.0.5 2012/10/01 'Created by kallan. '", "testing").should eq(["2","0","5"])
33
+ described_class.parse_label("Label testing-4.2.2 2012/10/01 'Created by kallan. '", "testing").should eq(["4","2","2"])
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor-scmversion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-09-26 00:00:00.000000000Z
14
+ date: 2012-10-08 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: thor
18
- requirement: &70295688203360 !ruby/object:Gem::Requirement
18
+ requirement: &70281121566680 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70295688203360
26
+ version_requirements: *70281121566680
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: webmock
29
- requirement: &70295688706320 !ruby/object:Gem::Requirement
29
+ requirement: &70281121904800 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *70295688706320
37
+ version_requirements: *70281121904800
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: geminabox
40
- requirement: &70295689010460 !ruby/object:Gem::Requirement
40
+ requirement: &70281122109820 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *70295689010460
48
+ version_requirements: *70281122109820
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: spork
51
- requirement: &70295689371080 !ruby/object:Gem::Requirement
51
+ requirement: &70281122489560 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *70295689371080
59
+ version_requirements: *70281122489560
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: simplecov
62
- requirement: &70295689476520 !ruby/object:Gem::Requirement
62
+ requirement: &70281125870580 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70295689476520
70
+ version_requirements: *70281125870580
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: vcr
73
- requirement: &70295689535300 !ruby/object:Gem::Requirement
73
+ requirement: &70281126177140 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: '0'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *70295689535300
81
+ version_requirements: *70281126177140
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: aruba
84
- requirement: &70295692467880 !ruby/object:Gem::Requirement
84
+ requirement: &70281126843440 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ! '>='
@@ -89,10 +89,10 @@ dependencies:
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *70295692467880
92
+ version_requirements: *70281126843440
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rspec
95
- requirement: &70295692789340 !ruby/object:Gem::Requirement
95
+ requirement: &70281126962300 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
98
  - - ! '>='
@@ -100,13 +100,14 @@ dependencies:
100
100
  version: '0'
101
101
  type: :development
102
102
  prerelease: false
103
- version_requirements: *70295692789340
103
+ version_requirements: *70281126962300
104
104
  description: Thor tasks to manage a VERSION file based on SCM tags
105
105
  email:
106
106
  - ivey@gweezlebur.com
107
107
  - kallan@riotgames.com
108
108
  - josiah@skirmisher.net
109
- executables: []
109
+ executables:
110
+ - scmversion
110
111
  extensions: []
111
112
  extra_rdoc_files: []
112
113
  files:
@@ -116,6 +117,7 @@ files:
116
117
  - README.md
117
118
  - Rakefile
118
119
  - Thorfile
120
+ - bin/scmversion
119
121
  - features/bump.feature
120
122
  - features/bump_tags.feature
121
123
  - features/fixtures/Thorfile