Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 171 lines (143 sloc) 4.233 kB
c1abbec @mojombo initial library setup
mojombo authored
1 require 'rubygems'
2 require 'rake'
3 require 'date'
4
5 #############################################################################
6 #
7 # Helper functions
8 #
9 #############################################################################
10
11 def name
12 @name ||= Dir['*.gemspec'].first.split('.').first
13 end
14
15 def version
16 line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17 line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18 end
19
ac432aa @bootstraponline Add bump task to Rakefile
bootstraponline authored
20 # assumes x.y.z all digit version
21 def next_version
22 # x.y.z
23 v = version.split '.'
24 # bump z
25 v[-1] = v[-1].to_i + 1
26 v.join '.'
27 end
28
29 def bump_version
30 old_file = File.read("lib/#{name}.rb")
31 old_version_line = old_file[/^\s*VERSION\s*=\s*.*/]
32 new_version = next_version
33 # replace first match of old vesion with new version
34 old_file.sub!(old_version_line, " VERSION = '#{new_version}'")
35
36 File.write("lib/#{name}.rb", old_file)
37
38 new_version
39 end
40
c1abbec @mojombo initial library setup
mojombo authored
41 def date
42 Date.today.to_s
43 end
44
45 def rubyforge_project
46 name
47 end
48
49 def gemspec_file
50 "#{name}.gemspec"
51 end
52
53 def gem_file
54 "#{name}-#{version}.gem"
55 end
56
57 def replace_header(head, header_name)
58 head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
59 end
60
61 #############################################################################
62 #
63 # Standard tasks
64 #
65 #############################################################################
66
67 task :default => :test
68
69 require 'rake/testtask'
70 Rake::TestTask.new(:test) do |test|
4e3b4e2 @cehoffman Ruby 1.9 compatibility
cehoffman authored
71 test.libs << 'lib' << 'test' << '.'
c1abbec @mojombo initial library setup
mojombo authored
72 test.pattern = 'test/**/test_*.rb'
73 test.verbose = true
74 end
75
76 desc "Generate RCov test coverage and open in your browser"
77 task :coverage do
78 require 'rcov'
79 sh "rm -fr coverage"
80 sh "rcov test/test_*.rb"
81 sh "open coverage/index.html"
82 end
83
84 desc "Open an irb session preloaded with this library"
85 task :console do
86 sh "irb -rubygems -r ./lib/#{name}.rb"
87 end
88
89 #############################################################################
90 #
91 # Custom tasks (add your own tasks here)
92 #
93 #############################################################################
94
ac432aa @bootstraponline Add bump task to Rakefile
bootstraponline authored
95 desc "Update version number and gemspec"
96 task :bump do
97 puts "Updated version to #{bump_version}"
98 # Execute does not invoke dependencies.
99 # Manually invoke gemspec then validate.
100 Rake::Task[:gemspec].execute
101 Rake::Task[:validate].execute
102 end
c1abbec @mojombo initial library setup
mojombo authored
103
104 #############################################################################
105 #
106 # Packaging tasks
107 #
108 #############################################################################
109
00b6f5c @bootstraponline Add desc to tasks so they show up in rake -T.
bootstraponline authored
110 desc 'Create a release build'
c1abbec @mojombo initial library setup
mojombo authored
111 task :release => :build do
112 unless `git branch` =~ /^\* master$/
113 puts "You must be on the master branch to release!"
114 exit!
115 end
116 sh "git commit --allow-empty -a -m 'Release #{version}'"
117 sh "git tag v#{version}"
118 sh "git push origin master"
2a905ce @mojombo Release 1.0.1
mojombo authored
119 sh "git push origin v#{version}"
c1abbec @mojombo initial library setup
mojombo authored
120 sh "gem push pkg/#{name}-#{version}.gem"
121 end
122
00b6f5c @bootstraponline Add desc to tasks so they show up in rake -T.
bootstraponline authored
123 desc 'Build gem'
c1abbec @mojombo initial library setup
mojombo authored
124 task :build => :gemspec do
125 sh "mkdir -p pkg"
126 sh "gem build #{gemspec_file}"
127 sh "mv #{gem_file} pkg"
128 end
129
02d3a3d @bootstraponline Clarify gemspec task desc.
bootstraponline authored
130 desc 'Update gemspec'
c1abbec @mojombo initial library setup
mojombo authored
131 task :gemspec => :validate do
132 # read spec file and split out manifest section
133 spec = File.read(gemspec_file)
134 head, manifest, tail = spec.split(" # = MANIFEST =\n")
135
136 # replace name version and date
137 replace_header(head, :name)
138 replace_header(head, :version)
139 replace_header(head, :date)
140 #comment this out if your rubyforge_project has a different name
141 replace_header(head, :rubyforge_project)
142
143 # determine file list from git ls-files
144 files = `git ls-files`.
145 split("\n").
146 sort.
147 reject { |file| file =~ /^\./ }.
f928cfa @bootstraponline Don't ship Lorem ipsum in gem
bootstraponline authored
148 reject { |file| file =~ /^(rdoc|pkg|test|Home\.md)/ }.
c1abbec @mojombo initial library setup
mojombo authored
149 map { |file| " #{file}" }.
150 join("\n")
151
152 # piece file back together and write
153 manifest = " s.files = %w[\n#{files}\n ]\n"
154 spec = [head, manifest, tail].join(" # = MANIFEST =\n")
155 File.open(gemspec_file, 'w') { |io| io.write(spec) }
156 puts "Updated #{gemspec_file}"
157 end
158
00b6f5c @bootstraponline Add desc to tasks so they show up in rake -T.
bootstraponline authored
159 desc 'Validate lib files and version file'
c1abbec @mojombo initial library setup
mojombo authored
160 task :validate do
161 libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
162 unless libfiles.empty?
163 puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
164 exit!
165 end
166 unless Dir['VERSION*'].empty?
167 puts "A `VERSION` file at root level violates Gem best practices."
168 exit!
169 end
56a5a7d @bootstraponline Fix #507
bootstraponline authored
170 end
Something went wrong with that request. Please try again.