forked from dnunez24/channeladvisor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
69 lines (55 loc) · 1.52 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
$:.unshift File.expand_path("../lib", __FILE__)
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "channeladvisor/version"
RSpec::Core::RakeTask.new do |t|
t.rspec_opts = ["--format progress"]
end
task :default => :spec
task :build do
system "gem build channeladvisor.gemspec"
end
task :release => :build do
system "gem push channeladvisor-#{ChannelAdvisor::VERSION}"
end
desc "Display current gem version"
task :version do
puts "Current version: #{ChannelAdvisor::VERSION}"
end
namespace :version do
desc "Bump version (defaults to patch)"
task :bump => "bump:patch"
namespace :bump do
desc "Bump major version"
task :major => :version do |t|
bump_version(t.name.split(":").last)
end
desc "Bump minor version"
task :minor => :version do |t|
bump_version(t.name.split(":").last)
end
desc "Bump patch version"
task :patch => :version do |t|
bump_version(t.name.split(":").last)
end
end
end
def bump_version(segment)
segments = ChannelAdvisor::VERSION.split(".").map(&:to_i)
case segment
when "major"
segments[0] = segments[0] + 1
segments[1] = 0
segments[2] = 0
when "minor"
segments[1] = segments[1] + 1
segments[2] = 0
when "patch"
segments[2] = segments[2] + 1
end
new_version = segments.join(".")
file_name = "lib/channeladvisor/version.rb"
new_text = File.read(file_name).gsub(ChannelAdvisor::VERSION, new_version)
File.open(file_name, "w") { |f| f.puts new_text }
puts "New version: #{new_version}"
end