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