forked from marcel/aws-s3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
334 lines (275 loc) · 9.54 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require File.dirname(__FILE__) + '/lib/aws/s3'
def library_root
File.dirname(__FILE__)
end
task :default => :test
Rake::TestTask.new do |test|
test.pattern = 'test/*_test.rb'
test.verbose = true
end
namespace :doc do
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = "AWS::S3 -- Support for Amazon S3's REST api"
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('COPYING')
rdoc.rdoc_files.include('INSTALL')
rdoc.rdoc_files.include('lib/**/*.rb')
end
task :rdoc => 'doc:readme'
task :refresh => :rerdoc do
system 'open doc/index.html'
end
task :readme do
require 'support/rdoc/code_info'
RDoc::CodeInfo.parse('lib/**/*.rb')
strip_comments = lambda {|comment| comment.gsub(/^# ?/, '')}
docs_for = lambda do |location|
info = RDoc::CodeInfo.for(location)
raise RuntimeError, "Couldn't find documentation for `#{location}'" unless info
strip_comments[info.comment]
end
open('README', 'w') do |file|
file.write ERB.new(IO.read('README.erb')).result(binding)
end
end
task :deploy => :rerdoc do
sh %(scp -r doc [email protected]:/var/www/gforge-projects/amazon/)
end
end
namespace :dist do
spec = Gem::Specification.new do |s|
s.name = 'aws-s3'
s.version = Gem::Version.new(AWS::S3::Version)
s.summary = "Client library for Amazon's Simple Storage Service's REST API"
s.description = s.summary
s.email = '[email protected]'
s.author = 'Marcel Molina Jr.'
s.has_rdoc = true
s.extra_rdoc_files = %w(README COPYING INSTALL)
s.homepage = 'http://amazon.rubyforge.org'
s.rubyforge_project = 'amazon'
s.files = FileList['Rakefile', 'lib/**/*.rb', 'bin/*', 'support/**/*.rb']
s.executables << 's3sh'
s.test_files = Dir['test/**/*']
s.add_dependency 'xml-simple'
s.add_dependency 'builder'
s.add_dependency 'mime-types'
s.rdoc_options = ['--title', "AWS::S3 -- Support for Amazon S3's REST api",
'--main', 'README',
'--line-numbers', '--inline-source']
end
# Regenerate README before packaging
task :package => 'doc:readme'
Rake::GemPackageTask.new(spec) do |pkg|
pkg.need_tar_gz = true
pkg.package_files.include('{lib,script,test,support}/**/*')
pkg.package_files.include('README')
pkg.package_files.include('COPYING')
pkg.package_files.include('INSTALL')
pkg.package_files.include('Rakefile')
end
desc 'Install with gems'
task :install => :repackage do
sh "sudo gem i pkg/#{spec.name}-#{spec.version}.gem"
end
desc 'Uninstall gem'
task :uninstall do
sh "sudo gem uninstall #{spec.name} -x"
end
desc 'Reinstall gem'
task :reinstall => [:uninstall, :install]
task :confirm_release do
print "Releasing version #{spec.version}. Are you sure you want to proceed? [Yn] "
abort if STDIN.getc == ?n
end
desc 'Tag release'
task :tag do
sh %(git tag -a '#{spec.version}-release' -m 'Tagging #{spec.version} release')
sh 'git push --tags'
end
desc 'Update changelog to include a release marker'
task :add_release_marker_to_changelog do
changelog = IO.read('CHANGELOG')
changelog.sub!(/^head:/, "#{spec.version}:")
open('CHANGELOG', 'w') do |file|
file.write "head:\n\n#{changelog}"
end
end
task :commit_changelog do
sh %(git commit CHANGELOG -m "Bump changelog version marker for release")
sh 'git push'
end
package_name = lambda {|specification| File.join('pkg', "#{specification.name}-#{specification.version}")}
desc 'Push a release to rubyforge'
task :release => [:confirm_release, :clean, :add_release_marker_to_changelog, :package, :commit_changelog, :tag] do
require 'rubyforge'
package = package_name[spec]
rubyforge = RubyForge.new.configure
rubyforge.login
user_config = rubyforge.userconfig
user_config['release_changes'] = YAML.load_file('CHANGELOG')[spec.version.to_s].join("\n")
version_already_released = lambda do
releases = rubyforge.autoconfig['release_ids']
releases.has_key?(spec.name) && releases[spec.name][spec.version.to_s]
end
abort("Release #{spec.version} already exists!") if version_already_released.call
begin
rubyforge.add_release(spec.rubyforge_project, spec.name, spec.version.to_s, "#{package}.tar.gz", "#{package}.gem")
puts "Version #{spec.version} released!"
rescue Exception => exception
puts 'Release failed!'
raise
end
end
desc 'Upload a beta gem'
task :push_beta_gem => [:clobber_package, :package] do
beta_gem = package_name[spec]
sh %(scp #{beta_gem}.gem [email protected]:/var/www/gforge-projects/amazon/beta)
end
task :spec do
puts spec.to_ruby
end
end
desc 'Check code to test ratio'
task :stats do
library_files = FileList["#{library_root}/lib/**/*.rb"]
test_files = FileList["#{library_root}/test/**/*_test.rb"]
count_code_lines = Proc.new do |lines|
lines.inject(0) do |code_lines, line|
next code_lines if [/^\s*$/, /^\s*#/].any? {|non_code_line| non_code_line === line}
code_lines + 1
end
end
count_code_lines_for_files = Proc.new do |files|
files.inject(0) {|code_lines, file| code_lines + count_code_lines[IO.read(file)]}
end
library_code_lines = count_code_lines_for_files[library_files]
test_code_lines = count_code_lines_for_files[test_files]
ratio = Proc.new { sprintf('%.2f', test_code_lines.to_f / library_code_lines)}
puts "Code LOC: #{library_code_lines} Test LOC: #{test_code_lines} Code to Test Ratio: 1:#{ratio.call}"
end
namespace :test do
find_file = lambda do |name|
file_name = lambda {|path| File.join(path, "#{name}.rb")}
root = $:.detect do |path|
File.exist?(file_name[path])
end
file_name[root] if root
end
TEST_LOADER = find_file['rake/rake_test_loader']
multiruby = lambda do |glob|
system 'multiruby', TEST_LOADER, *Dir.glob(glob)
end
desc 'Check test coverage'
task :coverage do
system("rcov --sort coverage #{File.join(library_root, 'test/*_test.rb')}")
show_test_coverage_results
end
Rake::TestTask.new(:remote) do |test|
test.pattern = 'test/remote/*_test.rb'
test.verbose = true
end
Rake::TestTask.new(:all) do |test|
test.pattern = 'test/**/*_test.rb'
test.verbose = true
end
desc 'Check test coverage of full stack remote tests'
task :full_coverage do
system("rcov --sort coverage #{File.join(library_root, 'test/remote/*_test.rb')} #{File.join(library_root, 'test/*_test.rb')}")
show_test_coverage_results
end
desc 'Run local tests against multiple versions of Ruby'
task :version_audit do
multiruby['test/*_test.rb']
end
namespace :version_audit do
desc 'Run remote tests against multiple versions of Ruby'
task :remote do
multiruby['test/remote/*_test.rb']
end
desc 'Run all tests against multiple versions of Ruby'
task :all do
multiruby['test/**/*_test.rb']
end
end
def show_test_coverage_results
system("open #{File.join(library_root, 'coverage/index.html')}") if PLATFORM['darwin']
end
desc 'Remove coverage products'
task :clobber_coverage do
rm_r 'coverage' rescue nil
end
end
namespace :todo do
class << TODOS = IO.read(File.join(library_root, 'TODO'))
def items
split("\n").grep(/^\[\s|X\]/)
end
def completed
find_items_matching(/^\[X\]/)
end
def uncompleted
find_items_matching(/^\[\s\]/)
end
def find_items_matching(regexp)
items.grep(regexp).instance_eval do
def display
puts map {|item| "* #{item.sub(/^\[[^\]]\]\s/, '')}"}
end
self
end
end
end
desc 'Completed todo items'
task :completed do
TODOS.completed.display
end
desc 'Incomplete todo items'
task :uncompleted do
TODOS.uncompleted.display
end
end if File.exists?(File.join(library_root, 'TODO'))
namespace :site do
require 'erb'
require 'rdoc/markup/simple_markup'
require 'rdoc/markup/simple_markup/to_html'
readme = lambda { IO.read('README')[/^== Getting started\n(.*)/m, 1] }
readme_to_html = lambda do
handler = SM::ToHtml.new
handler.instance_eval do
require 'syntax'
require 'syntax/convertors/html'
def accept_verbatim(am, fragment)
syntax = Syntax::Convertors::HTML.for_syntax('ruby')
@res << %(<div class="ruby">#{syntax.convert(fragment.txt, true)}</div>)
end
end
SM::SimpleMarkup.new.convert(readme.call, handler)
end
desc 'Regenerate the public website page'
task :build => 'doc:readme' do
open('site/public/index.html', 'w') do |file|
erb_data = {}
erb_data[:readme] = readme_to_html.call
file.write ERB.new(IO.read('site/index.erb')).result(binding)
end
end
task :refresh => :build do
system 'open site/public/index.html'
end
desc 'Update the live website'
task :deploy => :build do
site_files = FileList['site/public/*']
site_files.delete_if {|file| File.directory?(file)}
sh %(scp #{site_files.join ' '} [email protected]:/var/www/gforge-projects/amazon/)
end
end
task :clean => ['dist:clobber_package', 'doc:clobber_rdoc', 'test:clobber_coverage']