tagging 0.0.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 563e40a9d49dda41aff47cbd39e4cfa87e767f2f
4
- data.tar.gz: dd603db2458c9b6edbd34475560f21d6d6c48c09
3
+ metadata.gz: 2ece77b05d75ff8933edb236c0ded896bbfbb4f6
4
+ data.tar.gz: 599c773e9a58e466593b0bc4d64634920e641573
5
5
  SHA512:
6
- metadata.gz: 122b81fc674f62fd71891e0afba94ff21312c086545b64fd0688720c1630676714c66575ec40787f7579ab03f57b8ab49074a5da0b3e98e6d0d4fa5a3079b7f8
7
- data.tar.gz: b9b6632b3d88838ce01d5e540a0c9cdd7d0de3427c555174093e1ebde83750f7fe1736f6a96100bbe2f3e83e035bf118958eb83083456abb30ef947773255e99
6
+ metadata.gz: ca854995e01c57a4507c0ecb4a1f22d808b91fa4d7e91d27e3ad737c44843daede0253a633bb8e839ccd56e23b87caf4c975309e37d1c93712306d6c6739aa51
7
+ data.tar.gz: baaa21d142bb6e9a2ae404c1f9f262379ec6eb7f6bac2addcca3ba3b9505d137547f6d1532c01129864c643947bc55da22472bcae236b6e9bcd00b5119d0faeb
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2009 Jeff Patmon
1
+ Copyright (c) 2016 Alther Alves
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Tagging
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/tagging.svg)](https://badge.fury.io/rb/tagging)
4
+
3
5
  Automated version management for your Gem builds.
4
6
 
5
7
  ## Resources
@@ -24,47 +26,30 @@ Never bother updating the version for your next gem build by hand. Configured i
24
26
 
25
27
  `bundle exec rake tagging:push`
26
28
 
27
- * Bash
29
+ ### Bash
28
30
 
29
31
  `cd /rails/app/path && git-tagging push`
30
32
 
31
33
 
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.
34
+ * It's necessary that your server have ssh permission. Seting a git user
50
35
 
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.
36
+ `git-tagging push --config user.email para.alves@gmail.com user.name "Altherlex Alves"`
52
37
 
53
- ## Rake tasks
54
38
 
55
- Two rake tasks gem:clean and gem:version are available whenever you require gem_version.
39
+ * Load remote tags
56
40
 
57
- * Clean the project root of .gem and .gemspec files.
41
+ `git-tagging --version -f`
58
42
 
59
- rake gem:clean
60
43
 
61
- * Get the next gem version
44
+ ### AWS OpsWorkers + CircleCI
62
45
 
63
- rake gem:version
64
-
65
- * Set the next gem version
66
-
67
- rake gem:version set=0.1.0
46
+ ```
47
+ production:
48
+ branch: master
49
+ commands:
50
+ - git-tagging --push
51
+ - dpl --provider=opsworks --access-key-id=$AWS_ACCESS_KEY_ID --secret-access-key="$AWS_SECRET_ACCESS_KEY" --app-id=$AWS_APP_ID --wait-until-deployed --custom_json='{"deploy":{"my_app":{"scm":{"revision":"tags/$(git-tagging --version)" }}}}' --skip_cleanup
52
+ ```
68
53
 
69
54
 
70
55
  ## Dependencies
data/bin/git-tagging CHANGED
@@ -3,20 +3,24 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
3
 
4
4
  require 'optparse'
5
5
  require 'tagging/app_version'
6
- require 'tagging/gem_version'
7
6
 
8
7
  module Tagging
9
8
  class CLI
10
9
 
11
10
  def self.run(options)
11
+ app_version = Tagging::AppVersion.new(options)
12
+
12
13
  if options[:push]
13
- puts Tagging::AppVersion.increment_and_push rescue exit 1
14
+ puts app_version.increment_and_push
14
15
  exit 0
15
16
  elsif options[:version]
16
- puts Tagging::AppVersion.version rescue exit 1
17
+ puts app_version.version
17
18
  exit 0
18
19
  elsif options[:next_version]
19
- puts Tagging::AppVersion.increment_version rescue exit 1
20
+ puts app_version.increment_version
21
+ exit 0
22
+ elsif options[:load_tags]
23
+ puts app_version.load_tags
20
24
  exit 0
21
25
  else
22
26
  puts "## [message] Run `tagging --help' for more options."
@@ -33,26 +37,55 @@ module Tagging
33
37
  end
34
38
 
35
39
  options = {}
36
- opt_parser = OptionParser.new do |opt|
37
- opt.banner = "Usage: tagging [OPTIONS]"
38
- opt.separator ""
39
- opt.separator "Options"
40
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
41
+ if ARGV.first == 'push'
42
+ options[:push] = true
48
43
 
49
- opt.on("-n","--next_version","Show the next version") do |value|
50
- options[:next_version] = value
51
- end
44
+ opt_parser = OptionParser.new do |opt|
45
+ opt.banner = "Usage: git-tagging push [OPTIONS]"
46
+ opt.separator ""
47
+ opt.separator "Options"
48
+
49
+ # git config --global
50
+ opt.on("--config [variables]", "user.email \"you@example.com\" and user.name \"Name\". Like `git config --global`", String) do |value|
51
+ options[:config] = Hash[*ARGV]
52
+ end
53
+
54
+ opt.on("-m", "Tag message", String) do |message|
55
+ options[:message] = message
56
+ end
52
57
 
53
- opt.on("-h","--help","help") do
54
- puts opt_parser
55
- exit
58
+ opt.on_tail("-h","--help","help push command") do
59
+ puts opt_parser
60
+ exit
61
+ end
62
+ end
63
+ else
64
+ opt_parser = OptionParser.new do |opt|
65
+ opt.banner = "Usage: git-tagging [OPTIONS]"
66
+ opt.separator ""
67
+ opt.separator "Options"
68
+
69
+ # opt.on("-p","--push","Increment version and push to tag") do |value|
70
+ # options[:push] = value
71
+ # end
72
+
73
+ opt.on("-v","--version","Show current version into rails app path") do |value|
74
+ options[:version] = value
75
+ end
76
+
77
+ opt.on("-n","--next-version","Show the next version") do |value|
78
+ options[:next_version] = value
79
+ end
80
+
81
+ opt.on("-f","--fetch-tags","Load remote tags") do
82
+ options[:load_tags] = true
83
+ end
84
+
85
+ opt.on_tail("-h","--help","help") do
86
+ puts opt_parser
87
+ exit
88
+ end
56
89
  end
57
90
  end
58
91
  opt_parser.parse!
@@ -3,16 +3,25 @@ require 'logger'
3
3
 
4
4
  module Tagging
5
5
  class AppVersion
6
- @@default_commit_message = 'versioning by CI'
7
- @@version
8
6
 
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
7
+ def initialize(options={})
8
+ @options = {message:'versioning by CI'}.merge(options)
9
+ @git = nil
13
10
  end
14
11
 
15
- def self.version_format_valid?(v)
12
+ def version
13
+ load_tags if @options[:load_tags]
14
+ @options[:current_version] ||= `git -C #{Dir.pwd} describe --tags $(git -C #{Dir.pwd} for-each-ref refs/tags --sort=-taggerdate --format='%(objectname)' --count=1)`.chomp
15
+ @options[:current_version] = self.class.init_version_file unless self.class.version_format_valid?(@options[:current_version])
16
+ @options[:current_version]
17
+ end
18
+
19
+ def load_tags
20
+ puts "git -C #{Dir.pwd} fetch --tags"
21
+ `git -C #{Dir.pwd} fetch --tags`
22
+ end
23
+
24
+ def self.version_format_valid?(v='')
16
25
  (v && v =~ /^v\d+\.\d+\.\d+-[\.\d+]+$/)
17
26
  end
18
27
 
@@ -20,19 +29,31 @@ module Tagging
20
29
  initial_version = 'v0.0.1-00'
21
30
  end
22
31
 
23
- def self.increment_and_push
24
- self.increment_version
25
- self.commit_and_push
32
+ def increment_and_push
33
+ load_tags
34
+ increment_version
35
+ commit_and_push
26
36
  end
27
37
 
28
- def self.increment_version
29
- @@version = self.version.next
38
+ def increment_version
39
+ @options[:current_version] = self.version.next
30
40
  end
31
41
 
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)
42
+ def set_global_config
43
+ if @options[:config]
44
+ @options[:config].each do |key, value|
45
+ @git.config(key, value)
46
+ end
47
+ end
48
+ end
49
+
50
+ def commit_and_push(project_directory=Dir.pwd)
51
+ @git = Git.open(project_directory, :log=>Logger.new(STDOUT))
52
+
53
+ set_global_config
54
+
55
+ @git.add_tag(self.version, nil, message: @options[:message])
56
+ @git.push('origin', "refs/tags/#{self.version}")
36
57
  end
37
58
  end
38
59
  end
@@ -1,3 +1,3 @@
1
1
  module Tagging
2
- VERSION = '0.0.3'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/tagging.rb CHANGED
@@ -2,4 +2,3 @@ require 'rubygems'
2
2
  require 'git'
3
3
  require 'logger'
4
4
  require 'tagging/app_version'
5
- require 'tagging/gem_version'
data/tagging.gemspec CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Alther Alves"]
9
9
  s.email = ["para.alves@gmail.com"]
10
- s.date = "2016-04-21"
11
- s.homepage = "http://github.com/altherlex/gem_version/tree/master"
10
+ s.date = "2016-04-27"
11
+ s.homepage = 'https://github.com/altherlex/tagging'
12
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
13
  s.description = %q{Automated version management for your Gem and RailsApp builds}
14
14
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tagging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alther Alves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-21 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -80,18 +80,15 @@ files:
80
80
  - README.md
81
81
  - Rakefile
82
82
  - bin/git-tagging
83
- - lib/gem_version.rb
84
83
  - lib/tagging.rb
85
84
  - lib/tagging/app_version.rb
86
- - lib/tagging/gem_version.rb
87
85
  - lib/tagging/tasks/app_version.rake
88
- - lib/tagging/tasks/gem_version.rake
89
86
  - lib/tagging/version.rb
90
87
  - spec/gem_version_spec.rb
91
88
  - spec/next_gem_version
92
89
  - spec/spec.opts
93
90
  - tagging.gemspec
94
- homepage: http://github.com/altherlex/gem_version/tree/master
91
+ homepage: https://github.com/altherlex/tagging
95
92
  licenses:
96
93
  - MIT
97
94
  metadata: {}
data/lib/gem_version.rb DELETED
@@ -1,67 +0,0 @@
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
@@ -1,62 +0,0 @@
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
@@ -1,24 +0,0 @@
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