autoversion 0.4.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e19cd24caedde612005e57c536d6d23a3cf27c4
4
+ data.tar.gz: 4abca7955e686be2d91b0946f33af46b050880aa
5
+ SHA512:
6
+ metadata.gz: 5af8dcd3a141bcf64ebe09e715771b1b0a860e2d2f87f53193c41585efd28b69f7995c9d68ee46bf2eb9e96a1d298a5edad3515a2aa3f48d92807fe0c87eae5c
7
+ data.tar.gz: 762b5bc91b6f378dabbc364e58737e7a434b2ad6113b859f7ae003114266b1a939be479ca7d6308c621830269522734a724f72bc88680e8a5cb2eed1df35edc2
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ spec/tmp/*
3
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ autoversion (0.3.2)
5
+ git (= 1.2.5)
6
+ semantic (= 1.1.0)
7
+ thor (= 0.17.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.2.1)
13
+ git (1.2.5)
14
+ rspec (2.13.0)
15
+ rspec-core (~> 2.13.0)
16
+ rspec-expectations (~> 2.13.0)
17
+ rspec-mocks (~> 2.13.0)
18
+ rspec-core (2.13.1)
19
+ rspec-expectations (2.13.0)
20
+ diff-lcs (>= 1.1.3, < 2.0)
21
+ rspec-mocks (2.13.0)
22
+ semantic (1.1.0)
23
+ thor (0.17.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ autoversion!
30
+ rspec (= 2.13.0)
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012 Jonathan Pettersson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,125 @@
1
+ Autoversion
2
+ ===========
3
+
4
+ Autoversion is a command line tool that can automate [semantic versioning](http://semver.org) in your application. It
5
+ integrates nicely with git to give you automatic & atomic commits of version increments. It also supports hooks that can be run before and after a new version has been comitted.
6
+
7
+ Autoversion is not finished, but it's used enough to be public. Consider it an experiment.<br />
8
+ And yes, Autoversion uses Autoversion for versioning ;)
9
+
10
+ Basics
11
+ ---------
12
+
13
+ **Read current version**
14
+ ```Bash
15
+ $ autoversion
16
+ ```
17
+
18
+ **Increment versions**
19
+ ```Bash
20
+ $ autoversion major
21
+ $ autoversion minor
22
+ $ autoversion patch
23
+ $ autoversion build 'named-version'
24
+ ```
25
+
26
+ The Versionfile
27
+ --------------------
28
+
29
+ The Versionfile is a ruby script which is used by Autoversion to read and write version.
30
+
31
+ **Example**
32
+
33
+ ```Ruby
34
+
35
+ # This block should return a valid Semantic object. Typically it will read a file and parse it.
36
+ read_version do
37
+ # Return a valid Semantic object
38
+ end
39
+
40
+ # This block should take a Semantic object and persist it. Usually this means rewriting some version file.
41
+ write_version do |semver|
42
+ # Write a Semantic object
43
+ end
44
+
45
+ after :version do
46
+ # Run some command after any versioning action
47
+ # Example: Export a .crx file, copy & name it for Blackberry
48
+ end
49
+
50
+ after :patch do
51
+ # Run some command after patch
52
+ end
53
+
54
+ after :minor do
55
+ # Run some command after minor
56
+ end
57
+
58
+ after :major do
59
+ # Run some command after release
60
+ # Example: Copy lib/ files from Exo.js to exojs-gem
61
+ end
62
+
63
+ ```
64
+
65
+ Versionfile Examples
66
+ ----------------------------
67
+
68
+ **A ruby gem**
69
+
70
+ ```Ruby
71
+ automate_git
72
+
73
+ read_version do
74
+ contents = File.read File.join(Dir.pwd, "lib/autoversion/version.rb")
75
+ instance_eval(contents)
76
+ Autoversion::VERSION
77
+ end
78
+
79
+ write_version do |currentVersion, nextVersion|
80
+ contents = File.read File.join(Dir.pwd, "lib/autoversion/version.rb")
81
+ contents = contents.sub(currentVersion.to_s, nextVersion.to_s)
82
+
83
+ File.open(File.join(Dir.pwd, "lib/autoversion/version.rb"), 'w') do |file|
84
+ file.write contents
85
+ end
86
+ end
87
+ ```
88
+
89
+ **A Chrome Extension**
90
+
91
+ ```Ruby
92
+ require 'json'
93
+ require 'crxmake'
94
+
95
+ automate_git :actions => [:commit]
96
+
97
+ read_version do
98
+ doc = JSON.load File.read('./app/source/manifest.json')
99
+ doc['version']
100
+ end
101
+
102
+ write_version do |currentVersion, nextVersion|
103
+ doc = JSON.load File.read './app/source/manifest.json'
104
+ doc['version'] = nextVersion.to_s
105
+ File.open('./app/source/manifest.json', 'w') {|f| f.write JSON.pretty_generate(doc) }
106
+ end
107
+
108
+ after :version do |currentVersion|
109
+ CrxMake.make(
110
+ :ex_dir => "./app/build",
111
+ :pkey => "./app/build.pem",
112
+ :crx_output => "./app/releases/#{currentVersion.to_s}.crx",
113
+ :verbose => true,
114
+ :ignorefile => /\.swp/,
115
+ :ignoredir => /\.(?:svn|git|cvs)/
116
+ )
117
+ end
118
+ ```
119
+
120
+ **An npm module**
121
+
122
+ ```Ruby
123
+ ```
124
+
125
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new('spec')
4
+
5
+ # If you want to make this the default task
6
+ task :default => :spec
data/Versionfile ADDED
@@ -0,0 +1,32 @@
1
+ automate_git
2
+
3
+ read_version do
4
+ contents = File.read File.join(Dir.pwd, "lib/autoversion/version.rb")
5
+ instance_eval(contents)
6
+ Autoversion::VERSION
7
+ end
8
+
9
+ write_version do |currentVersion, nextVersion|
10
+ contents = File.read File.join(Dir.pwd, "lib/autoversion/version.rb")
11
+ contents = contents.sub(currentVersion.to_s, nextVersion.to_s)
12
+
13
+ File.open(File.join(Dir.pwd, "lib/autoversion/version.rb"), 'w') do |file|
14
+ file.write contents
15
+ end
16
+ end
17
+
18
+ before :version do |currentVersion, nextVersion|
19
+ puts "Before version #{currentVersion} => #{nextVersion}"
20
+ end
21
+
22
+ after :version do |currentVersion|
23
+ puts "After version #{currentVersion}"
24
+ end
25
+
26
+ before :patch do |currentVersion, nextVersion|
27
+ puts "Before patch #{currentVersion} => #{nextVersion}"
28
+ end
29
+
30
+ after :patch do |currentVersion|
31
+ puts "After patch #{currentVersion}"
32
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "autoversion/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'autoversion'
7
+ s.version = Autoversion::VERSION
8
+ s.date = '2013-03-27'
9
+ s.summary = "Automate your Semantic Versioning with git and hooks"
10
+ s.description = "Yeah"
11
+ s.authors = ["Jonathan Pettersson"]
12
+ s.email = 'jonathan@spacetofu.com'
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.homepage = 'https://github.com/jpettersson/autoversion'
16
+ s.executables << 'autoversion'
17
+ s.license = 'MIT'
18
+
19
+ s.add_development_dependency "rspec", "2.13.0"
20
+ s.add_runtime_dependency "thor", "0.17.0"
21
+ s.add_runtime_dependency "git", "1.2.5"
22
+ s.add_runtime_dependency "semantic", "1.1.0"
23
+ end
data/bin/autoversion ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/autoversion'
3
+ ::Autoversion::CLI.start
@@ -0,0 +1,9 @@
1
+ module Autoversion
2
+
3
+ end
4
+
5
+ require_relative 'autoversion/cli'
6
+ require_relative 'autoversion/semver'
7
+ require_relative 'autoversion/dsl'
8
+ require_relative 'autoversion/versioner'
9
+ require_relative 'autoversion/gitter'
File without changes
@@ -0,0 +1,64 @@
1
+ require "thor"
2
+
3
+ module Autoversion
4
+ class CLI < Thor
5
+ include Thor::Actions
6
+
7
+ class << self
8
+ attr_accessor :version_file_contents
9
+ attr_accessor :pwd
10
+ end
11
+
12
+ def initialize(*args)
13
+ super *args
14
+ version_file_contents = CLI::version_file_contents || File.read(File.join(Dir.pwd, "Versionfile"))
15
+ @versioner = Autoversion::Versioner.new version_file_contents, CLI::pwd
16
+ end
17
+
18
+ desc 'read_version', 'Read the Semantic Version of the current project'
19
+ def read_version
20
+ say @versioner.current_version.to_s, :cyan
21
+ end
22
+
23
+ desc 'patch', "Increment a patch version"
24
+ method_option :simulate, :type => :boolean, :aliases => "-s"
25
+ method_option :force, :type => :boolean, :aliases => '-f'
26
+ def patch
27
+ increment_version :patch, options[:simulate], options[:force]
28
+ end
29
+
30
+ desc 'minor', 'Increment a minor version'
31
+ method_option :simulate, :type => :boolean, :aliases => "-s"
32
+ method_option :force, :type => :boolean, :aliases => '-f'
33
+ def minor
34
+ increment_version :minor, options[:simulate], options[:force]
35
+ end
36
+
37
+ desc 'major', 'Increment a major version'
38
+ method_option :simulate, :type => :boolean, :aliases => "-s"
39
+ method_option :force, :type => :boolean, :aliases => '-f'
40
+ def major
41
+ increment_version :major, options[:simulate], options[:force]
42
+ end
43
+
44
+ #TODO: Accept arg
45
+ desc 'build', 'Create a build version'
46
+ def special
47
+ create_build_version
48
+ end
49
+
50
+ no_tasks do
51
+ def increment_version type, simulate=false, force=false
52
+ if force or yes? "Do you want to increment #{type.to_s} to #{@versioner.next_version(type)}? (y/N)"
53
+ outcome = simulate ? "would change" : "changed"
54
+ @versioner.increment! type, simulate
55
+ say "Version #{outcome} to #{@versioner.current_version}", simulate ? :cyan : :green
56
+ else
57
+ say "No changes were made."
58
+ end
59
+ end
60
+ end
61
+
62
+ default_task :read_version
63
+ end
64
+ end
@@ -0,0 +1,88 @@
1
+ module Autoversion
2
+ class DSL
3
+
4
+ class MissingReadBlock < Exception
5
+ end
6
+
7
+ class InvalidGitConfig < Exception
8
+ end
9
+
10
+ attr_accessor :read_blk
11
+ attr_accessor :write_blk
12
+ attr_accessor :listeners
13
+ attr_accessor :config
14
+
15
+ def initialize
16
+ @read_blk = nil
17
+ @write_blk = nil
18
+ @listeners = []
19
+ @config = {
20
+ :git => {
21
+ :actions => [],
22
+ :prefix => '',
23
+ :stable_branch => 'master'
24
+ }
25
+ }
26
+ end
27
+
28
+ def validate!
29
+ # A read_version block is required
30
+ raise MissingReadBlock unless @read_blk
31
+ raise InvalidGitConfig if @config[:git][:actions].include?(:tag) && !@config[:git][:actions].include?(:commit)
32
+ end
33
+
34
+ def automate_git *args
35
+ if args.length == 0
36
+ @config[:git][:actions] = [:commit, :tag]
37
+ else
38
+ args[0].each do |arg|
39
+ if [:actions, :stable_branch, :prefix].include?(arg[0])
40
+ @config[:git][arg[0]] = arg[1]
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ # Register a block that will be used to read the
47
+ # version number from the current project.
48
+ def read_version &blk
49
+ @read_blk = blk
50
+ end
51
+
52
+ # Register a block that will be used to write the
53
+ # version number to the current project.
54
+ def write_version &blk
55
+ @write_blk = blk
56
+ end
57
+
58
+ # Register a block that will be executed after
59
+ # a certain event has fired.
60
+ def after event, &blk
61
+ @listeners.push({
62
+ :type => :after,
63
+ :event => event,
64
+ :blk => blk
65
+ })
66
+ end
67
+
68
+ # Register a block that will be executed before
69
+ # a certain event has fired.
70
+ def before event, &blk
71
+ @listeners.push({
72
+ :type => :before,
73
+ :event => event,
74
+ :blk => blk
75
+ })
76
+ end
77
+
78
+ class << self
79
+ def evaluate(script)
80
+ obj = self.new
81
+ obj.instance_eval(script)
82
+ obj.validate!
83
+
84
+ return obj.read_blk, obj.write_blk, obj.listeners, obj.config
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,63 @@
1
+ require 'git'
2
+
3
+ module Autoversion
4
+ class Gitter
5
+
6
+ class DirtyStaging < Exception
7
+ end
8
+
9
+ class NotOnStableBranch < Exception
10
+ end
11
+
12
+ def initialize path, config
13
+ @path = path
14
+ @config = config
15
+ @repo = Git.open(path)
16
+ end
17
+
18
+ def ensure_cleanliness!
19
+ if @config[:actions].include?(:commit)
20
+ raise DirtyStaging unless dir_is_clean?
21
+ end
22
+ end
23
+
24
+ def dir_is_clean?
25
+ # sum = @repo.status.untracked.length + @repo.status.added.length + @repo.status.changed.length + @repo.status.deleted.length
26
+ # if sum > 0
27
+ # puts "untracked: #{@repo.status.untracked}"
28
+ # puts "added: #{@repo.status.added}"
29
+ # puts "changed: #{@repo.status.changed}"
30
+ # puts "deleted: #{@repo.status.deleted}"
31
+ # end
32
+
33
+ # sum == 0
34
+
35
+ # Disabled for now. ruby-git doesn't seem to read the .gitignore files, so the untracked count is completely useless.
36
+ true
37
+ end
38
+
39
+ def on_stable_branch?
40
+ @repo.current_branch == @config[:stable_branch].to_s
41
+ end
42
+
43
+ def commit! versionType, currentVersion
44
+ return false unless @config[:actions].include?(:commit)
45
+ raise NotOnStableBranch if versionType == :major && !on_stable_branch?
46
+
47
+ write_commit currentVersion
48
+ write_tag currentVersion if @config[:actions].include?(:tag)
49
+ end
50
+
51
+ private
52
+
53
+ def write_commit version
54
+ @repo.add '.'
55
+ @repo.commit "#{@config[:prefix]}#{version}"
56
+ end
57
+
58
+ def write_tag version
59
+ @repo.add_tag "#{@config[:prefix]}#{version}"
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,25 @@
1
+ require 'semantic'
2
+
3
+ module Autoversion
4
+ class SemVer < ::Semantic::Version
5
+
6
+ def increment type
7
+ version = to_a
8
+ found = false
9
+ [:major, :minor, :patch].each_with_index do |seg, i|
10
+ if found
11
+ version[i] = 0
12
+ end
13
+
14
+ if seg == type
15
+ old = instance_variable_get("@#{seg}")
16
+ version[i] = old+1
17
+ found = true
18
+ end
19
+ end
20
+
21
+ SemVer.new version.reject{|v| v.nil? }.join '.'
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Autoversion
2
+ VERSION = '0.4.0'
3
+ end
@@ -0,0 +1,68 @@
1
+ module Autoversion
2
+ class Versioner
3
+
4
+ class UnableToReadVersion < Exception
5
+ end
6
+
7
+ def initialize versionfileContents, pwd=nil
8
+ # Eval the Versionfile within the DSL
9
+ @read_blk, @write_blk, @listeners, @config = Autoversion::DSL.evaluate versionfileContents
10
+
11
+ raise UnableToReadVersion unless @read_blk
12
+
13
+ # Fetch current version
14
+ @current = read_version if @read_blk
15
+
16
+ @gitter = ::Autoversion::Gitter.new(pwd || Dir.pwd, @config[:git])
17
+ end
18
+
19
+ def current_version
20
+ @current
21
+ end
22
+
23
+ def next_version type
24
+ @current.increment(type)
25
+ end
26
+
27
+ def increment! type, simulate=false
28
+ @gitter.ensure_cleanliness!
29
+
30
+ nextVersion = @current.increment(type)
31
+
32
+ process_before type, @current, nextVersion
33
+ unless simulate
34
+ write_version @current, nextVersion
35
+ @current = nextVersion
36
+ @gitter.commit! type, @current.to_s
37
+ end
38
+
39
+ process_after type, @current
40
+ end
41
+
42
+ private
43
+
44
+ def read_version
45
+ Autoversion::SemVer.new @read_blk.call
46
+ end
47
+
48
+ def write_version currentVersion, nextVersion
49
+ @write_blk.call currentVersion, nextVersion
50
+ end
51
+
52
+ def process_before event, currentVersion, nextVersion
53
+ notify_listeners :before, event, currentVersion, nextVersion
54
+ notify_listeners :before, :version, currentVersion, nextVersion
55
+ end
56
+
57
+ def process_after event, currentVersion
58
+ notify_listeners :after, event, currentVersion
59
+ notify_listeners :after, :version, currentVersion
60
+ end
61
+
62
+ def notify_listeners type, event, *args
63
+ @listeners.select{|l| l[:type] == type && l[:event] == event }.each do |listener|
64
+ listener[:blk].call *args
65
+ end
66
+ end
67
+ end
68
+ end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+ require 'git'
3
+
4
+ describe Autoversion::CLI do
5
+
6
+ BASE_VERSIONFILE = <<-eos
7
+ read_version do
8
+ File.read File.join(File.dirname(__FILE__), 'spec', 'tmp', 'cli', 'version.txt')
9
+ end
10
+
11
+ write_version do |currentVersion, nextVersion|
12
+ File.open(File.join(File.dirname(__FILE__), 'spec', 'tmp', 'cli', 'version.txt'), 'w') do |file|
13
+ file.write currentVersion.to_s
14
+ end
15
+ end
16
+ eos
17
+
18
+ # Borrowing capture_io from minitest until I have
19
+ # time to move over to minitest fully.
20
+ def capture_io
21
+ require 'stringio'
22
+
23
+ captured_stdout, captured_stderr = StringIO.new, StringIO.new
24
+
25
+ Mutex.new.synchronize do
26
+ orig_stdout, orig_stderr = $stdout, $stderr
27
+ $stdout, $stderr = captured_stdout, captured_stderr
28
+
29
+ begin
30
+ yield
31
+ ensure
32
+ $stdout = orig_stdout
33
+ $stderr = orig_stderr
34
+ end
35
+ end
36
+
37
+ return captured_stdout.string, captured_stderr.string
38
+ end
39
+
40
+ before(:each) do
41
+ @path = File.join(File.dirname(__FILE__), 'tmp', 'cli')
42
+
43
+ if File.directory? @path
44
+ FileUtils.rm_rf @path
45
+ end
46
+
47
+ system("mkdir #{@path}")
48
+ system("tar -xf spec/fixtures/bare_repo.tar --strip 1 -C #{@path}")
49
+
50
+ system("echo '0.0.1' > #{@path}/version.txt")
51
+ system("cd #{@path} && git add .")
52
+ system("cd #{@path} && git commit -m 'first'")
53
+
54
+ @repo = Git.open(@path)
55
+
56
+ ::Autoversion::CLI.pwd = @path
57
+ end
58
+
59
+ it "should be able to read a version" do
60
+ ::Autoversion::CLI.version_file_contents = BASE_VERSIONFILE
61
+
62
+ out = capture_io{ Autoversion::CLI.start %w{} }.join ''
63
+ out.should == "\e[36m0.0.1\e[0m\n"
64
+ end
65
+
66
+ it "should be able to write versions" do
67
+ ::Autoversion::CLI.version_file_contents = BASE_VERSIONFILE
68
+
69
+ out = capture_io{ Autoversion::CLI.start %w{patch -f} }.join ''
70
+ out.should == "\e[32mVersion changed to 0.0.2\e[0m\n"
71
+
72
+ out = capture_io{ Autoversion::CLI.start %w{minor -f} }.join ''
73
+ out.should == "\e[32mVersion changed to 0.1.0\e[0m\n"
74
+
75
+ out = capture_io{ Autoversion::CLI.start %w{major -f} }.join ''
76
+ out.should == "\e[32mVersion changed to 1.0.0\e[0m\n"
77
+ end
78
+
79
+ it "should be able to write, commit and tag patch" do
80
+ ::Autoversion::CLI.version_file_contents = "automate_git\n\n" + BASE_VERSIONFILE
81
+
82
+ out = capture_io{ Autoversion::CLI.start %w{patch -f} }.join ''
83
+ out.should == "\e[32mVersion changed to 0.0.2\e[0m\n"
84
+ end
85
+
86
+ it "should be able to write, commit and tag minor" do
87
+ ::Autoversion::CLI.version_file_contents = "automate_git\n\n" + BASE_VERSIONFILE
88
+
89
+ out = capture_io{ Autoversion::CLI.start %w{minor -f} }.join ''
90
+ out.should == "\e[32mVersion changed to 0.1.0\e[0m\n"
91
+ end
92
+
93
+ it "should be able to write, commit and tag major" do
94
+ ::Autoversion::CLI.version_file_contents = "automate_git\n\n" + BASE_VERSIONFILE
95
+
96
+ out = capture_io{ Autoversion::CLI.start %w{major -f} }.join ''
97
+ out.should == "\e[32mVersion changed to 1.0.0\e[0m\n"
98
+ end
99
+ end
data/spec/dsl_spec.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Autoversion::DSL do
4
+
5
+ it "should raise MissingReadBlock unless read_version has defined block" do
6
+ expect {
7
+ @read_blk, @write_blk, @listeners, @config = Autoversion::DSL.evaluate ""
8
+ }.to raise_error(Autoversion::DSL::MissingReadBlock)
9
+ end
10
+
11
+ it "should return an empty git config if not defined" do
12
+ @read_blk, @write_blk, @listeners, @config = Autoversion::DSL.evaluate <<-eof
13
+ read_version do
14
+
15
+ end
16
+ eof
17
+
18
+ @config[:git][:actions].include?(:commit).should == false
19
+ @config[:git][:actions].include?(:tag).should == false
20
+ @config[:git][:prefix].should == ''
21
+ @config[:git][:stable_branch].should == 'master'
22
+ end
23
+
24
+ it "should return a default git config when defined" do
25
+ @read_blk, @write_blk, @listeners, @config = Autoversion::DSL.evaluate <<-eof
26
+ read_version do
27
+
28
+ end
29
+
30
+ automate_git
31
+ eof
32
+
33
+ @config[:git][:actions].include?(:commit).should == true
34
+ @config[:git][:actions].include?(:tag).should == true
35
+ @config[:git][:prefix].should == ''
36
+ @config[:git][:stable_branch].should == 'master'
37
+ end
38
+
39
+
40
+ it "should correctly parse git config" do
41
+ @read_blk, @write_blk, @listeners, @config = Autoversion::DSL.evaluate <<-eof
42
+ read_version do
43
+
44
+ end
45
+
46
+ automate_git :actions => [:commit], :prefix => 'v', :stable_branch => 'dev'
47
+ eof
48
+
49
+ @config[:git][:actions].include?(:commit).should == true
50
+ @config[:git][:actions].include?(:tag).should == false
51
+ @config[:git][:prefix].should == 'v'
52
+ @config[:git][:stable_branch].should == 'dev'
53
+ end
54
+
55
+ it "should raise InvalidGitConfig when invalid" do
56
+ expect {
57
+ @read_blk, @write_blk, @listeners, @config = Autoversion::DSL.evaluate <<-eof
58
+ read_version do
59
+
60
+ end
61
+
62
+ automate_git :actions => [:tag]
63
+ eof
64
+ }.to raise_error(Autoversion::DSL::InvalidGitConfig)
65
+ end
66
+
67
+ end
Binary file
@@ -0,0 +1,15 @@
1
+ module Versionfiles
2
+ VALID_BASIC = <<-eof
3
+ read_version do
4
+ '1.2.3'
5
+ end
6
+
7
+ write_version do |currentVersion, nextVersion|
8
+
9
+ end
10
+ eof
11
+
12
+ INVALID = <<-eof
13
+
14
+ eof
15
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'git'
3
+
4
+ describe Autoversion::Gitter do
5
+
6
+ before(:each) do
7
+ @gitter_path = File.join(File.dirname(__FILE__), 'tmp', 'gitter')
8
+
9
+ if File.directory? @gitter_path
10
+ FileUtils.rm_rf @gitter_path
11
+ end
12
+
13
+ system("mkdir #{@gitter_path}")
14
+ system("tar -xf spec/fixtures/bare_repo.tar --strip 1 -C #{@gitter_path}")
15
+
16
+ system("echo 'test' > #{@gitter_path}/test.txt")
17
+ system("cd #{@gitter_path} && git add .")
18
+ system("cd #{@gitter_path} && git commit -m 'test'")
19
+
20
+ @gitter_repo = Git.open(@gitter_path)
21
+ end
22
+
23
+ it 'should detect stable branch' do
24
+ @gitter = ::Autoversion::Gitter.new(@gitter_path, {
25
+ :stable_branch => 'master'})
26
+
27
+ @gitter_repo.branch('feature1').checkout
28
+ @gitter_repo.branch('feature2').checkout
29
+ @gitter.on_stable_branch?.should eq(false)
30
+
31
+ @gitter_repo.branch('master').checkout
32
+ @gitter.on_stable_branch?.should eq(true)
33
+ end
34
+
35
+ it 'should be able to commit and tag a new version' do
36
+ @gitter = ::Autoversion::Gitter.new(@gitter_path, {
37
+ :actions => [:commit, :tag],
38
+ :stable_branch => 'master'})
39
+
40
+ #Fake version file
41
+ system("touch #{@gitter_path}/version.rb")
42
+
43
+ @gitter.commit! :major, 'v1.2.3'
44
+
45
+ @gitter_repo.log.first.message.should == "v1.2.3"
46
+ @gitter_repo.tags.first.name.should == "v1.2.3"
47
+ end
48
+
49
+ it 'should should detect cleanliness' do
50
+ @gitter = ::Autoversion::Gitter.new(@gitter_path, {
51
+ :stable_branch => 'master'})
52
+
53
+ @gitter.dir_is_clean?.should eq(true)
54
+
55
+ # Disabled for now since ruby-git does not read .gitignore files
56
+ #system("touch #{@gitter_path}/test2.txt")
57
+ #@gitter.dir_is_clean?.should eq(false)
58
+ end
59
+
60
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require_relative '../lib/autoversion'
5
+ require_relative 'fixtures/versionfiles.rb'
6
+
7
+ RSpec.configure do |config|
8
+ # some (optional) config here
9
+ config.after(:all) do
10
+ FileUtils.rm_rf File.join(File.dirname(__FILE__), 'tmp', 'gitter')
11
+ FileUtils.rm_rf File.join(File.dirname(__FILE__), 'tmp', 'cli')
12
+ end
13
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Autoversion::Versioner do
4
+
5
+ before(:each) do
6
+ @versioner = Autoversion::Versioner.new Versionfiles::VALID_BASIC
7
+ end
8
+
9
+ it "should be able to read the current version" do
10
+ expect(
11
+ @versioner.current_version.to_s
12
+ ).to eq('1.2.3')
13
+ end
14
+
15
+ it "should be able to increment a major version" do
16
+ @versioner.increment! :major
17
+
18
+ expect(
19
+ @versioner.current_version.to_s
20
+ ).to eq('2.0.0')
21
+ end
22
+
23
+ it "should be able to increment a minor version" do
24
+ @versioner.increment! :minor
25
+
26
+ expect(
27
+ @versioner.current_version.to_s
28
+ ).to eq('1.3.0')
29
+ end
30
+
31
+ it "should be able to increment a patch version" do
32
+ @versioner.increment! :patch
33
+
34
+ expect(
35
+ @versioner.current_version.to_s
36
+ ).to eq('1.2.4')
37
+ end
38
+
39
+ it "should not increment a major if simulate" do
40
+ @versioner.increment! :major, true
41
+
42
+ expect(
43
+ @versioner.current_version.to_s
44
+ ).to eq('1.2.3')
45
+ end
46
+
47
+ it "should not increment a minor if simulate" do
48
+ @versioner.increment! :minor, true
49
+
50
+ expect(
51
+ @versioner.current_version.to_s
52
+ ).to eq('1.2.3')
53
+ end
54
+
55
+ it "should not increment a patch if simulate" do
56
+ @versioner.increment! :patch, true
57
+
58
+ expect(
59
+ @versioner.current_version.to_s
60
+ ).to eq('1.2.3')
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autoversion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Pettersson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.13.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.13.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.17.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.17.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: git
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: semantic
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.1.0
69
+ description: Yeah
70
+ email: jonathan@spacetofu.com
71
+ executables:
72
+ - autoversion
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - Versionfile
84
+ - autoversion.gemspec
85
+ - bin/autoversion
86
+ - lib/autoversion.rb
87
+ - lib/autoversion/.gitkeep
88
+ - lib/autoversion/cli.rb
89
+ - lib/autoversion/dsl.rb
90
+ - lib/autoversion/gitter.rb
91
+ - lib/autoversion/semver.rb
92
+ - lib/autoversion/version.rb
93
+ - lib/autoversion/versioner.rb
94
+ - spec/cli_spec.rb
95
+ - spec/dsl_spec.rb
96
+ - spec/fixtures/bare_repo.tar
97
+ - spec/fixtures/versionfiles.rb
98
+ - spec/gitter_spec.rb
99
+ - spec/semver_spec.rb
100
+ - spec/spec_helper.rb
101
+ - spec/tmp/.gitkeep
102
+ - spec/versioner_spec.rb
103
+ homepage: https://github.com/jpettersson/autoversion
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.0
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Automate your Semantic Versioning with git and hooks
127
+ test_files:
128
+ - spec/cli_spec.rb
129
+ - spec/dsl_spec.rb
130
+ - spec/fixtures/bare_repo.tar
131
+ - spec/fixtures/versionfiles.rb
132
+ - spec/gitter_spec.rb
133
+ - spec/semver_spec.rb
134
+ - spec/spec_helper.rb
135
+ - spec/tmp/.gitkeep
136
+ - spec/versioner_spec.rb