semver2 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.semver +5 -0
- data/README.md +33 -0
- data/bin/semver +83 -0
- data/lib/semver/semvermissingerror.rb +2 -0
- data/lib/semver.rb +99 -0
- data/semver2.gemspec +15 -0
- metadata +52 -0
data/.semver
ADDED
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
SemVer
|
2
|
+
======
|
3
|
+
|
4
|
+
quickstart on the command line
|
5
|
+
------------------------------
|
6
|
+
install it
|
7
|
+
|
8
|
+
% gem install semver
|
9
|
+
|
10
|
+
use it
|
11
|
+
|
12
|
+
% semver init
|
13
|
+
% semver tag # => v0.0.0
|
14
|
+
% semver inc minor # => v0.1.0
|
15
|
+
% git tag -a `semver tag`
|
16
|
+
% say 'that was easy'
|
17
|
+
|
18
|
+
quickstart for ruby
|
19
|
+
-------------------
|
20
|
+
require 'semver'
|
21
|
+
v = SemVer.find
|
22
|
+
v.major # => "0"
|
23
|
+
v.major += 1
|
24
|
+
v.major # => "1"
|
25
|
+
v.format "%M.%m.%p" # => "1.1.0"
|
26
|
+
v.to_s # => "v1.1.0"
|
27
|
+
v.save
|
28
|
+
|
29
|
+
git integration
|
30
|
+
---------------
|
31
|
+
% git config --global alias.semtag '!git tag -a $(semver tag) -m "tagging $(semver tag)"'
|
32
|
+
|
33
|
+
[Franco Lazzarino](mailto:flazzarino@gmail.com)
|
data/bin/semver
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'semver'
|
5
|
+
|
6
|
+
class CommandError < StandardError; end
|
7
|
+
|
8
|
+
begin
|
9
|
+
command = ARGV.shift || 'tag'
|
10
|
+
|
11
|
+
case command
|
12
|
+
when /^init(ialize)?$/
|
13
|
+
file = SemVer::FILE_NAME
|
14
|
+
|
15
|
+
if File.exist? file
|
16
|
+
puts "#{file} already exists"
|
17
|
+
else
|
18
|
+
version = SemVer.new
|
19
|
+
version.save file
|
20
|
+
end
|
21
|
+
|
22
|
+
when /^inc(rement)?$/
|
23
|
+
version = SemVer.find
|
24
|
+
dimension = ARGV.shift or raise CommandError, "required: major | minor | patch"
|
25
|
+
|
26
|
+
case dimension
|
27
|
+
when 'major'
|
28
|
+
version.major += 1
|
29
|
+
version.minor = 0
|
30
|
+
version.patch = 0
|
31
|
+
|
32
|
+
when 'minor'
|
33
|
+
version.minor += 1
|
34
|
+
version.patch = 0
|
35
|
+
|
36
|
+
when 'patch'
|
37
|
+
version.patch += 1
|
38
|
+
|
39
|
+
else
|
40
|
+
raise CommandError, "#{dimension} is invalid: major | minor | patch"
|
41
|
+
end
|
42
|
+
|
43
|
+
version.special = ''
|
44
|
+
version.save
|
45
|
+
|
46
|
+
when /^spe(cial)?$/
|
47
|
+
version = SemVer.find
|
48
|
+
special_str = ARGV.shift or raise CommandError, "required: an arbitrary string (beta, alfa, romeo, etc)"
|
49
|
+
version.special = special_str
|
50
|
+
version.save
|
51
|
+
|
52
|
+
when 'format'
|
53
|
+
version = SemVer.find
|
54
|
+
format_str = ARGV.shift or raise CommandError, "required: format string"
|
55
|
+
version.format format_str
|
56
|
+
|
57
|
+
when 'tag'
|
58
|
+
version = SemVer.find
|
59
|
+
puts version.to_s
|
60
|
+
|
61
|
+
when 'help'
|
62
|
+
puts <<-HELP
|
63
|
+
semver commands
|
64
|
+
---------------
|
65
|
+
|
66
|
+
init[ialze] # initialize semantic version tracking
|
67
|
+
inc[rement] major | minor | patch # increment a specific version number
|
68
|
+
spe[cial] [STRING] # set a special version suffix
|
69
|
+
format # printf like format: %M, %m, %p, %s
|
70
|
+
tag # equivalent to format 'v%M.%m.%p%s'
|
71
|
+
help
|
72
|
+
|
73
|
+
PLEASE READ http://semver.org
|
74
|
+
HELP
|
75
|
+
|
76
|
+
else raise CommandError, "invalid command #{command}"
|
77
|
+
end
|
78
|
+
|
79
|
+
rescue CommandError => e
|
80
|
+
puts e.message
|
81
|
+
puts "#{$0} help for more info"
|
82
|
+
exit 1
|
83
|
+
end
|
data/lib/semver.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'semver/semvermissingerror'
|
3
|
+
|
4
|
+
class SemVer
|
5
|
+
|
6
|
+
FILE_NAME = '.semver'
|
7
|
+
TAG_FORMAT = 'v%M.%m.%p%s'
|
8
|
+
|
9
|
+
def SemVer.find dir=nil
|
10
|
+
v = SemVer.new
|
11
|
+
f = SemVer.find_file dir
|
12
|
+
v.load f
|
13
|
+
v
|
14
|
+
end
|
15
|
+
|
16
|
+
def SemVer.find_file dir=nil
|
17
|
+
dir ||= Dir.pwd
|
18
|
+
raise "#{dir} is not a directory" unless File.directory? dir
|
19
|
+
path = File.join dir, FILE_NAME
|
20
|
+
|
21
|
+
Dir.chdir dir do
|
22
|
+
while !File.exists? path do
|
23
|
+
raise SemVerMissingError, "#{dir} is not semantic versioned", caller if File.dirname(path).match(/(\w:\/|\/)$/i)
|
24
|
+
path = File.join File.dirname(path), ".."
|
25
|
+
path = File.expand_path File.join(path, FILE_NAME)
|
26
|
+
puts "semver: looking at #{path}"
|
27
|
+
end
|
28
|
+
return path
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :major, :minor, :patch, :special
|
34
|
+
|
35
|
+
def initialize major=0, minor=0, patch=0, special=''
|
36
|
+
major.kind_of? Integer or raise "invalid major: #{major}"
|
37
|
+
minor.kind_of? Integer or raise "invalid minor: #{minor}"
|
38
|
+
patch.kind_of? Integer or raise "invalid patch: #{patch}"
|
39
|
+
|
40
|
+
unless special.empty?
|
41
|
+
special =~ /[A-Za-z][0-9A-Za-z-]+/ or raise "invalid special: #{special}"
|
42
|
+
end
|
43
|
+
|
44
|
+
@major, @minor, @patch, @special = major, minor, patch, special
|
45
|
+
end
|
46
|
+
|
47
|
+
def load file
|
48
|
+
@file = file
|
49
|
+
hash = YAML.load_file(file) || {}
|
50
|
+
@major = hash[:major] or raise "invalid semver file: #{file}"
|
51
|
+
@minor = hash[:minor] or raise "invalid semver file: #{file}"
|
52
|
+
@patch = hash[:patch] or raise "invalid semver file: #{file}"
|
53
|
+
@special = hash[:special] or raise "invalid semver file: #{file}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def save file=nil
|
57
|
+
file ||= @file
|
58
|
+
|
59
|
+
hash = {
|
60
|
+
:major => @major,
|
61
|
+
:minor => @minor,
|
62
|
+
:patch => @patch,
|
63
|
+
:special => @special
|
64
|
+
}
|
65
|
+
|
66
|
+
yaml = YAML.dump hash
|
67
|
+
open(file, 'w') { |io| io.write yaml }
|
68
|
+
end
|
69
|
+
|
70
|
+
def format fmt
|
71
|
+
fmt.gsub! '%M', @major.to_s
|
72
|
+
fmt.gsub! '%m', @minor.to_s
|
73
|
+
fmt.gsub! '%p', @patch.to_s
|
74
|
+
fmt.gsub! '%s', @special.to_s
|
75
|
+
fmt
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_s
|
79
|
+
format TAG_FORMAT
|
80
|
+
end
|
81
|
+
|
82
|
+
def <=> other
|
83
|
+
maj = major.to_i <=> other.major.to_i
|
84
|
+
return maj unless maj == 0
|
85
|
+
|
86
|
+
min = minor.to_i <=> other.minor.to_i
|
87
|
+
return min unless min == 0
|
88
|
+
|
89
|
+
pat = patch.to_i <=> other.patch.to_i
|
90
|
+
return pat unless pat == 0
|
91
|
+
|
92
|
+
spe = special <=> other.special
|
93
|
+
return spec unless spe == 0
|
94
|
+
|
95
|
+
0
|
96
|
+
end
|
97
|
+
|
98
|
+
include Comparable
|
99
|
+
end
|
data/semver2.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require 'semver'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "semver2"
|
6
|
+
spec.version = SemVer.find.format '%M.%m.%p'
|
7
|
+
spec.summary = "Semantic Versioning"
|
8
|
+
spec.description = "maintain versions as per http://semver.org"
|
9
|
+
spec.email = "henrik@haf.se"
|
10
|
+
spec.authors = ["Francesco Lazzarino", "Henrik Feldt"]
|
11
|
+
spec.homepage = 'https://github.com/haf/semver'
|
12
|
+
spec.executables << 'semver'
|
13
|
+
spec.files = [".semver", "semver2.gemspec", "README.md"] + Dir["lib/**/*.rb"] + Dir['bin/*']
|
14
|
+
spec.has_rdoc = true
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: semver2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Francesco Lazzarino
|
9
|
+
- Henrik Feldt
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-07-07 00:00:00.000000000Z
|
14
|
+
dependencies: []
|
15
|
+
description: maintain versions as per http://semver.org
|
16
|
+
email: henrik@haf.se
|
17
|
+
executables:
|
18
|
+
- semver
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .semver
|
23
|
+
- semver2.gemspec
|
24
|
+
- README.md
|
25
|
+
- lib/semver/semvermissingerror.rb
|
26
|
+
- lib/semver.rb
|
27
|
+
- bin/semver
|
28
|
+
homepage: https://github.com/haf/semver
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.8.5
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: Semantic Versioning
|
52
|
+
test_files: []
|