bump "rack.version" env to [1,1]
[unicorn.git] / Rakefile
blob755915cefed2e31ba597d2413164d41973510667
1 # -*- encoding: binary -*-
3 # most tasks are in the GNUmakefile which offers better parallelism
5 def old_summaries
6   @old_summaries ||= File.readlines(".CHANGELOG.old").inject({}) do |hash, line|
7     version, summary = line.split(/ - /, 2)
8     hash[version] = summary
9     hash
10   end
11 end
13 def tags
14   timefmt = '%Y-%m-%dT%H:%M:%SZ'
15   @tags ||= `git tag -l`.split(/\n/).map do |tag|
16     next if tag == "v0.0.0"
17     if %r{\Av[\d\.]+\z} =~ tag
18       header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
19       header = header.split(/\n/)
20       tagger = header.grep(/\Atagger /).first
21       body ||= "initial"
22       {
23         :time => Time.at(tagger.split(/ /)[-2].to_i).utc.strftime(timefmt),
24         :tagger_name => %r{^tagger ([^<]+)}.match(tagger)[1].strip,
25         :tagger_email => %r{<([^>]+)>}.match(tagger)[1].strip,
26         :id => `git rev-parse refs/tags/#{tag}`.chomp!,
27         :tag => tag,
28         :subject => subject,
29         :body => (old = old_summaries[tag]) ? "#{old}\n#{body}" : body,
30       }
31     end
32   end.compact.sort { |a,b| b[:time] <=> a[:time] }
33 end
35 cgit_url = "http://git.bogomips.org/cgit/unicorn.git"
36 git_url = ENV['GIT_URL'] || 'git://git.bogomips.org/unicorn.git'
38 desc 'prints news as an Atom feed'
39 task :news_atom do
40   require 'nokogiri'
41   new_tags = tags[0,10]
42   puts(Nokogiri::XML::Builder.new do
43     feed :xmlns => "http://www.w3.org/2005/Atom" do
44       id! "http://unicorn.bogomips.org/NEWS.atom.xml"
45       title "Unicorn news"
46       subtitle "Rack HTTP server for Unix and fast clients"
47       link! :rel => 'alternate', :type => 'text/html',
48             :href => 'http://unicorn.bogomips.org/NEWS.html'
49       updated new_tags.first[:time]
50       new_tags.each do |tag|
51         entry do
52           title tag[:subject]
53           updated tag[:time]
54           published tag[:time]
55           author {
56             name tag[:tagger_name]
57             email tag[:tagger_email]
58           }
59           url = "#{cgit_url}/tag/?id=#{tag[:tag]}"
60           link! :rel => "alternate", :type => "text/html", :href =>url
61           id! url
62           message_only = tag[:body].split(/\n.+\(\d+\):\n {6}/s).first.strip
63           content({:type =>:text}, message_only)
64           content(:type =>:xhtml) { pre tag[:body] }
65         end
66       end
67     end
68   end.to_xml)
69 end
71 desc 'prints RDoc-formatted news'
72 task :news_rdoc do
73   tags.each do |tag|
74     time = tag[:time].tr!('T', ' ').gsub!(/:\d\dZ/, ' UTC')
75     puts "=== #{tag[:tag].sub(/^v/, '')} / #{time}"
76     puts ""
78     body = tag[:body]
79     puts tag[:body].gsub(/^/sm, "  ").gsub(/[ \t]+$/sm, "")
80     puts ""
81   end
82 end
84 desc "print release changelog for Rubyforge"
85 task :release_changes do
86   version = ENV['VERSION'] or abort "VERSION= needed"
87   version = "v#{version}"
88   vtags = tags.map { |tag| tag[:tag] =~ /\Av/ and tag[:tag] }.sort
89   prev = vtags[vtags.index(version) - 1]
90   system('git', 'diff', '--stat', prev, version) or abort $?
91   puts ""
92   system('git', 'log', "#{prev}..#{version}") or abort $?
93 end
95 desc "print release notes for Rubyforge"
96 task :release_notes do
97   require 'rubygems'
99   spec = Gem::Specification.load('unicorn.gemspec')
100   puts spec.description.strip
101   puts ""
102   puts "* #{spec.homepage}"
103   puts "* #{spec.email}"
104   puts "* #{git_url}"
106   _, _, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
107   print "\nChanges:\n\n"
108   puts body
111 desc "post to RAA"
112 task :raa_update do
113   require 'rubygems'
114   require 'net/http'
115   require 'net/netrc'
116   rc = Net::Netrc.locate('unicorn-raa') or abort "~/.netrc not found"
117   password = rc.password
119   s = Gem::Specification.load('unicorn.gemspec')
120   desc = [ s.description.strip ]
121   desc << ""
122   desc << "* #{s.email}"
123   desc << "* #{git_url}"
124   desc << "* #{cgit_url}"
125   desc = desc.join("\n")
126   uri = URI.parse('http://raa.ruby-lang.org/regist.rhtml')
127   form = {
128     :name => s.name,
129     :short_description => s.summary,
130     :version => s.version.to_s,
131     :status => 'stable',
132     :owner => s.authors.first,
133     :email => s.email,
134     :category_major => 'Library',
135     :category_minor => 'Web',
136     :url => s.homepage,
137     :download => "http://rubyforge.org/frs/?group_id=1306",
138     :license => "Ruby's",
139     :description_style => 'Plain',
140     :description => desc,
141     :pass => password,
142     :submit => "Update",
143   }
144   res = Net::HTTP.post_form(uri, form)
145   p res
146   puts res.body
149 desc "post to FM"
150 task :fm_update do
151   require 'tempfile'
152   require 'net/http'
153   require 'net/netrc'
154   require 'json'
155   version = ENV['VERSION'] or abort "VERSION= needed"
156   uri = URI.parse('http://freshmeat.net/projects/unicorn/releases.json')
157   rc = Net::Netrc.locate('unicorn-fm') or abort "~/.netrc not found"
158   api_token = rc.password
159   changelog = tags.find { |t| t[:tag] == "v#{version}" }[:body]
160   tmp = Tempfile.new('fm-changelog')
161   tmp.syswrite(changelog)
162   system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
163   changelog = File.read(tmp.path).strip
165   req = {
166     "auth_code" => api_token,
167     "release" => {
168       "tag_list" => "Stable",
169       "version" => version,
170       "changelog" => changelog,
171     },
172   }.to_json
173   Net::HTTP.start(uri.host, uri.port) do |http|
174     p http.post(uri.path, req, {'Content-Type'=>'application/json'})
175   end
178 # optional rake-compiler support in case somebody needs to cross compile
179 begin
180   require 'rubygems'
181   spec = Gem::Specification.load('unicorn.gemspec')
182   require 'rake/extensiontask'
183   unless test ?r, "ext/unicorn_http/unicorn_http.c"
184     abort "run 'gmake ragel' or 'make ragel' to generate the Ragel source"
185   end
186   mk = "ext/unicorn_http/Makefile"
187   if test ?r, mk
188     abort "run 'gmake -C ext/unicorn_http clean' and " \
189           "remove #{mk} before using rake-compiler"
190   end
191   Rake::ExtensionTask.new('unicorn_http', spec)
192 rescue LoadError