version_tracker 0.1.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.
- checksums.yaml +7 -0
- data/README.md +54 -0
- data/bin/version +51 -0
- data/lib/errors/version_tracker_error.rb +2 -0
- data/lib/tasks/version_tracker.rake +44 -0
- data/lib/version_tracker/bumper.rb +106 -0
- data/lib/version_tracker/command_line.rb +118 -0
- data/lib/version_tracker/file_manager.rb +31 -0
- data/lib/version_tracker/railtie.rb +14 -0
- data/lib/version_tracker/version.rb +3 -0
- data/lib/version_tracker.rb +9 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3c9ccf35a8fd399ff71c248ef6c56e67cea3f3f8
|
4
|
+
data.tar.gz: 58f795cc7fc22539870662cbe709e6cd24ad280f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cbb5de30de51935ab5ee4b609113da30ddc11c381dd76d172b2dfa51e24dd7486e46b0e76f8db96ef25a9db9a7f547fb6f3374d41003b838f2286191ac95901a
|
7
|
+
data.tar.gz: 4ef94aef036c5a2ef1675ca0f783ef9fdc9e33727dcfb99a8f937bb1b6093e4514e4a2ee1379d503d0af362f276e38d865c75e5baf00f645929c07b40095fb8d
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# VersionTracker
|
2
|
+
|
3
|
+
Add Version to your Rails Application.
|
4
|
+
Currently supported version format is *major.minor.patch*, i.e. `0.0.0`
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'version_tracker'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install version_tracker
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Using Command Line
|
25
|
+
```
|
26
|
+
version init [value] # Initialize VERSION File with provided value.
|
27
|
+
# Default: 0.0.0 if value is not provided and VERSION File does not exist
|
28
|
+
version read # Read current VERSION
|
29
|
+
version bump [part] # Bump VERSION based on part. Valid part: major, minor, patch. Default: patch
|
30
|
+
version tag # Tag using current VERSION
|
31
|
+
|
32
|
+
OPTIONS:
|
33
|
+
-r, --release Push to release branch using current version
|
34
|
+
-m, --message=MESSAGE Push with custom commit message
|
35
|
+
-p, --push Push to current branch
|
36
|
+
-h, --help Help
|
37
|
+
```
|
38
|
+
|
39
|
+
### Using Rake Tasks
|
40
|
+
```ruby
|
41
|
+
rake version_tracker:initialize # Initialize Version
|
42
|
+
rake version_tracker:current_version # Read Version
|
43
|
+
rake version_tracker:bump_major # Bump Major
|
44
|
+
rake version_tracker:bump_minor # Bump Minor
|
45
|
+
rake version_tracker:bump_patch # Bump Patch
|
46
|
+
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it ( https://github.com/[my-github-username]/version_tracker/fork )
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create a new Pull Request
|
data/bin/version
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'version_tracker/command_line'
|
4
|
+
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
option_parser =
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
opts.banner = <<BANNER
|
11
|
+
Version Tracker: Manages Rails Application Version
|
12
|
+
|
13
|
+
USAGE:
|
14
|
+
version init [value] # Initialize VERSION File with provided value. Default: 0.0.0 if value is not provided and VERSION File does not exist
|
15
|
+
version read # Read current VERSION
|
16
|
+
version bump [part] # Bump VERSION based on part. Valid part: major, minor, patch. Default: patch
|
17
|
+
version tag # Tag using current VERSION
|
18
|
+
|
19
|
+
OPTIONS:
|
20
|
+
BANNER
|
21
|
+
|
22
|
+
opts.on('-r', '--release', 'Push to release branch using current version') do
|
23
|
+
options[:release] = true
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
opts.on('-m MESSAGE', '--message=MESSAGE', 'Push with custom commit message') do |message|
|
28
|
+
options[:message] = message
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
opts.on('-p', '--push', 'Push to current branch') do
|
33
|
+
options[:push] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
opts.on('-h', '--help', 'Help') do
|
38
|
+
puts opts
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
option_parser.parse!
|
45
|
+
|
46
|
+
result, status = VersionTracker::CommandLine.new.execute ARGV, options
|
47
|
+
|
48
|
+
puts result
|
49
|
+
puts option_parser if status == VersionTracker::CommandLine::RESULT_STATUS::ERROR
|
50
|
+
|
51
|
+
exit status
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'version_tracker'
|
2
|
+
|
3
|
+
|
4
|
+
namespace :version_tracker do
|
5
|
+
|
6
|
+
|
7
|
+
def bump part
|
8
|
+
version_tracker = VersionTracker::Bumper.new
|
9
|
+
version_tracker.bump :part => part
|
10
|
+
|
11
|
+
puts version_tracker.version
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
desc 'Initialize Version'
|
16
|
+
task :initialize do
|
17
|
+
VersionTracker::Bumper.new.init
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
desc 'Read Version'
|
22
|
+
task :current_version do
|
23
|
+
puts VersionTracker::Bumper.new.version
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
desc 'Bump Major'
|
28
|
+
task :bump_major do
|
29
|
+
bump :major
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
desc 'Bump Minor'
|
34
|
+
task :bump_minor do
|
35
|
+
bump :minor
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
desc 'Bump Patch'
|
40
|
+
task :bump_patch do
|
41
|
+
bump :patch
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#
|
2
|
+
#
|
3
|
+
# Reference:
|
4
|
+
# http://semver.org/
|
5
|
+
#
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'errors/version_tracker_error'
|
9
|
+
require 'version_tracker/file_manager'
|
10
|
+
|
11
|
+
|
12
|
+
module VersionTracker
|
13
|
+
|
14
|
+
class Bumper
|
15
|
+
|
16
|
+
attr_accessor :parts
|
17
|
+
|
18
|
+
|
19
|
+
DELIMITER = '.'
|
20
|
+
INITIAL_VERSION = '0.0.0'
|
21
|
+
BASIC_FORMAT = /^\d+\.\d+\.\d+$/
|
22
|
+
|
23
|
+
|
24
|
+
module PARTS
|
25
|
+
MAJOR = 0
|
26
|
+
MINOR = 1
|
27
|
+
PATCH = 2
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def init version = nil
|
32
|
+
raise VersionTrackerError, 'Version format is invalid' if version && !(BASIC_FORMAT =~ version)
|
33
|
+
|
34
|
+
FileManager.write(version || INITIAL_VERSION)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# Options:
|
41
|
+
# :part
|
42
|
+
# :value
|
43
|
+
#
|
44
|
+
#
|
45
|
+
def bump options = {}
|
46
|
+
raise VersionTrackerError, 'Version File is not initialized' unless FileManager.initialized?
|
47
|
+
|
48
|
+
part = options[:part] || :patch
|
49
|
+
|
50
|
+
unless [:major, :minor, :patch].include?(part)
|
51
|
+
raise VersionTrackerError, 'Invalid Part Parameter.'
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
value = options[:value]
|
56
|
+
if value && !value.is_a?(Integer)
|
57
|
+
raise VersionTrackerError, 'Value should be of Integer Type'
|
58
|
+
end
|
59
|
+
|
60
|
+
self.send "bump_#{part}".to_sym, value
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def version
|
65
|
+
raise VersionTrackerError, 'Version File is not initialized' unless FileManager.initialized?
|
66
|
+
|
67
|
+
FileManager.read
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def parts
|
72
|
+
version_parts = self.version.split DELIMITER
|
73
|
+
|
74
|
+
hash = {}
|
75
|
+
hash[:major] = version_parts[PARTS::MAJOR].to_i
|
76
|
+
hash[:minor] = version_parts[PARTS::MINOR].to_i
|
77
|
+
hash[:patch] = version_parts[PARTS::PATCH].to_i
|
78
|
+
|
79
|
+
hash
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
protected
|
85
|
+
|
86
|
+
def bump_major value
|
87
|
+
value = value || self.parts[:major] + 1
|
88
|
+
FileManager.write [value, 0, 0].join DELIMITER
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
def bump_minor value
|
93
|
+
value = value || self.parts[:minor] + 1
|
94
|
+
FileManager.write [self.parts[:major], value, 0].join DELIMITER
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def bump_patch value
|
99
|
+
value = value || self.parts[:patch] + 1
|
100
|
+
FileManager.write(
|
101
|
+
[self.parts[:major], self.parts[:minor], value].join DELIMITER)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'errors/version_tracker_error'
|
2
|
+
require 'version_tracker/bumper'
|
3
|
+
|
4
|
+
|
5
|
+
module VersionTracker
|
6
|
+
|
7
|
+
class CommandLine
|
8
|
+
|
9
|
+
module COMMANDS
|
10
|
+
INIT = 'init'
|
11
|
+
BUMP = 'bump'
|
12
|
+
READ = 'read'
|
13
|
+
TAG = 'tag'
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
module RESULT_STATUS
|
18
|
+
SUCCESS = 0
|
19
|
+
ERROR = 1
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
VALID_COMMANDS = %w(init bump read tag)
|
24
|
+
VALID_PARTS = %w(major minor patch)
|
25
|
+
DEFAULT_PART = 'patch'
|
26
|
+
DEFAULT_COMMIT_MESSAGE = 'Set Version to'
|
27
|
+
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@version_tracker = VersionTracker::Bumper.new
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def execute args = [], options = {}
|
35
|
+
command = args[0] || COMMANDS::READ
|
36
|
+
raise VersionTrackerError, 'Invalid command' unless VALID_COMMANDS.include?(command)
|
37
|
+
|
38
|
+
@options = options.merge(:argument => args[1])
|
39
|
+
|
40
|
+
|
41
|
+
result =
|
42
|
+
case command
|
43
|
+
when COMMANDS::INIT
|
44
|
+
@version_tracker.init @options[:argument]
|
45
|
+
@version_tracker.version
|
46
|
+
when COMMANDS::READ
|
47
|
+
@version_tracker.version
|
48
|
+
when COMMANDS::TAG
|
49
|
+
self.git_tag
|
50
|
+
"Successfully created tag for #{@version_tracker.version}"
|
51
|
+
when COMMANDS::BUMP
|
52
|
+
self.bump
|
53
|
+
@version_tracker.version
|
54
|
+
end
|
55
|
+
|
56
|
+
self.release if !!@options[:release]
|
57
|
+
self.push if !!@options[:push] && !@options[:release]
|
58
|
+
|
59
|
+
[result, RESULT_STATUS::SUCCESS]
|
60
|
+
rescue VersionTrackerError => e
|
61
|
+
return [e.message, RESULT_STATUS::ERROR]
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
def git_tag
|
71
|
+
result = system("git tag #{@version_tracker.version}")
|
72
|
+
raise VersionTrackerError, 'Failed to create tag' unless result
|
73
|
+
|
74
|
+
system("git push origin #{@version_tracker.version}")
|
75
|
+
raise VersionTrackerError, 'Failed to create tag' unless result
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def bump
|
80
|
+
part = @options[:argument] || DEFAULT_PART
|
81
|
+
raise VersionTrackerError, 'Invalid part' unless VALID_PARTS.include?(part)
|
82
|
+
|
83
|
+
@version_tracker.bump :part => part.to_sym
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def release
|
88
|
+
branch = ['release', @version_tracker.version].join '/'
|
89
|
+
|
90
|
+
exists = system "git rev-parse --verify #{branch}"
|
91
|
+
create_branch = '-b' unless exists
|
92
|
+
|
93
|
+
system ['git', 'checkout', create_branch, branch].join(' ')
|
94
|
+
self.git_commit branch
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def push
|
99
|
+
result = `git rev-parse --abbrev-ref HEAD`
|
100
|
+
branch = result.gsub /\n/, ''
|
101
|
+
self.git_commit branch
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
def message
|
106
|
+
@options[:message] || [DEFAULT_COMMIT_MESSAGE, @version_tracker.version].join(' ')
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def git_commit branch
|
111
|
+
system 'git add VERSION'
|
112
|
+
system "git commit -m '#{self.message}'"
|
113
|
+
system "git push origin #{branch}"
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'errors/version_tracker_error'
|
2
|
+
|
3
|
+
|
4
|
+
module VersionTracker
|
5
|
+
|
6
|
+
class FileManager
|
7
|
+
|
8
|
+
FILENAME = 'VERSION'
|
9
|
+
|
10
|
+
|
11
|
+
def self.initialized?
|
12
|
+
File.exist? FILENAME
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def self.read
|
17
|
+
raise VersionTrackerError, 'VERSION File does not exist.' unless self.initialized?
|
18
|
+
|
19
|
+
File.read FILENAME
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def self.write version
|
24
|
+
File.open(FILENAME, 'w') do |file|
|
25
|
+
file.write version
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: version_tracker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Braymon Ramirez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.0
|
55
|
+
description: Add Version to your Rails Application
|
56
|
+
email:
|
57
|
+
- braymon.ramirez@gmail.com
|
58
|
+
executables:
|
59
|
+
- version
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- README.md
|
64
|
+
- bin/version
|
65
|
+
- lib/errors/version_tracker_error.rb
|
66
|
+
- lib/tasks/version_tracker.rake
|
67
|
+
- lib/version_tracker.rb
|
68
|
+
- lib/version_tracker/bumper.rb
|
69
|
+
- lib/version_tracker/command_line.rb
|
70
|
+
- lib/version_tracker/file_manager.rb
|
71
|
+
- lib/version_tracker/railtie.rb
|
72
|
+
- lib/version_tracker/version.rb
|
73
|
+
homepage: https://github.com/brayramirez/version_tracker
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Provides command line and rake tasks to bump versions of your Rails Applications
|
97
|
+
test_files: []
|