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