release.rake
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:6k
源码类别:

Ajax

开发平台:

Others

  1. require 'rake/gempackagetask'
  2. require 'rake/contrib/rubyforgepublisher'
  3. PKG_VERSION = "5.4.4"
  4. PKG_NAME = "typo"
  5. PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
  6. RUBY_FORGE_PROJECT = 'typo'
  7. RUBY_FORGE_USER = 'fdevillamil'
  8. RELEASE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
  9. spec = Gem::Specification.new do |s|
  10.   s.name = PKG_NAME
  11.   s.version = PKG_VERSION
  12.   s.summary = "Modern weblog engine."
  13.   s.has_rdoc = false
  14.   
  15.   s.files = Dir.glob('**/*', File::FNM_DOTMATCH).reject do |f| 
  16.      [ /.$/, /config/database.yml$/, /config/database.yml-/, 
  17.      /database.sqlite/,
  18.      /.log$/, /^pkg/, /.git/, /^vendor/rails/, 
  19.      /^public/(files|xml|articles|pages|index.html)/, 
  20.      /^public/(stylesheets|javascripts|images)/theme/, /~$/, 
  21.      //._/, //#/ ].any? {|regex| f =~ regex }
  22.   end
  23.   s.require_path = '.'
  24.   s.author = "Frédéric de Villamil"
  25.   s.email = "frederic@de-villamil.com"
  26.   s.homepage = "http://typosphere.org"  
  27.   s.rubyforge_project = "typo"
  28.   s.platform = Gem::Platform::RUBY 
  29.   s.executables = ['typo']
  30.   
  31.   s.add_dependency("rails", "= 2.3.5")
  32.   s.add_dependency("rails-app-installer", ">= 0.2.0")
  33.   s.add_dependency("ruby-debug", ">= 0.10.3")
  34.   s.add_dependency("flexmock", ">= 0.8.3")
  35.   s.add_dependency("rspec-rails", "= 1.2.7.1")
  36.   s.add_dependency("bluecloth", "~> 2.0.5")
  37.   s.add_dependency("htmlentities")
  38.   s.add_dependency("json")
  39.   s.add_dependency("calendar_date_select")
  40.   s.add_dependency("coderay", "~> 0.8")
  41.   s.add_dependency('RedCloth', "~> 4.2.2")
  42. end
  43. Rake::GemPackageTask.new(spec) do |p|
  44.   p.gem_spec = spec
  45.   p.need_tar = true
  46.   p.need_zip = true
  47. end
  48. desc "Publish the zip/tgz"
  49. task :leetsoft_upload => [:package] do
  50.   Rake::SshFilePublisher.new("leetsoft.com", "dist/pkg", "pkg", "#{PKG_FILE_NAME}.zip").upload
  51.   Rake::SshFilePublisher.new("leetsoft.com", "dist/pkg", "pkg", "#{PKG_FILE_NAME}.tgz").upload
  52. end
  53. desc "Publish the release files to RubyForge."
  54. task :tag_svn do
  55.   system("svn cp svn://typosphere.org/typo/trunk svn://typosphere.org/typo/tags/release_#{PKG_VERSION.gsub(/./,'_')} -m 'tag release #{PKG_VERSION}'")
  56. end
  57. desc "Publish the release files to RubyForge."
  58. task :rubyforge_upload => [:package] do
  59.   files = ["tgz", "zip"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
  60.   if RUBY_FORGE_PROJECT then
  61.     require 'net/http'
  62.     require 'open-uri'
  63.     project_uri = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}/"
  64.     project_data = open(project_uri) { |data| data.read }
  65.     group_id = project_data[/[?&]group_id=(d+)/, 1]
  66.     raise "Couldn't get group id" unless group_id
  67.     # This echos password to shell which is a bit sucky
  68.     if ENV["RUBY_FORGE_PASSWORD"]
  69.       password = ENV["RUBY_FORGE_PASSWORD"]
  70.     else
  71.       print "#{RUBY_FORGE_USER}@rubyforge.org's password: "
  72.       password = STDIN.gets.chomp
  73.     end
  74.     login_response = Net::HTTP.start("rubyforge.org", 80) do |http|
  75.       data = [
  76.         "login=1",
  77.         "form_loginname=#{RUBY_FORGE_USER}",
  78.         "form_pw=#{password}"
  79.       ].join("&")
  80.       http.post("/account/login.php", data)
  81.     end
  82.     cookie = login_response["set-cookie"]
  83.     raise "Login failed" unless cookie
  84.     headers = { "Cookie" => cookie }
  85.     release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}"
  86.     release_data = open(release_uri, headers) { |data| data.read }
  87.     package_id = release_data[/[?&]package_id=(d+)/, 1]
  88.     raise "Couldn't get package id" unless package_id
  89.     first_file = true
  90.     release_id = ""
  91.     files.each do |filename|
  92.       basename  = File.basename(filename)
  93.       file_ext  = File.extname(filename)
  94.       file_data = File.open(filename, "rb") { |file| file.read }
  95.       puts "Releasing #{basename}..."
  96.       release_response = Net::HTTP.start("rubyforge.org", 80) do |http|
  97.         release_date = Time.now.strftime("%Y-%m-%d %H:%M")
  98.         type_map = {
  99.           ".zip"    => "3000",
  100.           ".tgz"    => "3110",
  101.           ".gz"     => "3110",
  102.           ".gem"    => "1400"
  103.         }; type_map.default = "9999"
  104.         type = type_map[file_ext]
  105.         boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"
  106.         query_hash = if first_file then
  107.           {
  108.             "group_id" => group_id,
  109.             "package_id" => package_id,
  110.             "release_name" => RELEASE_NAME,
  111.             "release_date" => release_date,
  112.             "type_id" => type,
  113.             "processor_id" => "8000", # Any
  114.             "release_notes" => "",
  115.             "release_changes" => "",
  116.             "preformatted" => "1",
  117.             "submit" => "1"
  118.           }
  119.         else
  120.           {
  121.             "group_id" => group_id,
  122.             "release_id" => release_id,
  123.             "package_id" => package_id,
  124.             "step2" => "1",
  125.             "type_id" => type,
  126.             "processor_id" => "8000", # Any
  127.             "submit" => "Add This File"
  128.           }
  129.         end
  130.         query = "?" + query_hash.map do |(name, value)|
  131.           [name, URI.encode(value)].join("=")
  132.         end.join("&")
  133.         data = [
  134.           "--" + boundary,
  135.           "Content-Disposition: form-data; name="userfile"; filename="#{basename}"",
  136.           "Content-Type: application/octet-stream",
  137.           "Content-Transfer-Encoding: binary",
  138.           "", file_data, ""
  139.           ].join("x0Dx0A")
  140.         release_headers = headers.merge(
  141.           "Content-Type" => "multipart/form-data; boundary=#{boundary}"
  142.         )
  143.         target = first_file ? "/frs/admin/qrs.php" : "/frs/admin/editrelease.php"
  144.         http.post(target + query, data, release_headers)
  145.       end
  146.       if first_file then
  147.         release_id = release_response.body[/release_id=(d+)/, 1]
  148.         raise("Couldn't get release id") unless release_id
  149.       end
  150.       first_file = false
  151.     end
  152.   end
  153. end
  154. desc "Upload the package to leetsoft, rubyforge and tag the release in svn"
  155. #task :release => [:sweep_cache, :package, :leetsoft_upload, :rubyforge_upload, :tag_svn ]
  156. task :release => [:sweep_cache, :package ]