releaser 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in releaser.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'bundler/gem_tasks'
5
+ require 'rspec/core/rake_task'
6
+
7
+ task :default => :spec
8
+
9
+ RSpec::Core::RakeTask.new(:spec) do |t|
10
+ end
data/bin/releaser ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'releaser'
5
+ Releaser::CLI.start
data/lib/releaser.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "releaser/version"
2
+ require "releaser/revision"
3
+ require "releaser/cli"
4
+
5
+ class AlreadyReleasedError < StandardError
6
+ end
7
+
8
+ module Releaser
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,71 @@
1
+ require "active_support/core_ext/object/blank"
2
+ require 'rails/generators/actions'
3
+
4
+ module Releaser
5
+ class CLI < ::Thor
6
+ include Thor::Actions
7
+ include Rails::Generators::Actions
8
+ add_runtime_options!
9
+ class_option :message, :type => :string, :aliases => "-m", :desc => "Specify a tag message (-m option for git tag)"
10
+ class_option :push, :type => :boolean, :default => true
11
+ default_task :info
12
+
13
+ desc "major [CODENAME]", "Issue a major release"
14
+ def major(codename = "")
15
+ codename = ask "Please, give a codename: " unless codename.present?
16
+ new_version = version_from_tag_to_release.new_major(codename)
17
+ message = options.message.presence || "Major release: #{new_version}"
18
+ tag(new_version.to_tagline, :message => message)
19
+ end
20
+
21
+ desc "minor", "Issue a minor release"
22
+ def minor
23
+ new_version = version_from_tag_to_release.new_minor
24
+ message = options.message.presence || "Minor release: #{new_version}"
25
+ tag(new_version.to_tagline, :message => message)
26
+ end
27
+
28
+ desc "deploy", "Tag current commit for a deploy"
29
+ def deploy
30
+ tag(version_from_tag_to_release.to_deploy_tagline, :force => true)
31
+ rescue AlreadyReleasedError
32
+ # no actions required
33
+ end
34
+
35
+ desc "info", "Get current version"
36
+ method_option :verbose, :type => :boolean, :default => false, :aliases => "-v"
37
+ def info
38
+ version = version_from_tag
39
+
40
+ unless options.verbose?
41
+ say version
42
+ else
43
+ log :current_version, version
44
+ log :next_major, version.next_major("[CODENAME]")
45
+ log :next_minor, version.next_minor
46
+ end
47
+ end
48
+
49
+ protected
50
+
51
+ def version_from_tag_to_release
52
+ version_from_tag.tap { |v| raise AlreadyReleasedError.new(v.to_s) if v.current? }
53
+ end
54
+
55
+ def version_from_tag
56
+ tagline = `git describe --match \"v[0-9]*\" --long`.chomp
57
+ Version.new(tagline)
58
+ end
59
+
60
+ def tag(tag, config = {})
61
+ tag_options = [].tap do |opts|
62
+ opts.push "-m \"#{config[:message]}\"" if config[:message]
63
+ opts.push "-f" if config[:force]
64
+ end
65
+
66
+ run "git tag #{tag_options.join(" ")} -- #{tag}"
67
+ run "git push origin #{tag}" if options.push?
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,56 @@
1
+ require 'ostruct'
2
+
3
+ module Releaser
4
+ class Revision < OpenStruct
5
+ def initialize(duck)
6
+ super(duck.is_a?(String) ? parse_string(duck) : duck)
7
+ raise ArgumentError.new("Version should at least contain major part, but given: #{duck.inspect}") unless valid?
8
+ end
9
+
10
+ def valid?
11
+ !!major
12
+ end
13
+
14
+ def to_s
15
+ append_codename(version_string, " ")
16
+ end
17
+
18
+ def to_tagline
19
+ append_codename(version_string, "-")
20
+ end
21
+
22
+ def to_deploy_tagline
23
+ version_string
24
+ end
25
+
26
+ def current?
27
+ build == 0
28
+ end
29
+
30
+ def next_major(codename = nil)
31
+ self.class.new(@table.merge(:build => 0, :minor => 0, :codename => codename).tap {|hsh| hsh[:major] += 1})
32
+ end
33
+ alias_method :new_major, :next_major
34
+
35
+ def next_minor
36
+ self.class.new(@table.merge(:build => 0).tap {|hsh| hsh[:minor] += 1})
37
+ end
38
+ alias_method :new_minor, :next_minor
39
+
40
+ protected
41
+
42
+ def version_string(prefix = "v")
43
+ "#{prefix}#{[major, minor, build == 0 ? nil : build].compact.join(".")}"
44
+ end
45
+
46
+ def parse_string(str)
47
+ major, minor, codename, build, sha = *str.match(/^v(?:(\d+)(?:\.(\d+))?)(?:.\d+)?(?:-(.*))?(?:-(\d+))(?:-(.*))$/).captures
48
+ { :major => major.to_i, :minor => minor.to_i, :codename => codename, :build => build.to_i, :sha => sha }
49
+ end
50
+
51
+ def append_codename(str, separator = "")
52
+ [str, codename].compact.join(separator)
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module Releaser
2
+ VERSION = "0.0.1"
3
+ end
data/releaser.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "releaser/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "releaser"
7
+ s.version = Releaser::VERSION
8
+ s.authors = ["Dmitriy Kiriyenko"]
9
+ s.email = ["dmitriy.kiriyenko@anahoret.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A set of thor scripts for managing application versions}
12
+ s.description = %q{A set of thor scripts for managing application versions.
13
+ Use it to control and even display your application current version.}
14
+
15
+ s.rubyforge_project = "releaser"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ # specify any dependencies here; for example:
23
+ s.add_development_dependency "rspec"
24
+ s.add_development_dependency "rake"
25
+ s.add_runtime_dependency "thor"
26
+ s.add_runtime_dependency "activesupport"
27
+ s.add_runtime_dependency "railties"
28
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ describe Releaser::Revision do
4
+ let(:clazz) {Releaser::Revision}
5
+
6
+ def extract_hash_from_revision(revision)
7
+ {
8
+ :major => revision.major,
9
+ :minor => revision.minor,
10
+ :codename => revision.codename,
11
+ :build => revision.build,
12
+ :sha => revision.sha
13
+ }
14
+ end
15
+
16
+ def verify_revision(revision, expected_hash)
17
+ extract_hash_from_revision(revision).should include(expected_hash)
18
+ end
19
+
20
+ context "creation" do
21
+ context "from hash" do
22
+ it "should create correct object from hash" do
23
+ hash = {:major => 2, :minor => 3, :codename => "Hyperion", :build => 5, :sha => 'ab3de'}
24
+ revision = clazz.new(hash)
25
+ verify_revision(revision, hash)
26
+ end
27
+
28
+ it "should raise error when creating without major" do
29
+ hash = {:minor => 3, :codename => "Hyperion", :build => 5, :sha => 'ab3de'}
30
+ lambda { clazz.new(hash) }.should raise_error
31
+ end
32
+ end
33
+
34
+ context "from string" do
35
+ shared_examples_for "parsing from string" do
36
+ it "should create correct object from string" do
37
+ revision = clazz.new(given_string)
38
+ verify_revision(revision, expected_hash)
39
+ end
40
+ end
41
+
42
+ context "when only major" do
43
+ let(:given_string) { "v6-Edison-59-gf7114dd" }
44
+ let(:expected_hash) { {
45
+ :major => 6,
46
+ :minor => 0,
47
+ :build => 59,
48
+ :codename => "Edison",
49
+ :sha => "gf7114dd"
50
+ } }
51
+ it_should_behave_like "parsing from string"
52
+ end
53
+
54
+ context "when major and minor" do
55
+ let(:given_string) { "v6.1-Edison-59-gf7114dd" }
56
+ let(:expected_hash) { {
57
+ :major => 6,
58
+ :minor => 1,
59
+ :build => 59,
60
+ :codename => "Edison",
61
+ :sha => "gf7114dd"
62
+ } }
63
+ it_should_behave_like "parsing from string"
64
+ end
65
+
66
+ end
67
+
68
+ context "serialization" do
69
+ subject {clazz.new "v6.1-Edison-59-gf7114dd"}
70
+ its(:to_s) { should == "v6.1.59 Edison" }
71
+ its(:to_tagline) { should == "v6.1.59-Edison" }
72
+ its(:to_deploy_tagline) { should == "v6.1.59" }
73
+
74
+ context "with initial build" do
75
+ subject {clazz.new "v6.1-Edison-0-gf7114dd"}
76
+ its(:to_s) { should == "v6.1 Edison" }
77
+ its(:to_tagline) { should == "v6.1-Edison" }
78
+ its(:to_deploy_tagline) { should == "v6.1" }
79
+ end
80
+ end
81
+
82
+ describe "current" do
83
+ context "when build is initial" do
84
+ subject {clazz.new "v6.1-Edison-0-gf7114dd"}
85
+ it { should be_current }
86
+ end
87
+
88
+ context "when build is not initial" do
89
+ subject {clazz.new "v6.1-Edison-59-gf7114dd"}
90
+ it { should_not be_current }
91
+ end
92
+ end
93
+
94
+ context "next version" do
95
+ subject {clazz.new "v6.1-Edison-59-gf7114dd"}
96
+
97
+ it "should correctly return next major version" do
98
+ verify_revision(subject.next_major("Archimedes"), {
99
+ :major => 7,
100
+ :minor => 0,
101
+ :build => 0,
102
+ :codename => "Archimedes"
103
+ })
104
+ end
105
+
106
+ it "should correctly return next major version without codename" do
107
+ subject.next_major.to_s.should == "v7.0"
108
+ verify_revision(subject.next_major, {
109
+ :major => 7,
110
+ :minor => 0,
111
+ :build => 0,
112
+ :codename => nil
113
+ })
114
+ end
115
+
116
+ it "should correctly return next major version without codename" do
117
+ verify_revision(subject.next_minor, {
118
+ :major => 6,
119
+ :minor => 2,
120
+ :build => 0,
121
+ :codename => "Edison"
122
+ })
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ Bundler.require(:default, :development)
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir[File.join(File.dirname(__FILE__), "support", "**", "*.rb")].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ # some (optional) config here
12
+ end
File without changes
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: releaser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dmitriy Kiriyenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-18 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2160508780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2160508780
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &2160507760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2160507760
36
+ - !ruby/object:Gem::Dependency
37
+ name: thor
38
+ requirement: &2160506980 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2160506980
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: &2160505660 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2160505660
58
+ - !ruby/object:Gem::Dependency
59
+ name: railties
60
+ requirement: &2160504880 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *2160504880
69
+ description: ! "A set of thor scripts for managing application versions.\n Use
70
+ it to control and even display your application current version."
71
+ email:
72
+ - dmitriy.kiriyenko@anahoret.com
73
+ executables:
74
+ - releaser
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .rspec
80
+ - Gemfile
81
+ - Rakefile
82
+ - bin/releaser
83
+ - lib/releaser.rb
84
+ - lib/releaser/cli.rb
85
+ - lib/releaser/revision.rb
86
+ - lib/releaser/version.rb
87
+ - releaser.gemspec
88
+ - spec/lib/releaser/revision_spec.rb
89
+ - spec/spec_helper.rb
90
+ - spec/support/.gitkeep
91
+ homepage: ''
92
+ licenses: []
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: -2611041167600780001
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ segments:
113
+ - 0
114
+ hash: -2611041167600780001
115
+ requirements: []
116
+ rubyforge_project: releaser
117
+ rubygems_version: 1.8.6
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: A set of thor scripts for managing application versions
121
+ test_files:
122
+ - spec/lib/releaser/revision_spec.rb
123
+ - spec/spec_helper.rb
124
+ - spec/support/.gitkeep