bump 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bump (0.3.2)
4
+ bump (0.3.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -16,6 +16,16 @@ Bump your gemfile (major, minor, patch):
16
16
 
17
17
  Bump version 0.1.2 to 0.1.3
18
18
 
19
+ ### Rake
20
+
21
+ ```Ruby
22
+ # Rakefile
23
+ require "bump/tasks"
24
+ ```
25
+
26
+ rake bump:patch
27
+ rake bump:current
28
+
19
29
  # Supported locations
20
30
  - VERSION file with "1.2.3"
21
31
  - gemspec with `gem.version = "1.2.3"`
data/bin/bump CHANGED
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'optparse'
3
3
 
4
- options = {
5
- :commit => true,
6
- :bundle => File.exist?("Gemfile")
7
- }
4
+ options = {}
8
5
  OptionParser.new do |opts|
9
6
  opts.banner = <<BANNER
10
7
  Bump your gem version.
@@ -1,5 +1,5 @@
1
1
  Gem::Specification.new "bump" do |s|
2
- s.version = "0.3.2"
2
+ s.version = "0.3.3"
3
3
  s.author = "Gregory Marcilhacy"
4
4
  s.email = "g.marcilhacy@gmail.com"
5
5
  s.homepage = "https://github.com/gregorym/bump"
@@ -10,7 +10,16 @@ module Bump
10
10
  OPTIONS = BUMPS | ["current"]
11
11
  VERSION_REGEX = /(\d+\.\d+\.\d+(?:-(?:#{PRERELEASE.compact.join('|')}))?)/
12
12
 
13
- def self.run(bump, options)
13
+ def self.defaults
14
+ {
15
+ :commit => true,
16
+ :bundle => File.exist?("Gemfile")
17
+ }
18
+ end
19
+
20
+ def self.run(bump, options={})
21
+ options = defaults.merge(options)
22
+
14
23
  case bump
15
24
  when *BUMPS
16
25
  bump(bump, options)
@@ -37,7 +46,7 @@ module Bump
37
46
  current, file = current_version
38
47
  next_version = next_version(current, part)
39
48
  replace(file, current, next_version)
40
- system("bundle") if options[:bundle]
49
+ system("bundle") if options[:bundle] and under_version_control?("Gemfile.lock")
41
50
  commit(next_version, file, options) if options[:commit]
42
51
  ["Bump version #{current} to #{next_version}", 0]
43
52
  end
@@ -115,5 +124,10 @@ module Bump
115
124
  version = [major, minor, patch, *other].compact.join('.')
116
125
  [version, prerelease].compact.join('-')
117
126
  end
127
+
128
+ def self.under_version_control?(file)
129
+ @all_files ||= `git ls-files`.split(/\r?\n/)
130
+ @all_files.include?(file)
131
+ end
118
132
  end
119
133
  end
@@ -0,0 +1,11 @@
1
+ require "bump"
2
+
3
+ namespace :bump do
4
+ (Bump::Bump::BUMPS + ["current"]).each do |bump|
5
+ task bump do
6
+ output, status = Bump::Bump.run(bump)
7
+ puts output
8
+ abort unless status == 0
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe "rake bump" do
4
+ inside_of_folder("spec/fixture")
5
+
6
+ before do
7
+ write "VERSION", "1.2.3\n"
8
+ write "Rakefile", "require File.expand_path('../../../lib/bump/tasks', __FILE__)"
9
+ raise unless system("git add VERSION")
10
+ end
11
+
12
+ it "bumps a version" do
13
+ output = run "rake bump:minor"
14
+ output.should include("1.3.0")
15
+ read("VERSION").should == "1.3.0\n"
16
+ `git log -1 --pretty=format:'%s'`.should == "v1.3.0"
17
+ end
18
+
19
+ it "fails when it cannot bump" do
20
+ write "VERSION", "AAA"
21
+ run "rake bump:minor", :fail => true
22
+ end
23
+
24
+ it "shows the version" do
25
+ result = run "rake bump:current"
26
+ result.should include("1.2.3")
27
+ end
28
+ end
@@ -1,18 +1,10 @@
1
- require File.dirname(__FILE__) + "/../lib/bump.rb"
2
- require 'bundler'
1
+ require "spec_helper"
3
2
 
4
3
  describe Bump do
5
4
  let(:gemspec){ "fixture.gemspec" }
6
5
  let(:version_rb_file){ "lib/foo/version.rb" }
7
6
 
8
- around do |example|
9
- run "rm -rf fixture && mkdir fixture"
10
- Dir.chdir "fixture" do
11
- `git init && git commit --allow-empty -am 'initial'` # so we never accidentally do commit to the current repo
12
- example.call
13
- end
14
- run "rm -rf fixture"
15
- end
7
+ inside_of_folder("spec/fixture")
16
8
 
17
9
  it "should fail if it cannot find anything to bump" do
18
10
  bump("current", :fail => true).should include "Unable to find"
@@ -249,33 +241,18 @@ describe Bump do
249
241
  Bundler.with_clean_env { bump("patch --no-bundle") }
250
242
  read(gemspec).should include "1.0.1"
251
243
  read("Gemfile.lock").should include "1.0.0"
244
+ `git status --porcelain`.should include "?? Gemfile.lock"
252
245
  end
253
246
 
254
- it "does not commit an untracked Gemfile.lock" do
247
+ it "does not bundle or commit an untracked Gemfile.lock" do
255
248
  Bundler.with_clean_env { bump("patch") }
256
- read("Gemfile.lock").should include "1.0.1"
257
- `git status`.should include "Untracked files:"
249
+ read("Gemfile.lock").should include "1.0.0"
250
+ `git status --porcelain`.should include "?? Gemfile.lock"
258
251
  end
259
252
  end
260
253
 
261
254
  private
262
255
 
263
- def write(file, content)
264
- folder = File.dirname(file)
265
- run "mkdir -p #{folder}" unless File.exist?(folder)
266
- File.open(file, 'w'){|f| f.write content }
267
- end
268
-
269
- def read(file)
270
- File.read(file)
271
- end
272
-
273
- def run(cmd, options={})
274
- result = `#{cmd} 2>&1`
275
- raise "FAILED #{cmd} --> #{result}" if $?.success? != !options[:fail]
276
- result
277
- end
278
-
279
256
  def bump(command="", options={})
280
257
  run "#{File.expand_path("../../bin/bump", __FILE__)} #{command}", options
281
258
  end
@@ -0,0 +1,41 @@
1
+ require "bundler"
2
+ require "bump"
3
+
4
+ module SpecHelpers
5
+ module InstanceMethods
6
+ def write(file, content)
7
+ folder = File.dirname(file)
8
+ run "mkdir -p #{folder}" unless File.exist?(folder)
9
+ File.open(file, 'w'){|f| f.write content }
10
+ end
11
+
12
+ def read(file)
13
+ File.read(file)
14
+ end
15
+
16
+ def run(cmd, options={})
17
+ result = `#{cmd} 2>&1`
18
+ raise "FAILED #{cmd} --> #{result}" if $?.success? != !options[:fail]
19
+ result
20
+ end
21
+ end
22
+
23
+ module ClassMethods
24
+ def inside_of_folder(folder)
25
+ folder = File.expand_path(folder, File.dirname(File.dirname(__FILE__)))
26
+ around do |example|
27
+ run "rm -rf #{folder} && mkdir #{folder}"
28
+ Dir.chdir folder do
29
+ `git init && git commit --allow-empty -am 'initial'` # so we never accidentally do commit to the current repo
30
+ example.call
31
+ end
32
+ run "rm -rf #{folder}"
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ RSpec.configure do |c|
39
+ c.include SpecHelpers::InstanceMethods
40
+ c.extend SpecHelpers::ClassMethods
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-22 00:00:00.000000000 Z
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: g.marcilhacy@gmail.com
@@ -27,7 +27,10 @@ files:
27
27
  - bin/bump
28
28
  - bump.gemspec
29
29
  - lib/bump.rb
30
+ - lib/bump/tasks.rb
31
+ - spec/bump/tasks_spec.rb
30
32
  - spec/bump_spec.rb
33
+ - spec/spec_helper.rb
31
34
  homepage: https://github.com/gregorym/bump
32
35
  licenses:
33
36
  - MIT