Skip to content
Newer
Older
100644 442 lines (394 sloc) 11.3 KB
99289a4 @mitchellh Update bundler to use gemspec, modify Rakefile to use bundler environ…
mitchellh authored Aug 21, 2010
1 require 'bundler/setup'
e78c44e @geemus convert to rakegem
geemus authored Apr 20, 2010
2 require 'date'
4bd9095 @geemus fix deprecated requires in Rakefile
geemus authored Sep 15, 2012
3 require 'rubygems'
4 require 'rdoc/task'
5 require 'rubygems/package_task'
59fc86a @dylanegan Not sure if I'm missing something here, but rake did not work.
dylanegan authored Jun 20, 2011
6 require File.dirname(__FILE__) + '/lib/fog'
f9a0610 @geemus Initial commit to fog.
geemus authored May 18, 2009
7
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
8 #############################################################################
9 #
10 # Helper functions
11 #
12 #############################################################################
13
14 def name
15 @name ||= Dir['*.gemspec'].first.split('.').first
f9a0610 @geemus Initial commit to fog.
geemus authored May 18, 2009
16 end
17
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
18 def version
19 line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
20 line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
f9a0610 @geemus Initial commit to fog.
geemus authored May 18, 2009
21 end
22
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
23 def date
24 Date.today.to_s
f9a0610 @geemus Initial commit to fog.
geemus authored May 18, 2009
25 end
26
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
27 def rubyforge_project
28 name
29 end
3c21f15 setting up other two libraries for mocking
Wesley Beary authored Aug 10, 2009
30
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
31 def gemspec_file
32 "#{name}.gemspec"
33 end
3c21f15 setting up other two libraries for mocking
Wesley Beary authored Aug 11, 2009
34
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
35 def gem_file
36 "#{name}-#{version}.gem"
37 end
3c21f15 setting up other two libraries for mocking
Wesley Beary authored Aug 11, 2009
38
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
39 def replace_header(head, header_name)
40 head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
3c21f15 setting up other two libraries for mocking
Wesley Beary authored Aug 11, 2009
41 end
42
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
43 #############################################################################
44 #
45 # Standard tasks
46 #
47 #############################################################################
3c21f15 setting up other two libraries for mocking
Wesley Beary authored Aug 11, 2009
48
189dd88 @chirag-jog Add support to build/re-build/clobber gem/package/docs
chirag-jog authored May 3, 2012
49 GEM_NAME = "#{name}"
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
50 task :default => :test
51
20cc080 @mikehale temporary rake task for convenient testing
mikehale authored Feb 8, 2011
52 namespace :test do
53 task :dynect do
368265f @mikehale rename zone request to zones
mikehale authored Jun 17, 2011
54 [false].each do |mock|
8bda3ba @mikehale always run both mock and non-mock tests
mikehale authored Feb 8, 2011
55 sh("export FOG_MOCK=#{mock} && bundle exec shindont tests/dns/requests/dynect")
368265f @mikehale rename zone request to zones
mikehale authored Jun 17, 2011
56 #sh("export FOG_MOCK=#{mock} && bundle exec shindont tests/dns/models/")
8bda3ba @mikehale always run both mock and non-mock tests
mikehale authored Feb 9, 2011
57 end
20cc080 @mikehale temporary rake task for convenient testing
mikehale authored Feb 8, 2011
58 end
59 end
60
a32d313 @geemus remove examples as they are not that helpful or well supported
geemus authored Feb 27, 2012
61 task :test do
62 Rake::Task[:mock_tests].invoke && Rake::Task[:real_tests].invoke
32d0722 @geemus messy first pass at parallelization of testing
geemus authored May 26, 2011
63 end
64
65 def tests(mocked)
66 Formatador.display_line
67 start = Time.now.to_i
68 threads = []
69 Thread.main[:results] = []
f6a8731 Fix regression in Rakefile introduced in 70e7ea1
Michael Brodhead authored Nov 30, 2011
70 Fog.providers.each do |key, value|
32d0722 @geemus messy first pass at parallelization of testing
geemus authored May 26, 2011
71 threads << Thread.new do
72 Thread.main[:results] << {
f6a8731 Fix regression in Rakefile introduced in 70e7ea1
Michael Brodhead authored Nov 30, 2011
73 :provider => value,
74 :success => sh("export FOG_MOCK=#{mocked} && bundle exec shindont +#{key}")
32d0722 @geemus messy first pass at parallelization of testing
geemus authored May 26, 2011
75 }
76 end
77 end
78 threads.each do |thread|
79 thread.join
80 end
81 Formatador.display_table(Thread.main[:results].sort {|x,y| x[:provider] <=> y[:provider]})
82 Formatador.display_line("[bold]FOG_MOCK=#{mocked}[/] tests completed in [bold]#{Time.now.to_i - start}[/] seconds")
83 Formatador.display_line
84 end
85
86 task :mock_tests do
87 tests(true)
88 end
89
90 task :real_tests do
91 tests(false)
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
92 end
93
bbe5572 @geemus [tests] nuke rake task for test related cleanup
geemus authored Jun 16, 2011
94 task :nuke do
95 Fog.providers.each do |provider|
1160a9e @geemus [core] skip vmfusion in rake nuke
geemus authored Sep 26, 2011
96 next if ['Vmfusion'].include?(provider)
bbe5572 @geemus [tests] nuke rake task for test related cleanup
geemus authored Jun 16, 2011
97 begin
98 compute = Fog::Compute.new(:provider => provider)
99 for server in compute.servers
100 Formatador.display_line("[#{provider}] destroying server #{server.identity}")
101 server.destroy rescue nil
102 end
103 rescue
104 end
8285b41 @geemus [core] kill dns stuff in nuke as well
geemus authored Sep 27, 2011
105 begin
106 dns = Fog::DNS.new(:provider => provider)
107 for zone in dns.zones
108 for record in zone.records
109 record.destroy rescue nil
110 end
111 Formatador.display_line("[#{provider}] destroying zone #{zone.identity}")
112 zone.destroy rescue nil
113 end
114 rescue
115 end
bbe5572 @geemus [tests] nuke rake task for test related cleanup
geemus authored Jun 16, 2011
116 end
117 end
118
b9aa00d @geemus [misc] fix deprecated rdoc rake tasks
geemus authored May 26, 2011
119 require 'rdoc/task'
120 RDoc::Task.new do |rdoc|
f9a0610 @geemus Initial commit to fog.
geemus authored May 18, 2009
121 rdoc.rdoc_dir = 'rdoc'
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
122 rdoc.title = "#{name} #{version}"
f9a0610 @geemus Initial commit to fog.
geemus authored May 18, 2009
123 rdoc.rdoc_files.include('README*')
124 rdoc.rdoc_files.include('lib/**/*.rb')
125 end
126
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
127 desc "Open an irb session preloaded with this library"
128 task :console do
129 sh "irb -rubygems -r ./lib/#{name}.rb"
130 end
131
132 #############################################################################
133 #
134 # Packaging tasks
135 #
136 #############################################################################
137
138 task :release => :build do
139 unless `git branch` =~ /^\* master$/
140 puts "You must be on the master branch to release!"
141 exit!
142 end
cc3d5b9 @geemus Release 0.3.31
geemus authored Dec 10, 2010
143 sh "gem install pkg/#{name}-#{version}.gem"
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
144 sh "git commit --allow-empty -a -m 'Release #{version}'"
145 sh "git tag v#{version}"
146 sh "git push origin master"
f34cd1a @geemus fix tag push
geemus authored Apr 20, 2010
147 sh "git push origin v#{version}"
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
148 sh "gem push pkg/#{name}-#{version}.gem"
8c2bbe4 @geemus [core] update fog.io in release task
geemus authored May 13, 2011
149 Rake::Task[:docs].invoke
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
150 end
151
152 task :build => :gemspec do
153 sh "mkdir -p pkg"
154 sh "gem build #{gemspec_file}"
155 sh "mv #{gem_file} pkg"
156 end
157
158 task :gemspec => :validate do
159 # read spec file and split out manifest section
160 spec = File.read(gemspec_file)
161
162 # replace name version and date
ec6e901 @geemus [gemspec] fix file list, now buildable from source
geemus authored Dec 21, 2010
163 replace_header(spec, :name)
164 replace_header(spec, :version)
165 replace_header(spec, :date)
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
166 #comment this out if your rubyforge_project has a different name
ec6e901 @geemus [gemspec] fix file list, now buildable from source
geemus authored Dec 21, 2010
167 replace_header(spec, :rubyforge_project)
168
e78c44e @geemus convert to rakegem
geemus authored Apr 21, 2010
169 File.open(gemspec_file, 'w') { |io| io.write(spec) }
170 puts "Updated #{gemspec_file}"
171 end
172
173 task :validate do
174 libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
175 unless libfiles.empty?
176 puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
177 exit!
178 end
179 unless Dir['VERSION*'].empty?
180 puts "A `VERSION` file at root level violates Gem best practices."
181 exit!
f9a0610 @geemus Initial commit to fog.
geemus authored May 18, 2009
182 end
183 end
d15a722 @geemus first pass at website deploy script
geemus authored Apr 2, 2011
184
abd05aa @geemus [core] work toward automating changelog
geemus authored May 13, 2011
185 task :changelog do
186 timestamp = Time.now.utc.strftime('%m/%d/%Y')
187 sha = `git log | head -1`.split(' ').last
188 changelog = ["#{version} #{timestamp} #{sha}"]
189 changelog << ('=' * changelog[0].length)
190 changelog << ''
191
8c2a5aa @geemus [release] add stats to changelog
geemus authored Aug 9, 2011
192 require 'multi_json'
59c9f44 @ktheory fix changelog task for github API v3
ktheory authored Jul 2, 2012
193 github_repo_data = Fog::JSON.decode(Excon.get('https://api.github.com/repos/fog/fog').body)
194 data = github_repo_data.reject {|key, value| !['forks', 'open_issues', 'watchers'].include?(key)}
195 github_collaborator_data = Fog::JSON.decode(Excon.get('https://api.github.com/repos/fog/fog/collaborators').body)
196 data['collaborators'] = github_collaborator_data.length
dcefc2d @nirvdrum Fixed #875: Loosen multi_json version.
nirvdrum authored Apr 25, 2012
197 rubygems_data = Fog::JSON.decode(Excon.get('https://rubygems.org/api/v1/gems/fog.json').body)
8c2a5aa @geemus [release] add stats to changelog
geemus authored Aug 9, 2011
198 data['downloads'] = rubygems_data['downloads']
199 stats = []
200 for key in data.keys.sort
201 stats << "'#{key}' => #{data[key]}"
202 end
203 changelog << "Stats! { #{stats.join(', ')} }"
204 changelog << ''
205
abd05aa @geemus [core] work toward automating changelog
geemus authored May 13, 2011
206 last_sha = `cat changelog.txt | head -1`.split(' ').last
207 shortlog = `git shortlog #{last_sha}..HEAD`
208 changes = {}
026a02c @geemus [misc] add mvp suggestion to changelog task
geemus authored May 26, 2011
209 committers = {}
abd05aa @geemus [core] work toward automating changelog
geemus authored May 13, 2011
210 for line in shortlog.split("\n")
211 if line =~ /^\S/
212 committer = line.split(' (', 2).first
026a02c @geemus [misc] add mvp suggestion to changelog task
geemus authored May 26, 2011
213 committers[committer] = 0
0ff135b @geemus [core] omit Release commits from changelog
geemus authored May 13, 2011
214 elsif line =~ /^\s*((Merge.*)|(Release.*))?$/
215 # skip empty lines, Merge and Release commits
abd05aa @geemus [core] work toward automating changelog
geemus authored May 13, 2011
216 else
217 unless line[-1..-1] == '.'
218 line << '.'
219 end
4ca3f7d @geemus [release] update changelog during release process
geemus authored May 26, 2011
220 line.lstrip!
221 line.gsub!(/^\[([^\]]*)\] /, '')
abd05aa @geemus [core] work toward automating changelog
geemus authored May 13, 2011
222 tag = $1 || 'misc'
223 changes[tag] ||= []
224 changes[tag] << (line << ' thanks ' << committer)
026a02c @geemus [misc] add mvp suggestion to changelog task
geemus authored May 26, 2011
225 committers[committer] += 1
abd05aa @geemus [core] work toward automating changelog
geemus authored May 13, 2011
226 end
227 end
228
026a02c @geemus [misc] add mvp suggestion to changelog task
geemus authored May 26, 2011
229 for committer, commits in committers.to_a.sort {|x,y| y[1] <=> x[1]}
4ca3f7d @geemus [release] update changelog during release process
geemus authored May 26, 2011
230 if [
231 'Aaron Suggs',
f87cdfe @geemus [release] update MVP skip list
geemus authored Aug 18, 2011
232 'Brian Hartsock',
368ce6a @geemus [release] add newest MVP to changelog task MVP omit list
geemus authored Jul 25, 2011
233 'Christopher Oliver',
4cc36ef @geemus Release 1.3.1
geemus authored Mar 27, 2012
234 'Decklin Foster',
368ce6a @geemus [release] add newest MVP to changelog task MVP omit list
geemus authored Jul 25, 2011
235 'Dylan Egan',
4ca3f7d @geemus [release] update changelog during release process
geemus authored May 26, 2011
236 'geemus',
368ce6a @geemus [release] add newest MVP to changelog task MVP omit list
geemus authored Jul 25, 2011
237 'Henry Addison',
4846a16 @geemus [release] add Kevin Menard to future MVP exclusion list
geemus authored Mar 19, 2012
238 'Kevin Menard',
31a8552 @geemus [release] add mvps and fix fog.io uploader
geemus authored Jun 24, 2011
239 'Lincoln Stoll',
240 'Luqman Amjad',
6039318 @geemus 1.1.0 changelog
geemus authored Nov 11, 2011
241 'Michael Zeng',
4ca3f7d @geemus [release] update changelog during release process
geemus authored May 26, 2011
242 'nightshade427',
ee93e0f @geemus [release] omit Patrick Debois from future MVP status
geemus authored Sep 29, 2011
243 'Patrick Debois',
cfe6245 @geemus remove latest MVP from future possibilities
geemus authored Dec 18, 2011
244 'Stepan G. Fedorov',
4ca3f7d @geemus [release] update changelog during release process
geemus authored May 26, 2011
245 'Wesley Beary'
246 ].include?(committer)
026a02c @geemus [misc] add mvp suggestion to changelog task
geemus authored May 26, 2011
247 next
248 end
249 changelog << "MVP! #{committer}"
250 changelog << ''
251 break
252 end
253
abd05aa @geemus [core] work toward automating changelog
geemus authored May 13, 2011
254 for tag in changes.keys.sort
255 changelog << ('[' << tag << ']')
256 for commit in changes[tag]
257 changelog << (' ' << commit)
258 end
259 changelog << ''
260 end
261
4ca3f7d @geemus [release] update changelog during release process
geemus authored May 26, 2011
262 old_changelog = File.read('changelog.txt')
263 File.open('changelog.txt', 'w') do |file|
264 file.write(changelog.join("\n"))
265 file.write("\n\n")
266 file.write(old_changelog)
267 end
abd05aa @geemus [core] work toward automating changelog
geemus authored May 13, 2011
268 end
269
d15a722 @geemus first pass at website deploy script
geemus authored Apr 2, 2011
270 task :docs do
822fd3c @geemus [docs] add task to build/publish supported services matrix
geemus authored Aug 9, 2011
271 Rake::Task[:supported_services_docs].invoke
f4f9b05 @geemus [misc] separate fog.io and rdoc tasks
geemus authored May 27, 2011
272 Rake::Task[:upload_fog_io].invoke
273 Rake::Task[:upload_rdoc].invoke
274
31a8552 @geemus [release] add mvps and fix fog.io uploader
geemus authored Jun 24, 2011
275 # connect to storage provider
276 Fog.credential = :geemus
277 storage = Fog::Storage.new(:provider => 'AWS')
278 directory = storage.directories.new(:key => 'fog.io')
f4f9b05 @geemus [misc] separate fog.io and rdoc tasks
geemus authored May 27, 2011
279 # write base index with redirect to new version
280 directory.files.create(
281 :body => redirecter('latest'),
282 :content_type => 'text/html',
283 :key => 'index.html',
284 :public => true
285 )
286
287 Formatador.display_line
288 end
d15a722 @geemus first pass at website deploy script
geemus authored Apr 2, 2011
289
822fd3c @geemus [docs] add task to build/publish supported services matrix
geemus authored Aug 9, 2011
290 task :supported_services_docs do
291 support, shared = {}, []
292 for key, values in Fog.services
293 unless values.length == 1
294 shared |= [key]
295 values.each do |value|
296 support[value] ||= {}
297 support[value][key] = '+'
298 end
299 else
300 value = values.first
301 support[value] ||= {}
302 support[value][:other] ||= []
303 support[value][:other] << key
304 end
305 end
306 shared.sort! {|x,y| x.to_s <=> y.to_s}
307 columns = [:provider] + shared + [:other]
308 data = []
309 for key in support.keys.sort {|x,y| x.to_s <=> y.to_s}
310 data << { :provider => key }.merge!(support[key])
311 end
312
313 table = ''
314 table << "<table border='1'>\n"
315
316 table << " <tr>"
317 for column in columns
318 table << "<th>#{column}</th>"
319 end
320 table << "</tr>\n"
321
322 for datum in data
323 table << " <tr>"
324 for column in columns
325 if value = datum[column]
326 case value
327 when Array
328 table << "<td>#{value.join(', ')}</td>"
329 when '+'
330 table << "<td style='text-align: center;'>#{value}</td>"
331 else
332 table << "<th>#{value}</th>"
333 end
334 else
335 table << "<td></td>"
336 end
337 end
338 table << "</tr>\n"
339 end
340
341 table << "</table>\n"
342
343 File.open('docs/about/supported_services.markdown', 'w') do |file|
344 file.puts <<-METADATA
345 ---
346 layout: default
347 title: Supported Services
348 ---
349
350 METADATA
351 file.puts(table)
352 end
353 end
354
de80fc1 @geemus [docs] alphasort doc tasks
geemus authored Aug 9, 2011
355 task :upload_fog_io do
356 # connect to storage provider
357 Fog.credential = :geemus
358 storage = Fog::Storage.new(:provider => 'AWS')
359 directory = storage.directories.new(:key => 'fog.io')
360
361 # build the docs locally
362 sh "jekyll docs docs/_site"
363
364 # write web page files to versioned 'folder'
365 for file_path in Dir.glob('docs/_site/**/*')
366 next if File.directory?(file_path)
367 file_name = file_path.gsub('docs/_site/', '')
368 key = '' << version << '/' << file_name
369 Formatador.redisplay(' ' * 128)
370 Formatador.redisplay("Uploading [bold]#{key}[/]")
371 if File.extname(file_name) == '.html'
372 # rewrite links with version
373 body = File.read(file_path)
374 body.gsub!(/vX.Y.Z/, 'v' << version)
375 body.gsub!(/='\//, %{='/} << version << '/')
376 body.gsub!(/="\//, %{="/} << version << '/')
377 content_type = 'text/html'
378 directory.files.create(
379 :body => redirecter(key),
380 :content_type => 'text/html',
381 :key => 'latest/' << file_name,
382 :public => true
383 )
384 else
385 body = File.open(file_path)
386 content_type = nil # leave it up to mime-types
387 end
388 directory.files.create(
389 :body => body,
390 :content_type => content_type,
391 :key => key,
392 :public => true
393 )
394 end
395 Formatador.redisplay(' ' * 128)
396 Formatador.redisplay("Uploaded docs/_site\n")
397 end
398
f4f9b05 @geemus [misc] separate fog.io and rdoc tasks
geemus authored May 27, 2011
399 task :upload_rdoc do
400 # connect to storage provider
401 Fog.credential = :geemus
402 storage = Fog::Storage.new(:provider => 'AWS')
403 directory = storage.directories.new(:key => 'fog.io')
4b3e9dc @geemus [docs] also build/deploy rdocs
geemus authored May 19, 2011
404
405 # write rdoc files to versioned 'folder'
406 Rake::Task[:rdoc].invoke
407 for file_path in Dir.glob('rdoc/**/*')
408 next if File.directory?(file_path)
409 file_name = file_path.gsub('rdoc/', '')
410 key = '' << version << '/rdoc/' << file_name
411 Formatador.redisplay(' ' * 128)
32d0722 @geemus messy first pass at parallelization of testing
geemus authored May 26, 2011
412 Formatador.redisplay("Uploading [bold]#{key}[/]")
4b3e9dc @geemus [docs] also build/deploy rdocs
geemus authored May 20, 2011
413 directory.files.create(
414 :body => File.open(file_path),
415 :key => key,
416 :public => true
417 )
418 end
419 Formatador.redisplay(' ' * 128)
c385c4d @geemus [docs] make fog.io/latest/foo link to newest versioned docs
geemus authored May 24, 2011
420 directory.files.create(
421 :body => redirecter("#{version}/rdoc/index.html"),
422 :content_type => 'text/html',
423 :key => 'latest/rdoc/index.html',
424 :public => true
425 )
f4f9b05 @geemus [misc] separate fog.io and rdoc tasks
geemus authored May 27, 2011
426 Formatador.redisplay("Uploaded rdoc\n")
c385c4d @geemus [docs] make fog.io/latest/foo link to newest versioned docs
geemus authored May 24, 2011
427 end
428
429 def redirecter(path)
3fde14c @geemus [core] more consistent redirector for fog.io
geemus authored May 13, 2011
430 redirecter = <<-HTML
431 <!doctype html>
432 <head>
433 <title>fog</title>
c385c4d @geemus [docs] make fog.io/latest/foo link to newest versioned docs
geemus authored May 24, 2011
434 <meta http-equiv="REFRESH" content="0;url=http://fog.io/#{path}">
3fde14c @geemus [core] more consistent redirector for fog.io
geemus authored May 13, 2011
435 </head>
436 <body>
c385c4d @geemus [docs] make fog.io/latest/foo link to newest versioned docs
geemus authored May 24, 2011
437 <a href="http://fog.io/#{path}">redirecting to lastest (#{path})</a>
3fde14c @geemus [core] more consistent redirector for fog.io
geemus authored May 13, 2011
438 </body>
439 </html>
440 HTML
59fc86a @dylanegan Not sure if I'm missing something here, but rake did not work.
dylanegan authored Jun 20, 2011
441 end
Something went wrong with that request. Please try again.