Skip to content

Commit 8bf4b5b

Browse files
committed
Added bump target
1 parent fba8eb4 commit 8bf4b5b

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Rakefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require "bundler/gem_tasks"
22
require "rake/testtask"
33

4+
helper = Bundler::GemHelper.instance
5+
46
Rake::TestTask.new(:test) do |t|
57
t.test_files = FileList["test/**/test_*.rb"]
68
end
@@ -12,3 +14,41 @@ task "build" => "date_epoch"
1214
task "date_epoch" do
1315
ENV["SOURCE_DATE_EPOCH"] = IO.popen(%W[git -C #{__dir__} log -1 --format=%ct], &:read).chomp
1416
end
17+
18+
def helper.update_gemspec
19+
path = "#{__dir__}/#{gemspec.name}.gemspec"
20+
File.open(path, "r+b") do |f|
21+
if (d = f.read).sub!(/^(version\s*=\s*)".*"/) {$1 + gemspec.version.to_s.dump}
22+
f.rewind
23+
f.truncate(0)
24+
f.print(d)
25+
end
26+
end
27+
end
28+
29+
def helper.commit_bump
30+
sh(%W[git -C #{__dir__} commit -m bump\ up\ to\ #{gemspec.version}
31+
#{gemspec.name}.gemspec])
32+
end
33+
34+
def helper.version=(v)
35+
gemspec.version = v
36+
update_gemspec
37+
commit_bump
38+
tag_version
39+
end
40+
major, minor, teeny = helper.gemspec.version.segments
41+
42+
task "bump:teeny" do
43+
helper.version = Gem::Version.new("#{major}.#{minor}.#{teeny+1}")
44+
end
45+
46+
task "bump:minor" do
47+
raise "can't bump up minor"
48+
end
49+
50+
task "bump:major" do
51+
raise "can't bump up major"
52+
end
53+
54+
task "bump" => "bump:teeny"

0 commit comments

Comments
 (0)