semantic-version 2.0.0.pre.alpha.1 → 2.0.0.pre.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +89 -20
- data/Rakefile +1 -0
- data/lib/semantic/version/tasks.rb +236 -0
- data/lib/semantic/version.rb +11 -6
- data/semantic-version.version +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ab245c417014558c7034b5692dc17532fc0d253
|
4
|
+
data.tar.gz: 660f07bf67170be21faf606cd622c1afea2b0366
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac2b2458ce74a1c4ce9c02f9c2e0b6cd9d4a486f64135d03ff73842858fcadf1b9bae9923931cc1a5f2fafd70d2c56df72cef1845c90dfceb241f8182725f291
|
7
|
+
data.tar.gz: 649f48151f9703142f692ae84140c67e65a953325eceb41df557584f682047577d68e11140bb9413099201bd9dd8136c973c4b7c7386f606085373299dea2787
|
data/README.md
CHANGED
@@ -3,10 +3,11 @@ Semantic::Version
|
|
3
3
|
|
4
4
|
> *Semantic version objects for Ruby.*
|
5
5
|
|
6
|
-
|
6
|
+
A utility library that provides a `Semantic::Version` value object.
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
You can parse strings into version objects or construct them by hand. Any module, class, or object can be given a version through a helper. All version objects properly handle instantiation, duplication, cloning, accessors, mutators, stringification, and comparison; and come with helpful predicate methods.
|
10
|
+
|
10
11
|
|
11
12
|
Installation
|
12
13
|
------------
|
@@ -23,24 +24,25 @@ And then execute:
|
|
23
24
|
bundle
|
24
25
|
```
|
25
26
|
|
26
|
-
|
27
|
+
You can also version your gem with it.
|
27
28
|
|
28
29
|
1. Create or modify your version file:
|
29
30
|
|
30
|
-
```
|
31
|
-
# my_gem/version.rb
|
31
|
+
```diff
|
32
|
+
# lib/my_gem/version.rb
|
32
33
|
|
33
|
-
require 'semantic/version'
|
34
|
+
+require 'semantic/version'
|
34
35
|
|
35
36
|
module MyGem
|
36
|
-
|
37
|
-
|
37
|
+
- VERSION = '0.0.1'
|
38
|
+
+ extend Semantic::Version::Helper
|
39
|
+
+ version '0.0.1'
|
38
40
|
end
|
39
41
|
```
|
40
42
|
|
41
43
|
2. Modify your gemspec:
|
42
44
|
|
43
|
-
```
|
45
|
+
```diff
|
44
46
|
# my_gem.gemspec
|
45
47
|
|
46
48
|
#...
|
@@ -48,29 +50,22 @@ Or version your gem with it like so:
|
|
48
50
|
|
49
51
|
Gem::Specification.new do |spec|
|
50
52
|
#...
|
51
|
-
|
53
|
+
- spec.version = MyGem::VERSION
|
54
|
+
+ spec.version = MyGem.version
|
52
55
|
#...
|
53
56
|
spec.add_dependency "semantic-version", "~> 2.0.0"
|
54
57
|
#...
|
55
58
|
end
|
56
59
|
```
|
57
60
|
|
58
|
-
3. Update your `Gemfile.lock
|
61
|
+
3. Update your `Gemfile.lock` by executing:
|
59
62
|
|
60
63
|
```sh
|
61
64
|
bundle
|
62
65
|
```
|
63
66
|
|
64
|
-
|
65
|
-
|
66
|
-
```ruby
|
67
|
-
# Rakefile
|
68
|
-
|
69
|
-
#...
|
70
|
-
require 'semantic/version/tasks'
|
71
|
-
```
|
67
|
+
There is currently no advantage to using `Semantic::Version` objects in your gemspec, except to declare to the world that your gem is semantic versioning compliant. There is also a `semantic-version-tasks` Rakefile plugin.
|
72
68
|
|
73
|
-
There is currently no advantage to using `Semantic::Version` objects in your gemspec, outside of using the provided rake tasks, except to declare to the world that your gem is semantic versioning compliant.
|
74
69
|
|
75
70
|
Usage
|
76
71
|
-----
|
@@ -164,6 +159,16 @@ version.meta.to_s
|
|
164
159
|
|
165
160
|
version.to_s
|
166
161
|
#=> "1.0.1-alpha.12+build.2981.sha.e796e5da1f40820dcf5dab85487dd9e9a32f27e8"
|
162
|
+
version.bump.to_s
|
163
|
+
#=> "1.0.2"
|
164
|
+
version.bump(preserve: :prerelease).to_s
|
165
|
+
#=> "1.0.2-alpha.12"
|
166
|
+
version.bump(preserve: :meta).to_s
|
167
|
+
#=> "1.0.2+build.2981.sha.e796e5da1f40820dcf5dab85487dd9e9a32f27e8"
|
168
|
+
version.bump(preserve: %i[prerelease meta]).to_s
|
169
|
+
#=> "1.0.2-alpha.12+build.2981.sha.e796e5da1f40820dcf5dab85487dd9e9a32f27e8"
|
170
|
+
version.bump(preserve: :all).to_s
|
171
|
+
#=> "1.0.2-alpha.12+build.2981.sha.e796e5da1f40820dcf5dab85487dd9e9a32f27e8"
|
167
172
|
```
|
168
173
|
|
169
174
|
Most importantly, they are properly comparable per the Semantic Version spec:
|
@@ -242,6 +247,70 @@ api1 < api2
|
|
242
247
|
Take care to never use `attr_accessor` in conjunction with `version` when using this helper, or the coercion magic will be ruined.
|
243
248
|
|
244
249
|
|
250
|
+
Tasks
|
251
|
+
-----
|
252
|
+
|
253
|
+
By adding a version file to your gem's root directory you can use rake tasks to manage your versioning.
|
254
|
+
|
255
|
+
1. Add the helper tasks to your Rakefile:
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
#...
|
259
|
+
require 'semantic/version/tasks'
|
260
|
+
```
|
261
|
+
|
262
|
+
2. Create a new version file for your project by executing:
|
263
|
+
|
264
|
+
```sh
|
265
|
+
rake version:install
|
266
|
+
```
|
267
|
+
|
268
|
+
3. Reconfigure your gem to use the version file:
|
269
|
+
|
270
|
+
```diff
|
271
|
+
# lib/my_gem/version.rb
|
272
|
+
|
273
|
+
require 'semantic/version'
|
274
|
+
|
275
|
+
module MyGem
|
276
|
+
extend Semantic::Version::Helper
|
277
|
+
- version '0.0.1'
|
278
|
+
+ version from: 'my_gem.version'
|
279
|
+
end
|
280
|
+
```
|
281
|
+
|
282
|
+
High-level tasks are visible in your task list:
|
283
|
+
|
284
|
+
```bash
|
285
|
+
rake -T
|
286
|
+
rake version:install[version] # Generates a .version file in the project root
|
287
|
+
# 'version' defaults to what's in your gemspec or 0.0.1
|
288
|
+
rake version # Show version number in semantic-version.version (v2.0.0-alpha.2)
|
289
|
+
rake version:release # Removes prerelease data or bumps patch level (to v2.0.0)
|
290
|
+
rake version:bump # Bump patch version by 1 (to v2.0.1)
|
291
|
+
rake version:bump:minor # Bump minor version by 1 (to v2.1.0)
|
292
|
+
rake version:bump:major # Bump major version by 1 (to v3.0.0)
|
293
|
+
```
|
294
|
+
|
295
|
+
There are also hidden tasks for querying and manipulating the version number, namely:
|
296
|
+
|
297
|
+
```bash
|
298
|
+
rake version:number # Shows version number only
|
299
|
+
rake version:(prerelease|meta) # Shows data type only
|
300
|
+
rake version:(prerelease|meta):clear # Clears out data
|
301
|
+
rake version:(prerelease|meta):set[to] # Changes data
|
302
|
+
rake version:(prerelease|meta):append[element] # Appends element to data
|
303
|
+
```
|
304
|
+
|
305
|
+
Finally, lower-level number manipulation tasks are available following the formula:
|
306
|
+
|
307
|
+
```bash
|
308
|
+
rake version:(bump|jump):(patch|minor|major):(by|to)[num] # default num is 1
|
309
|
+
```
|
310
|
+
|
311
|
+
So, `rake version:bump:major:by[2]` will take you from `v2.0.0-alpha.2` to `v4.0.0`, and `rake version:jump:minor:to` will take you from `v2.0.0-alpha.2` to `v2.1.0`.
|
312
|
+
|
313
|
+
|
245
314
|
Contributing
|
246
315
|
------------
|
247
316
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,236 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
require 'highline/import'
|
4
|
+
require 'semantic/version'
|
5
|
+
|
6
|
+
|
7
|
+
module Semantic
|
8
|
+
class Version
|
9
|
+
module Tasks
|
10
|
+
|
11
|
+
def levels
|
12
|
+
%i[major minor patch]
|
13
|
+
end
|
14
|
+
def types
|
15
|
+
{bump: :by, jump: :to}
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_level
|
19
|
+
:patch
|
20
|
+
end
|
21
|
+
def default_type
|
22
|
+
:bump
|
23
|
+
end
|
24
|
+
def default_incrementor
|
25
|
+
:by
|
26
|
+
end
|
27
|
+
def default_num
|
28
|
+
1
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def version
|
33
|
+
@version ||= Semantic::Version.read version_filepath
|
34
|
+
end
|
35
|
+
|
36
|
+
def version_filepath
|
37
|
+
@version_filepath ||= Pathname.new find_version_file
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_version_file
|
41
|
+
ENV['VERSION_FILE'] ||= begin
|
42
|
+
candidates = Dir['*.version']
|
43
|
+
case candidates.length
|
44
|
+
when 0
|
45
|
+
ask [
|
46
|
+
'Specify a version file to read from.',
|
47
|
+
'In the future you can avoid this by running `rake version:install`,',
|
48
|
+
'or setting ENV["VERSION_FILE"] to a custom .version file location in your Rakefile.',
|
49
|
+
' > ',
|
50
|
+
].join("\n")
|
51
|
+
when 1
|
52
|
+
candidates.first
|
53
|
+
else
|
54
|
+
choose do |menu|
|
55
|
+
menu.prompt = "Multiple possible version files found. Please select one."
|
56
|
+
(0..candidates.length).each do |number|
|
57
|
+
selection = candidates[number]
|
58
|
+
menu.choice "#{number}: #{selection}" do
|
59
|
+
say "(In the future you can avoid this by setting ENV['VERSION_FILE'] in your Rakefile.)\n > "
|
60
|
+
selection
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def update_version(type, level = default_level, incrementor = default_incrementor, num = default_num)
|
69
|
+
say "#{type.to_s.capitalize.chomp('e')}ing #{version} to #{updated_version(type, level, incrementor, num)}..."
|
70
|
+
File.write version_filepath, updated_version(type, level, incrementor, num)
|
71
|
+
end
|
72
|
+
|
73
|
+
def updated_version(type, level = default_level, incrementor = default_incrementor, num = default_num)
|
74
|
+
if type == :release
|
75
|
+
version.tap do |v|
|
76
|
+
if version.prerelease?
|
77
|
+
version.prerelease = nil
|
78
|
+
else
|
79
|
+
version.bump :patch
|
80
|
+
end
|
81
|
+
end
|
82
|
+
else
|
83
|
+
version.bump(level, incrementor => num)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def generate_description(type, level = default_level, incrementor = default_incrementor, num = default_num)
|
88
|
+
if type == :release
|
89
|
+
[
|
90
|
+
'Removes prerelease data or bumps patch level',
|
91
|
+
version ? "(to v#{updated_version(type)})" : nil,
|
92
|
+
].compact.join(' ')
|
93
|
+
else
|
94
|
+
[
|
95
|
+
"#{type.to_s.capitalize} #{level} level",
|
96
|
+
(incrementor == :by and num == 1) ? nil : "#{incrementor} #{num}",
|
97
|
+
version ? "(to v#{updated_version(type, level, incrementor, num)})" : nil,
|
98
|
+
].compact.join(' ')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
include Semantic::Version::Tasks
|
107
|
+
|
108
|
+
desc [
|
109
|
+
'Show version number in',
|
110
|
+
version_filepath ? version_filepath : '.version',
|
111
|
+
version ? "(v#{version})" : nil,
|
112
|
+
].compact.join(' ')
|
113
|
+
task :version do
|
114
|
+
say "#{version}"
|
115
|
+
end
|
116
|
+
|
117
|
+
namespace :version do
|
118
|
+
|
119
|
+
desc 'Generates a .version file in the project root.'
|
120
|
+
task :install, :version do |_, opts|
|
121
|
+
|
122
|
+
gemspec_file = ENV['GEMSPEC_FILE'] ||= begin
|
123
|
+
candidates = Dir['*.gemspec']
|
124
|
+
case candidates.length
|
125
|
+
when 0
|
126
|
+
say [
|
127
|
+
'No .gemspec file found.',
|
128
|
+
'To auto-load gemspec information in future runs of `rake version:install`,',
|
129
|
+
'set ENV["GEMSPEC_FILE"] to a .gemspec file location in your Rakefile.',
|
130
|
+
].join("\n")
|
131
|
+
when 1
|
132
|
+
candidates.first
|
133
|
+
else
|
134
|
+
choose do |menu|
|
135
|
+
menu.prompt = "Multiple gemspec files found to name your .version file after. Please select one."
|
136
|
+
(0..candidates.length).each do |number|
|
137
|
+
selection = candidates[number]
|
138
|
+
menu.choice "#{number}: #{selection}" do
|
139
|
+
say ' > '
|
140
|
+
selection
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
version_file = ENV['VERSION_FILE'] ||= if gemspec_file
|
148
|
+
version_file = File.basename(gemspec_file, '.*') + '.version'
|
149
|
+
else
|
150
|
+
version_file = ask [
|
151
|
+
'Specify a version file to create.',
|
152
|
+
' > ',
|
153
|
+
].join("\n")
|
154
|
+
end
|
155
|
+
|
156
|
+
version = opts[:version] ||= if gemspec_file
|
157
|
+
load gemspec_file
|
158
|
+
Gem::Specification.find_by_name(File.basename(gemspec_file, '.*')).version
|
159
|
+
else
|
160
|
+
'0.0.1'
|
161
|
+
end
|
162
|
+
|
163
|
+
File.write version_file, version
|
164
|
+
end
|
165
|
+
|
166
|
+
types.each do |type, incrementor|
|
167
|
+
|
168
|
+
desc generate_description(type, default_level, types[default_type], default_num) if type == default_type
|
169
|
+
task type do
|
170
|
+
update_version(type, default_level, types[type], default_num)
|
171
|
+
end
|
172
|
+
|
173
|
+
namespace type do
|
174
|
+
|
175
|
+
%i[major minor patch].each do |level|
|
176
|
+
|
177
|
+
desc generate_description(type, level, types[type], default_num) if type == default_type and level != default_level
|
178
|
+
task level do
|
179
|
+
update_version(type, level, types[type], default_num)
|
180
|
+
end
|
181
|
+
|
182
|
+
namespace level do
|
183
|
+
desc generate_description(type, level, types[type], 'the specified number') unless true # type == default_type
|
184
|
+
task types[type], :num do |_, opts|
|
185
|
+
update_version(type, level, types[type], Integer(opts[:num]))
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
desc generate_description(:release)
|
196
|
+
task :release do
|
197
|
+
update_version(:release)
|
198
|
+
end
|
199
|
+
|
200
|
+
task :number do
|
201
|
+
say version.number
|
202
|
+
end
|
203
|
+
|
204
|
+
%i[prerelease meta].each do |data|
|
205
|
+
|
206
|
+
task data do
|
207
|
+
say version.send data
|
208
|
+
end
|
209
|
+
|
210
|
+
namespace data do
|
211
|
+
|
212
|
+
task :clear do
|
213
|
+
updated_version = version.tap do |v|
|
214
|
+
v.send :"#{data}=", nil
|
215
|
+
end
|
216
|
+
File.write version_filepath, updated_version
|
217
|
+
end
|
218
|
+
|
219
|
+
task :set, :to do |_, opts|
|
220
|
+
updated_version = version.tap do |v|
|
221
|
+
v.send :"#{data}=", *opts[:to].split('.')
|
222
|
+
end
|
223
|
+
File.write version_filepath, updated_version
|
224
|
+
end
|
225
|
+
|
226
|
+
task :append, :element do |_, opts|
|
227
|
+
updated_version = version.tap do |v|
|
228
|
+
v.send(:"#{data}") << opts[:element]
|
229
|
+
end
|
230
|
+
File.write version_filepath, updated_version
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
data/lib/semantic/version.rb
CHANGED
@@ -13,9 +13,6 @@ module Semantic
|
|
13
13
|
|
14
14
|
class << self
|
15
15
|
|
16
|
-
extend Forwardable
|
17
|
-
def_delegators :number, :major, :minor, :patch, :stable?
|
18
|
-
|
19
16
|
def pattern
|
20
17
|
/(?<number>\d+\.\d+\.\d+)(\-(?<prerelease>[^+]+))?(\+(?<meta>.+))?/
|
21
18
|
end
|
@@ -40,13 +37,21 @@ module Semantic
|
|
40
37
|
super Number.new(major, minor, patch), Data.new(*prerelease), Data.new(*meta)
|
41
38
|
end
|
42
39
|
|
40
|
+
extend Forwardable
|
41
|
+
def_delegators :number, :major, :minor, :patch, :stable?
|
42
|
+
|
43
43
|
def bump(*args)
|
44
44
|
clone.bump!(*args)
|
45
45
|
end
|
46
46
|
|
47
|
-
def bump!(*args)
|
47
|
+
def bump!(*args, preserve: [], **opts)
|
48
48
|
tap do |version|
|
49
49
|
version.number.bump!(*args)
|
50
|
+
preserve = Array(preserve)
|
51
|
+
unless preserve.include? :all
|
52
|
+
version.prerelease = nil unless preserve.include? :prerelease
|
53
|
+
version.meta = nil unless preserve.include? :meta
|
54
|
+
end
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
@@ -55,7 +60,7 @@ module Semantic
|
|
55
60
|
end
|
56
61
|
|
57
62
|
def prerelease= *array
|
58
|
-
self[:prerelease] = Data.new(*array)
|
63
|
+
self[:prerelease] = array.flatten.compact.empty? ? nil : Data.new(*array.flatten)
|
59
64
|
end
|
60
65
|
|
61
66
|
def meta?
|
@@ -63,7 +68,7 @@ module Semantic
|
|
63
68
|
end
|
64
69
|
|
65
70
|
def meta= *array
|
66
|
-
self[:meta] = Data.new(*array)
|
71
|
+
self[:meta] = array.flatten.compact.empty? ? nil : Data.new(*array.flatten)
|
67
72
|
end
|
68
73
|
|
69
74
|
def to_s
|
data/semantic-version.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0-alpha.
|
1
|
+
2.0.0-alpha.2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic-version
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.pre.alpha.
|
4
|
+
version: 2.0.0.pre.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Keele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/semantic/version/data.rb
|
88
88
|
- lib/semantic/version/helper.rb
|
89
89
|
- lib/semantic/version/number.rb
|
90
|
+
- lib/semantic/version/tasks.rb
|
90
91
|
- lib/semantic/version/to_string.rb
|
91
92
|
- semantic-version.gemspec
|
92
93
|
- semantic-version.version
|