simpler keepalive check for synchronous models
[rainbows.git] / Rakefile
blob373604433ab2754e0d02e9915ef350a8abbf0d64
1 # -*- encoding: binary -*-
2 autoload :Gem, 'rubygems'
3 autoload :Tempfile, 'tempfile'
5 # most tasks are in the GNUmakefile which offers better parallelism
7 def tags
8   timefmt = '%Y-%m-%dT%H:%M:%SZ'
9   @tags ||= `git tag -l`.split(/\n/).map do |tag|
10     if %r{\Av[\d\.]+} =~ tag
11       header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
12       header = header.split(/\n/)
13       tagger = header.grep(/\Atagger /).first
14       body ||= "initial"
15       {
16         :time => Time.at(tagger.split(/ /)[-2].to_i).utc.strftime(timefmt),
17         :tagger_name => %r{^tagger ([^<]+)}.match(tagger)[1].strip,
18         :tagger_email => %r{<([^>]+)>}.match(tagger)[1].strip,
19         :id => `git rev-parse refs/tags/#{tag}`.chomp!,
20         :tag => tag,
21         :subject => subject,
22         :body => body,
23       }
24     end
25   end.compact.sort { |a,b| b[:time] <=> a[:time] }
26 end
28 cgit_url = "http://git.bogomips.org/cgit/rainbows.git"
29 git_url = ENV['GIT_URL'] || 'git://git.bogomips.org/rainbows.git'
31 desc 'prints news as an Atom feed'
32 task :news_atom do
33   require 'nokogiri'
34   new_tags = tags[0,10]
35   puts(Nokogiri::XML::Builder.new do
36     feed :xmlns => "http://www.w3.org/2005/Atom" do
37       id! "http://rainbows.rubyforge.org/NEWS.atom.xml"
38       title "Rainbows! news"
39       subtitle "Unicorn for sleepy apps and slow clients"
40       link! :rel => 'alternate', :type => 'text/html',
41             :href => 'http://rainbows.rubyforge.org/NEWS.html'
42       updated(new_tags.empty? ? "1970-01-01T00:00:00Z" : new_tags.first[:time])
43       new_tags.each do |tag|
44         entry do
45           title tag[:subject]
46           updated tag[:time]
47           published tag[:time]
48           author {
49             name tag[:tagger_name]
50             email tag[:tagger_email]
51           }
52           url = "#{cgit_url}/tag/?id=#{tag[:tag]}"
53           link! :rel => "alternate", :type => "text/html", :href =>url
54           id! url
55           message_only = tag[:body].split(/\n.+\(\d+\):\n {6}/s).first.strip
56           content({:type =>:text}, message_only)
57           content(:type =>:xhtml) { pre tag[:body] }
58         end
59       end
60     end
61   end.to_xml)
62 end
64 desc 'prints RDoc-formatted news'
65 task :news_rdoc do
66   tags.each do |tag|
67     time = tag[:time].tr!('T', ' ').gsub!(/:\d\dZ/, ' UTC')
68     puts "=== #{tag[:tag].sub(/^v/, '')} / #{time}"
69     puts ""
71     body = tag[:body]
72     puts tag[:body].gsub(/^/sm, "  ").gsub(/[ \t]+$/sm, "")
73     puts ""
74   end
75 end
77 desc "print release changelog for Rubyforge"
78 task :release_changes do
79   version = ENV['VERSION'] or abort "VERSION= needed"
80   version = "v#{version}"
81   vtags = tags.map { |tag| tag[:tag] =~ /\Av/ and tag[:tag] }.sort
82   prev = vtags[vtags.index(version) - 1]
83   if prev
84     system('git', 'diff', '--stat', prev, version) or abort $?
85     puts ""
86     system('git', 'log', "#{prev}..#{version}") or abort $?
87   else
88     system('git', 'log', version) or abort $?
89   end
90 end
92 desc "print release notes for Rubyforge"
93 task :release_notes do
94   spec = Gem::Specification.load('rainbows.gemspec')
95   puts spec.description.strip
96   puts ""
97   puts "* #{spec.homepage}"
98   puts "* #{spec.email}"
99   puts "* #{git_url}"
101   _, _, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
102   print "\nChanges:\n\n"
103   puts body
106 desc "read news article from STDIN and post to rubyforge"
107 task :publish_news do
108   require 'rubyforge'
109   spec = Gem::Specification.load('rainbows.gemspec')
110   tmp = Tempfile.new('rf-news')
111   _, subject, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
112   tmp.puts subject
113   tmp.puts
114   tmp.puts spec.description.strip
115   tmp.puts ""
116   tmp.puts "* #{spec.homepage}"
117   tmp.puts "* #{spec.email}"
118   tmp.puts "* #{git_url}"
119   tmp.print "\nChanges:\n\n"
120   tmp.puts body
121   tmp.flush
122   system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
123   msg = File.readlines(tmp.path)
124   subject = msg.shift
125   blank = msg.shift
126   blank == "\n" or abort "no newline after subject!"
127   subject.strip!
128   body = msg.join("").strip!
130   rf = RubyForge.new.configure
131   rf.login
132   rf.post_news('rainbows', subject, body)
135 desc "post to RAA"
136 task :raa_update do
137   require 'net/http'
138   require 'net/netrc'
139   rc = Net::Netrc.locate('rainbows-raa') or abort "~/.netrc not found"
140   password = rc.password
142   s = Gem::Specification.load('rainbows.gemspec')
143   desc = [ s.description.strip ]
144   desc << ""
145   desc << "* #{s.email}"
146   desc << "* #{git_url}"
147   desc << "* #{cgit_url}"
148   desc = desc.join("\n")
149   uri = URI.parse('http://raa.ruby-lang.org/regist.rhtml')
150   form = {
151     :name => s.name,
152     :short_description => s.summary,
153     :version => s.version.to_s,
154     :status => 'experimental',
155     :owner => s.authors.first,
156     :email => s.email,
157     :category_major => 'Library',
158     :category_minor => 'Web',
159     :url => s.homepage,
160     :download => "http://rubyforge.org/frs/?group_id=8977",
161     :license => "Ruby's",
162     :description_style => 'Plain',
163     :description => desc,
164     :pass => password,
165     :submit => "Update",
166   }
167   res = Net::HTTP.post_form(uri, form)
168   p res
169   puts res.body
172 desc "post to FM"
173 task :fm_update do
174   require 'net/http'
175   require 'net/netrc'
176   require 'json'
177   version = ENV['VERSION'] or abort "VERSION= needed"
178   uri = URI.parse('http://freshmeat.net/projects/rainbows/releases.json')
179   rc = Net::Netrc.locate('rainbows-fm') or abort "~/.netrc not found"
180   api_token = rc.password
181   changelog = tags.find { |t| t[:tag] == "v#{version}" }[:body]
182   tmp = Tempfile.new('fm-changelog')
183   tmp.syswrite(changelog)
184   system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
185   changelog = File.read(tmp.path).strip
187   req = {
188     "auth_code" => api_token,
189     "release" => {
190       "tag_list" => "Stable",
191       "version" => version,
192       "changelog" => changelog,
193     },
194   }.to_json
195   if ! changelog.strip.empty? && version =~ %r{\A[\d\.]+\d+\z}
196     Net::HTTP.start(uri.host, uri.port) do |http|
197       p http.post(uri.path, req, {'Content-Type'=>'application/json'})
198     end
199   else
200     warn "not updating freshmeat for v#{version}"
201   end