doc: add HACKING document
[rainbows.git] / Rakefile
blobdcc0fcef52e19cf329994a6ea47bb11d354cf8be
1 # -*- encoding: binary -*-
2 autoload :Gem, 'rubygems'
3 autoload :Tempfile, 'tempfile'
4 require 'wrongdoc'
6 cgit_url = Wrongdoc.config[:cgit_url]
7 git_url = Wrongdoc.config[:git_url]
9 desc "read news article from STDIN and post to rubyforge"
10 task :publish_news do
11   require 'rubyforge'
12   spec = Gem::Specification.load('rainbows.gemspec')
13   tmp = Tempfile.new('rf-news')
14   _, subject, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
15   tmp.puts subject
16   tmp.puts
17   tmp.puts spec.description.strip
18   tmp.puts ""
19   tmp.puts "* #{spec.homepage}"
20   tmp.puts "* #{spec.email}"
21   tmp.puts "* #{git_url}"
22   tmp.print "\nChanges:\n\n"
23   tmp.puts body
24   tmp.flush
25   system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
26   msg = File.readlines(tmp.path)
27   subject = msg.shift
28   blank = msg.shift
29   blank == "\n" or abort "no newline after subject!"
30   subject.strip!
31   body = msg.join("").strip!
33   rf = RubyForge.new.configure
34   rf.login
35   rf.post_news('rainbows', subject, body)
36 end
38 desc "post to RAA"
39 task :raa_update do
40   require 'net/http'
41   require 'net/netrc'
42   rc = Net::Netrc.locate('rainbows-raa') or abort "~/.netrc not found"
43   password = rc.password
45   s = Gem::Specification.load('rainbows.gemspec')
46   desc = [ s.description.strip ]
47   desc << ""
48   desc << "* #{s.email}"
49   desc << "* #{git_url}"
50   desc << "* #{cgit_url}"
51   desc = desc.join("\n")
52   uri = URI.parse('http://raa.ruby-lang.org/regist.rhtml')
53   form = {
54     :name => s.name,
55     :short_description => s.summary,
56     :version => s.version.to_s,
57     :status => 'experimental',
58     :owner => s.authors.first,
59     :email => s.email,
60     :category_major => 'Library',
61     :category_minor => 'Web',
62     :url => s.homepage,
63     :download => "http://rubyforge.org/frs/?group_id=8977",
64     :license => "Ruby's",
65     :description_style => 'Plain',
66     :description => desc,
67     :pass => password,
68     :submit => "Update",
69   }
70   res = Net::HTTP.post_form(uri, form)
71   p res
72   puts res.body
73 end
75 desc "post to FM"
76 task :fm_update do
77   require 'net/http'
78   require 'net/netrc'
79   require 'json'
80   version = ENV['VERSION'] or abort "VERSION= needed"
81   uri = URI.parse('https://freecode.com/projects/rainbows/releases.json')
82   rc = Net::Netrc.locate('rainbows-fm') or abort "~/.netrc not found"
83   api_token = rc.password
84   _, subject, body = `git cat-file tag v#{version}`.split(/\n\n/, 3)
85   tmp = Tempfile.new('fm-changelog')
86   tmp.puts subject
87   tmp.puts
88   tmp.puts body
89   tmp.flush
90   system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
91   changelog = File.read(tmp.path).strip
93   req = {
94     "auth_code" => api_token,
95     "release" => {
96       "tag_list" => "Stable",
97       "version" => version,
98       "changelog" => changelog,
99     },
100   }.to_json
101   if ! changelog.strip.empty? && version =~ %r{\A[\d\.]+\d+\z}
102     Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
103       p http.post(uri.path, req, {'Content-Type'=>'application/json'})
104     end
105   else
106     warn "not updating freshmeat for v#{version}"
107   end