]> projects.mako.cc - rubyvote/blob - Rakefile
Merged in changes that added unit test support by Joe Slag. Thanks!
[rubyvote] / Rakefile
1 require 'rubygems'
2 require 'rake'
3 require 'rake/testtask'
4 require 'rake/rdoctask'
5 require 'rake/packagetask'
6 require 'rake/gempackagetask'
7 require 'rake/contrib/rubyforgepublisher'
8
9 PKG_NAME = "rubyvote"
10 PKG_VERSION = "0.2"
11 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
12 RELEASE_NAME  = "REL #{PKG_VERSION}"
13
14 RUBY_FORGE_PROJECT = "rubyvote"
15 RUBY_FORGE_USER    = "mako"
16
17 desc "Default Task"
18 task :default => [ :test ]
19
20 # Run the unit tests
21 Rake::TestTask.new { |t|
22   t.libs << "test"
23   t.pattern = 'test/*_test.rb'
24   t.verbose = true
25 }
26
27
28 # Genereate the RDoc documentation
29 Rake::RDocTask.new { |rdoc|
30   rdoc.rdoc_dir = 'doc'
31   rdoc.title    = "RubyVote -- Election Methods in Ruby"
32   rdoc.rdoc_files.include('README', 'ChangeLog', 'COPYING')
33   rdoc.rdoc_files.include('lib/rubyvote.rb')
34   rdoc.rdoc_files.include('lib/rubyvote/*.rb')
35 }
36
37
38 # Create compressed packages
39 spec = Gem::Specification.new do |s|
40   s.platform = Gem::Platform::RUBY
41   s.name = PKG_NAME
42   s.summary = "Election methods library in ruby."
43   s.description = %q{Provides a variety of different election types.}
44   s.version = PKG_VERSION
45
46   s.author = "Benjamin Mako Hill"
47   s.email = "mako @nospam@ atdot.cc"
48   s.rubyforge_project = RUBY_FORGE_PROJECT
49   s.homepage = "http://rubyvote.rubyforge.org"
50
51   s.has_rdoc = true
52   s.requirements << 'none'
53   s.require_path = 'lib'
54   s.autorequire = 'rubyvote'
55
56   s.files = [ "Rakefile", "README", "ChangeLog", "COPYING" ]
57   s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
58   s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
59 end
60   
61 Rake::GemPackageTask.new(spec) do |p|
62   p.gem_spec = spec
63   p.need_tar = true
64   p.need_zip = true
65 end
66
67 ###TODO: Configure for api documentation login and path
68 desc "Publish the API documentation"
69 task :pgem => [:package] do 
70   Rake::SshFilePublisher.new("login@foo.com", "path/to/place", "pkg", "#{PKG_FILE_NAME}.gem").upload
71 end
72
73 desc "Publish the release files to RubyForge."
74 task :release => [:package] do
75   files = ["gem", "tgz", "zip"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
76
77   if RUBY_FORGE_PROJECT then
78     require 'net/http'
79     require 'open-uri'
80
81     project_uri = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}/"
82     project_data = open(project_uri) { |data| data.read }
83     group_id = project_data[/[?&]group_id=(\d+)/, 1]
84     raise "Couldn't get group id" unless group_id
85
86     # This echos password to shell which is a bit sucky
87     if ENV["RUBY_FORGE_PASSWORD"]
88       password = ENV["RUBY_FORGE_PASSWORD"]
89     else
90       print "#{RUBY_FORGE_USER}@rubyforge.org's password: "
91       password = STDIN.gets.chomp
92     end
93
94     login_response = Net::HTTP.start("rubyforge.org", 80) do |http|
95       data = [
96         "login=1",
97         "form_loginname=#{RUBY_FORGE_USER}",
98         "form_pw=#{password}"
99       ].join("&")
100       http.post("/account/login.php", data)
101     end
102
103     cookie = login_response["set-cookie"]
104     raise "Login failed" unless cookie
105     headers = { "Cookie" => cookie }
106
107     release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}"
108     release_data = open(release_uri, headers) { |data| data.read }
109     package_id = release_data[/[?&]package_id=(\d+)/, 1]
110     raise "Couldn't get package id" unless package_id
111
112     first_file = true
113     release_id = ""
114
115     files.each do |filename|
116       basename  = File.basename(filename)
117       file_ext  = File.extname(filename)
118       file_data = File.open(filename, "rb") { |file| file.read }
119
120       puts "Releasing #{basename}..."
121
122       release_response = Net::HTTP.start("rubyforge.org", 80) do |http|
123         release_date = Time.now.strftime("%Y-%m-%d %H:%M")
124         type_map = {
125           ".zip"    => "3000",
126           ".tgz"    => "3110",
127           ".gz"     => "3110",
128           ".gem"    => "1400"
129         }; type_map.default = "9999"
130         type = type_map[file_ext]
131         boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"
132
133         query_hash = if first_file then
134           {
135             "group_id" => group_id,
136             "package_id" => package_id,
137             "release_name" => RELEASE_NAME,
138             "release_date" => release_date,
139             "type_id" => type,
140             "processor_id" => "8000", # Any
141             "release_notes" => "",
142             "release_changes" => "",
143             "preformatted" => "1",
144             "submit" => "1"
145           }
146         else
147           {
148             "group_id" => group_id,
149             "release_id" => release_id,
150             "package_id" => package_id,
151             "step2" => "1",
152             "type_id" => type,
153             "processor_id" => "8000", # Any
154             "submit" => "Add This File"
155           }
156         end
157
158         query = "?" + query_hash.map do |(name, value)|
159           [name, URI.encode(value)].join("=")
160         end.join("&")
161
162         data = [
163           "--" + boundary,
164           "Content-Disposition: form-data; name=\"userfile\"; filename=\"#{basename}\"",
165           "Content-Type: application/octet-stream",
166           "Content-Transfer-Encoding: binary",
167           "", file_data, ""
168           ].join("\x0D\x0A")
169
170         release_headers = headers.merge(
171           "Content-Type" => "multipart/form-data; boundary=#{boundary}"
172         )
173
174         target = first_file ? "/frs/admin/qrs.php" : "/frs/admin/editrelease.php"
175         http.post(target + query, data, release_headers)
176       end
177
178       if first_file then
179         release_id = release_response.body[/release_id=(\d+)/, 1]
180         raise("Couldn't get release id") unless release_id
181       end
182
183       first_file = false
184     end
185   end
186 end

Benjamin Mako Hill || Want to submit a patch?