-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
96 lines (72 loc) · 2.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require "bundler/gem_helper"
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
class Bundler::GemHelper
def git_archive( dir = "../zip" )
FileUtils.mkdir_p dir
dest_path = File.join(dir, "#{name}-#{version}.zip")
cmnd = "git archive --format zip --prefix=#{name}/ HEAD > #{dest_path}"
_, code = sh_with_status( cmnd )
raise "Couldn't archive gem," unless code == 0
Bundler.ui.confirm "#{name} #{version} archived to #{dest_path}."
end
def git_push
ver = version.to_s
cmnd = "git push origin #{ver} "
_, code = sh_with_status( cmnd )
raise "Couldn't git push origin." unless code == 0
cmnd = "git push "
_, code = sh_with_status( cmnd )
raise "Couldn't git push." unless code == 0
Bundler.ui.confirm "Git Push #{ver}."
end
def update_version( new_version )
version_filename = %x[ find . -type f -name "version.rb" | grep -v vendor | head -1 ].chomp
version_pathname = File.expand_path( version_filename )
lines = File.open( version_pathname ).read
lines = lines.gsub( /VERSION\s*=\s*\"\d+\.\d+\.\d+\"/, "VERSION = \"#{new_version}\"" )
File.open( version_pathname, "w" ) do |file|
file.write( lines )
end
cmnd = "git add #{version_pathname} "
_, code = sh_with_status( cmnd )
raise "Couldn't git add," unless code == 0
cmnd = "git commit -m '#{new_version}' "
_, code = sh_with_status( cmnd )
raise "Couldn't git commit." unless code == 0
cmnd = "git tag #{new_version} "
_, code = sh_with_status( cmnd )
raise "Couldn't git tag." unless code == 0
Bundler.ui.confirm "Update Tags to #{new_version}."
end
end
Bundler::GemHelper.new(Dir.pwd).instance_eval do
desc "Archive #{name}-#{version}.zip from repository"
task 'zip' do
git_archive
end
desc "Git Push"
task 'push' do
git_push
end
desc "Update Version Tiny"
task 'tiny' do
major, minor, tiny = version.to_s.split('.')
new_version = [major, minor, tiny.to_i + 1].join('.')
update_version( new_version )
end
desc "Update Version Minor"
task 'minor' do
major, minor, _tiny = version.to_s.split('.')
new_version = [major, minor.to_i + 1, 0].join('.')
update_version( new_version )
end
desc "Update Version Major"
task 'major' do
major, _minor, _tiny = version.to_s.split('.')
new_version = [major.to_i + 1, 0, 0].join('.')
update_version( new_version )
end
end