tagging 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f685e3b15875e4342cdd304fdf030645c0312b77
4
+ data.tar.gz: 7226632615697ab31240ca7d49b0d7af63139527
5
+ SHA512:
6
+ metadata.gz: 4650df9403e7c75449bd2c84f06730b8efa930f5c90d42ced69fe1cf60bdc3868c49243f248310f1e1c81e4390540a8885f4bdcce5325704403f8820255c2ba2
7
+ data.tar.gz: cd7dc5d24c8ddc1172007f898f753495315e55c9426772684767680401a6bf63f881643fdc5d22afdea7dcd288f65028ecbb1522996034dca8e82cb9d04c3094
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .DS_Store
2
+ .idea
3
+ pkg
4
+ nbproject
5
+ TODO.txt
6
+ spec/next_gem_version
7
+ *.gem
8
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in .gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006-2009 Jeff Patmon
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # Tagging
2
+
3
+ Automated version management for your Gem builds.
4
+
5
+ ## Resources
6
+
7
+ Install
8
+
9
+ ```bash
10
+ $ sudo gem install gem_version
11
+
12
+ or
13
+
14
+ $ require 'gem_version'
15
+ ```
16
+
17
+ ## Description
18
+
19
+ Never bother updating the version for your next gem build by hand. Configured in your Rakefile, gem_version automatically provides the next version and commits it to the repository.
20
+
21
+ ## Use
22
+
23
+ * Rake
24
+
25
+ `bundle exec rake tagging:push`
26
+
27
+ * Bash
28
+
29
+ `cd /rails/app/path && git-tagging push`
30
+
31
+
32
+ ## Adding other files
33
+
34
+ To add other files to the GemVersion.commit_and_push method use the block. For instance,
35
+ if you want to commit and push the gemspec file also:
36
+
37
+ task :gemspec do
38
+ File.open("#{spec.name}.gemspec", 'w') do |f|
39
+ f.write spec.to_ruby
40
+ end
41
+ GemVersion.increment_version
42
+ GemVersion.commit_and_push do |git|
43
+ git.add("#{spec.name}.gemspec")
44
+ end
45
+ end
46
+
47
+ ## Bumping or resetting the next gem version
48
+
49
+ GemVersion creates a file named 'next_gem_version' in the root directory of your project which contains the 'next' gem version. Edit the version in this file or use the rake tasks to bump or set the version for the next build.
50
+
51
+ GemVersion increments the last component of your version. If you need to bump from 0.1.x to 0.2.x, you'll need to bump the version manually.
52
+
53
+ ## Rake tasks
54
+
55
+ Two rake tasks gem:clean and gem:version are available whenever you require gem_version.
56
+
57
+ * Clean the project root of .gem and .gemspec files.
58
+
59
+ rake gem:clean
60
+
61
+ * Get the next gem version
62
+
63
+ rake gem:version
64
+
65
+ * Set the next gem version
66
+
67
+ rake gem:version set=0.1.0
68
+
69
+
70
+ ## Dependencies
71
+
72
+ * Git gem (>= 1.2.5)
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require "tagging/tasks/app_version"
4
+ require "tagging/tasks/gem_version"
data/bin/git-tagging ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'optparse'
5
+ require 'tagging/app_version'
6
+ require 'tagging/gem_version'
7
+
8
+ module Tagging
9
+ class CLI
10
+
11
+ def self.run(options)
12
+ if options[:push]
13
+ puts Tagging::AppVersion.increment_and_push rescue exit 1
14
+ exit 0
15
+ elsif options[:version]
16
+ puts Tagging::AppVersion.version rescue exit 1
17
+ exit 0
18
+ elsif options[:next_version]
19
+ puts Tagging::AppVersion.increment_version rescue exit 1
20
+ exit 0
21
+ else
22
+ puts "## [message] Run `tagging --help' for more options."
23
+ end
24
+ end
25
+
26
+ def self.options_verify?(op)
27
+ if op[:help] and ([op[:push], op[:version], op[:next_version]].compact.length > 1)
28
+ warn("[fail] Can only push, version or next_version. Choose one.")
29
+ exit(1)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ options = {}
36
+ opt_parser = OptionParser.new do |opt|
37
+ opt.banner = "Usage: tagging [OPTIONS]"
38
+ opt.separator ""
39
+ opt.separator "Options"
40
+
41
+ opt.on("-p","--push","Increment version and push to tag") do |value|
42
+ options[:push] = value
43
+ end
44
+
45
+ opt.on("-v","--version","Show current version into rails app path") do |value|
46
+ options[:version] = value
47
+ end
48
+
49
+ opt.on("-n","--next_version","Show the next version") do |value|
50
+ options[:next_version] = value
51
+ end
52
+
53
+ opt.on("-h","--help","help") do
54
+ puts opt_parser
55
+ exit
56
+ end
57
+ end
58
+ opt_parser.parse!
59
+
60
+ Tagging::CLI.run(options)
@@ -0,0 +1,67 @@
1
+ require 'rubygems'
2
+ require 'git'
3
+ require 'logger'
4
+
5
+ load File.dirname(__FILE__) + '/tasks/gem_version.rake'
6
+
7
+
8
+ module GemVersion
9
+ @@gem_version_file = 'next_gem_version'
10
+ @@default_commit_message = 'incremented gem version'
11
+
12
+ def self.gem_version_file=(str)
13
+ @@gem_version_file = str
14
+ end
15
+
16
+ def self.next_version
17
+ init_version_file unless File.exist?(@@gem_version_file)
18
+ file = File.new(@@gem_version_file, 'r')
19
+ version = file.gets.chomp
20
+ raise "#{@@gem_version_file} file corrupt" unless self.version_format_valid?(version)
21
+ file.close
22
+ version
23
+ end
24
+
25
+ def self.set_version(version)
26
+ raise "Invalid version format" unless self.version_format_valid?(version)
27
+ update_version(version)
28
+ end
29
+
30
+ def self.version_format_valid?(version)
31
+ (version && version =~ /^\d+\.\d+[\.\d+]+$/)
32
+ end
33
+
34
+ def self.init_version_file
35
+ file = File.new(@@gem_version_file, 'w')
36
+ file.puts '0.0.1'
37
+ file.close
38
+ end
39
+
40
+ def self.increment_and_push
41
+ self.increment_version
42
+ self.commit_and_push
43
+ end
44
+
45
+ def self.increment_version
46
+ version = self.next_version
47
+ components = version.split('.')
48
+ components.push((components.pop.to_i + 1).to_s)
49
+ new_version = components.join('.')
50
+ update_version(new_version)
51
+ version
52
+ end
53
+
54
+ def self.update_version(new_version)
55
+ file = File.new(@@gem_version_file, 'w')
56
+ file.puts new_version
57
+ file.close
58
+ end
59
+
60
+ def self.commit_and_push(project_directory = nil, msg = nil, &block)
61
+ g=Git.open(project_directory || Dir.pwd, :log=>Logger.new(STDOUT))
62
+ g.add(@@gem_version_file)
63
+ yield(g) if block_given?
64
+ g.commit(msg || @@default_commit_message)
65
+ g.push
66
+ end
67
+ end
@@ -0,0 +1,38 @@
1
+ require 'git'
2
+ require 'logger'
3
+
4
+ module Tagging
5
+ class AppVersion
6
+ @@default_commit_message = 'versioning by CI'
7
+ @@version
8
+
9
+ def self.version
10
+ @@version ||= `git -C #{Dir.pwd} describe --tags $(git -C #{Dir.pwd} for-each-ref refs/tags --sort=-taggerdate --format='%(objectname)' --count=1)`.chomp
11
+ @@version = self.init_version_file unless self.version_format_valid?(@@version)
12
+ @@version
13
+ end
14
+
15
+ def self.version_format_valid?(v)
16
+ (v && v =~ /^v\d+\.\d+\.\d+-[\.\d+]+$/)
17
+ end
18
+
19
+ def self.init_version_file
20
+ initial_version = 'v0.0.1-00'
21
+ end
22
+
23
+ def self.increment_and_push
24
+ self.increment_version
25
+ self.commit_and_push
26
+ end
27
+
28
+ def self.increment_version
29
+ @@version = self.version.next
30
+ end
31
+
32
+ def self.commit_and_push(project_directory = nil, msg = nil, &block)
33
+ g=Git.open(project_directory || Dir.pwd, :log=>Logger.new(STDOUT))
34
+ g.add_tag(self.version, nil, message: @@default_commit_message)
35
+ g.push('origin', "refs/tags/#{self.version}", f: true)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,62 @@
1
+ module Tagging
2
+ class GemVersion
3
+ @@gem_version_file = 'next_gem_version'
4
+ @@default_commit_message = 'incremented gem version'
5
+
6
+ def self.gem_version_file=(str)
7
+ @@gem_version_file = str
8
+ end
9
+
10
+ def self.next_version
11
+ init_version_file unless File.exist?(@@gem_version_file)
12
+ file = File.new(@@gem_version_file, 'r')
13
+ version = file.gets.chomp
14
+ raise "#{@@gem_version_file} file corrupt" unless self.version_format_valid?(version)
15
+ file.close
16
+ version
17
+ end
18
+
19
+ def self.set_version(version)
20
+ raise "Invalid version format" unless self.version_format_valid?(version)
21
+ update_version(version)
22
+ end
23
+
24
+ def self.version_format_valid?(version)
25
+ (version && version =~ /^\d+\.\d+[\.\d+]+$/)
26
+ end
27
+
28
+ def self.init_version_file
29
+ file = File.new(@@gem_version_file, 'w')
30
+ file.puts '0.0.1'
31
+ file.close
32
+ end
33
+
34
+ def self.increment_and_push
35
+ self.increment_version
36
+ self.commit_and_push
37
+ end
38
+
39
+ def self.increment_version
40
+ version = self.next_version
41
+ components = version.split('.')
42
+ components.push((components.pop.to_i + 1).to_s)
43
+ new_version = components.join('.')
44
+ update_version(new_version)
45
+ version
46
+ end
47
+
48
+ def self.update_version(new_version)
49
+ file = File.new(@@gem_version_file, 'w')
50
+ file.puts new_version
51
+ file.close
52
+ end
53
+
54
+ def self.commit_and_push(project_directory = nil, msg = nil, &block)
55
+ g=Git.open(project_directory || Dir.pwd, :log=>Logger.new(STDOUT))
56
+ g.add(@@gem_version_file)
57
+ yield(g) if block_given?
58
+ g.commit(msg || @@default_commit_message)
59
+ g.push
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,20 @@
1
+
2
+ namespace :tagging do
3
+ desc "Setting next gem version and push the tag version"
4
+ task :push do
5
+ puts Tagging::AppVersion.increment_and_push rescue exit 1
6
+ exit 0
7
+ end
8
+
9
+ desc "Setting next gem version and push the tag version"
10
+ task :version do
11
+ puts Tagging::AppVersion.version rescue exit 1
12
+ exit 0
13
+ end
14
+
15
+ desc "Setting next gem version and push the tag version"
16
+ task :next_version do
17
+ puts Tagging::AppVersion.increment_version rescue exit 1
18
+ exit 0
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ namespace :tagging do
2
+ namespace :gem do
3
+ desc "Clean *.gem* files from project root"
4
+ task :clean do
5
+ FileUtils.rm_f Dir.glob('*.gem*')
6
+ exit 0
7
+ end
8
+
9
+ desc "Return and set next gem version"
10
+ task :version do
11
+ if (ENV.include?("set"))
12
+ version = ENV['set'].gsub(/'/, '')
13
+ unless Tagging::GemVersion.version_format_valid?(version)
14
+ raise "Version '#{version}' format invalid. Must only contain digits separated by decimal points."
15
+ end
16
+ Tagging::GemVersion.set_version(version)
17
+ puts "Next version set at '#{version}'"
18
+ else
19
+ puts Tagging::GemVersion.next_version
20
+ end
21
+ exit 0
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Tagging
2
+ VERSION = '0.0.2'
3
+ end
data/lib/tagging.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'git'
3
+ require 'logger'
4
+ require 'tagging/app_version'
5
+ require 'tagging/gem_version'
@@ -0,0 +1,59 @@
1
+ require 'lib/gem_version'
2
+
3
+ $gem_version_file = File.expand_path(File.dirname(__FILE__)) + '/next_gem_version'
4
+
5
+ describe "GemVersion" do
6
+ describe "next_version method" do
7
+ it "should create an initial 'next_gem_version' file with the version 0.0.1 if none exists" do
8
+ GemVersion.gem_version_file = $gem_version_file
9
+ File.delete($gem_version_file) if File.exists?($gem_version_file)
10
+ File.exists?($gem_version_file).should == false
11
+ GemVersion.next_version.should == '0.0.1'
12
+ File.exists?($gem_version_file).should == true
13
+ File.new($gem_version_file).gets.chomp.should == '0.0.1'
14
+ end
15
+ it "should return the 'next' version from the 'next_gem_version' file" do
16
+ GemVersion.gem_version_file = $gem_version_file
17
+ file = File.new($gem_version_file, 'w')
18
+ version = '111.222.333.444'
19
+ file.puts version
20
+ file.close
21
+ GemVersion.next_version.should == version
22
+ end
23
+ it "should raise exception if version value corrupted in file" do
24
+ GemVersion.gem_version_file = $gem_version_file
25
+ file = File.new($gem_version_file, 'w')
26
+ file.puts '.1.2.'
27
+ file.close
28
+ lambda { GemVersion.next_version }.should raise_exception(/corrupt/)
29
+ end
30
+ it "should raise exception if version value is nil (non-existent)" do
31
+ GemVersion.gem_version_file = $gem_version_file
32
+ File.delete($gem_version_file)
33
+ file = File.new($gem_version_file, 'w')
34
+ file.puts
35
+ file.close
36
+ lambda { GemVersion.next_version }.should raise_exception(/corrupt/)
37
+ end
38
+ end
39
+ describe "increment_version method" do
40
+ it "should increment and store the next version number" do
41
+ GemVersion.gem_version_file = $gem_version_file
42
+ File.delete($gem_version_file)
43
+ file = File.new($gem_version_file, 'w')
44
+ file.puts '1.2.3'
45
+ file.close
46
+ GemVersion.increment_version
47
+ file = File.new($gem_version_file, 'r')
48
+ file.gets.chomp.should == '1.2.4'
49
+ end
50
+ it "should return the 'next' version number" do
51
+ GemVersion.gem_version_file = $gem_version_file
52
+ File.delete($gem_version_file)
53
+ file = File.new($gem_version_file, 'w')
54
+ file.puts '1.2.5'
55
+ file.close
56
+ GemVersion.increment_version.should == '1.2.5'
57
+ end
58
+ end
59
+ end
@@ -0,0 +1 @@
1
+
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
data/tagging.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.unshift File.expand_path("../lib", __FILE__)
3
+ require "tagging/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "tagging"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Alther Alves"]
9
+ s.email = ["para.alves@gmail.com"]
10
+ s.date = "2016-04-21"
11
+ s.homepage = "http://github.com/altherlex/gem_version/tree/master"
12
+ s.summary = %q{Never bother updating the version for your next gem build by hand. Configured in your Rakefile, gem_version provides the next Gem version and stores it to the repository.}
13
+ s.description = %q{Automated version management for your Gem and RailsApp builds}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- spec/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+ s.required_ruby_version = Gem::Requirement.new(">= 1.8.6")
20
+ s.rubygems_version = %q{1.3.7}
21
+ s.version = Tagging::VERSION
22
+ s.license = "MIT"
23
+
24
+ s.add_dependency 'git', [">= 1.2.5"]
25
+ s.add_dependency 'logger'
26
+
27
+ # s.add_runtime_dependency 'git', '~> 1.2', '>= 1.2.5'
28
+ # s.add_runtime_dependency 'logger', '~> 0'
29
+
30
+ s.add_development_dependency 'rspec'
31
+ s.add_development_dependency 'rake'
32
+ # s.add_development_dependency 'coveralls'
33
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tagging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Alther Alves
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: git
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: logger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Automated version management for your Gem and RailsApp builds
70
+ email:
71
+ - para.alves@gmail.com
72
+ executables:
73
+ - git-tagging
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - bin/git-tagging
83
+ - lib/gem_version.rb
84
+ - lib/tagging.rb
85
+ - lib/tagging/app_version.rb
86
+ - lib/tagging/gem_version.rb
87
+ - lib/tagging/tasks/app_version.rake
88
+ - lib/tagging/tasks/gem_version.rake
89
+ - lib/tagging/version.rb
90
+ - spec/gem_version_spec.rb
91
+ - spec/next_gem_version
92
+ - spec/spec.opts
93
+ - tagging.gemspec
94
+ homepage: http://github.com/altherlex/gem_version/tree/master
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 1.8.6
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.8
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Never bother updating the version for your next gem build by hand. Configured
118
+ in your Rakefile, gem_version provides the next Gem version and stores it to the
119
+ repository.
120
+ test_files:
121
+ - spec/gem_version_spec.rb
122
+ - spec/next_gem_version
123
+ - spec/spec.opts