Skip to content

HTTPS clone URL

Subversion checkout URL

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