-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
93 lines (75 loc) · 1.83 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
require 'rake/testtask'
require 'fileutils'
class GemInfo
def initialize
@gemspec_filename = Dir['*.gemspec'][0]
end
def spec
@spec ||= eval(File.read(@gemspec_filename))
end
def name
@name ||= spec.name
end
def version
@version ||= spec.version.to_s
end
def gem_filename
"#{name}-#{version}.gem"
end
def gemspec_filename
@gemspec_filename
end
end
$gem = GemInfo.new
desc "Start irb #{$gem.name} session"
task :console do
sh "irb -rubygems -I./lib -r ./lib/#{$gem.name}.rb"
end
desc "Install #{$gem.name} gem"
task :install => :build do
gemfile = "gem/#{$gem.gem_filename}"
if !gemfile.nil?
sh "gem install --no-ri --no-rdoc #{gemfile}"
else
puts 'Could not find gem.'
end
end
desc "Uninstall #{$gem.name} gem"
task :uninstall do
sh "gem uninstall #{$gem.name} -x"
end
desc "Build #{$gem.name} gem"
task :build do
FileUtils.mkdir_p('gem')
sh "gem build #{$gem.gemspec_filename}"
FileUtils.mv $gem.gem_filename, 'gem'
end
desc "Release #{$gem.name} v#{$gem.version} and tag in git"
task :release => :build do
if (`git` rescue nil).nil?
puts 'Could not run git command.'
exit!
end
if (`gem` rescue nil).nil?
puts 'Could not run gem command.'
exit!
end
unless (`git branch --no-color`.strip rescue '') =~ /\A*\s+master\z/
puts 'You must release from the master branch.'
exit!
end
print "Do you want to release #{$gem.name} v#{$gem.version} and tag it in git (y/n)? "
response = $stdin.gets.strip
unless response =~ /\Ay/
puts 'Aborting.'
exit!
end
version = $gem.version
puts "Releasing version #{version}."
sh "git commit --allow-empty -a -m \"Release #{version}.\""
sh "git tag v#{version}"
sh 'git push origin master'
sh "git push origin v#{version}"
sh "gem push gem/#{$gem.gem_filename}"
puts 'Fin.'
end