Rakefile 6.8 KB
Newer Older
1
#!/usr/bin/env rake
2

3
require 'rdoc/task'
4
require 'net/http'
5

6 7 8 9 10 11 12
$:.unshift File.expand_path('..', __FILE__)
require "tasks/release"

desc "Build gem files for all projects"
task :build => "all:build"

desc "Release all gems to gemcutter and create a tag"
C
Carl Lerche 已提交
13
task :release => "all:release"
14

C
Carlhuda 已提交
15
PROJECTS = %w(activesupport activemodel actionpack actionmailer activeresource activerecord railties)
16 17

desc 'Run all tests by default'
18
task :default => %w(test test:isolated)
19

20
%w(test test:isolated package gem).each do |task_name|
21 22
  desc "Run #{task_name} task for all projects"
  task task_name do
23
    errors = []
24
    PROJECTS.each do |project|
25
      system(%(cd #{project} && #{$0} #{task_name})) || errors << project
26
    end
27
    fail("Errors in #{errors.join(', ')}") unless errors.empty?
28 29
  end
end
J
Jeremy Kemper 已提交
30

31 32 33
desc "Smoke-test all projects"
task :smoke do
  (PROJECTS - %w(activerecord)).each do |project|
34
    system %(cd #{project} && #{$0} test:isolated)
35
  end
36
  system %(cd activerecord && #{$0} sqlite3:isolated_test)
37
end
C
Carlhuda 已提交
38

J
José Valim 已提交
39
desc "Install gems for all projects."
40
task :install => :gem do
41
  version = File.read("RAILS_VERSION").strip
42
  (PROJECTS - ["railties"]).each do |project|
C
Carlhuda 已提交
43
    puts "INSTALLING #{project}"
44
    system("gem install #{project}/pkg/#{project}-#{version}.gem --no-ri --no-rdoc")
45
  end
46 47
  system("gem install railties/pkg/railties-#{version}.gem --no-ri --no-rdoc")
  system("gem install pkg/rails-#{version}.gem --no-ri --no-rdoc")
48 49
end

J
Jeremy Kemper 已提交
50
desc "Generate documentation for the Rails framework"
A
Aaron Patterson 已提交
51
RDoc::Task.new do |rdoc|
52 53
  RDOC_MAIN = 'RDOC_MAIN.rdoc'

54 55 56 57 58 59 60 61 62 63
  # This is a hack.
  #
  # Backslashes are needed to prevent RDoc from autolinking "Rails" to the
  # documentation of the Rails module. On the other hand, as of this
  # writing README.rdoc is displayed in the front page of the project in
  # GitHub, where backslashes are shown and look weird.
  #
  # The temporary solution is to have a README.rdoc without backslashes for
  # GitHub, and gsub it to generate the main page of the API.
  #
64 65 66
  # Also, relative links in GitHub have to point to blobs, whereas in the API
  # they need to point to files.
  #
67 68 69
  # The idea for the future is to have totally different files, since the
  # API is no longer a generic entry point to Rails and deserves a
  # dedicated main page specifically thought as an API entry point.
70 71
  rdoc.before_running_rdoc do
    rdoc_main = File.read('README.rdoc')
72 73 74 75 76

    # The ^(?=\S) assertion prevents code blocks from being processed,
    # since no autolinking happens there and RDoc displays the backslash
    # otherwise.
    rdoc_main.gsub!(/^(?=\S).*?\b(?=Rails)\b/) { "#$&\\" }
77
    rdoc_main.gsub!(%r{link:/rails/rails/blob/master/(\w+)/README\.rdoc}, "link:files/\\1/README_rdoc.html")
78

79 80 81
    # Remove Travis build status image from API pages. Only GitHub README page gets this image
    rdoc_main.gsub!("http://travis-ci.org/rails/rails.png", "")

82 83 84 85 86 87 88
    File.open(RDOC_MAIN, 'w') do |f|
      f.write(rdoc_main)
    end

    rdoc.rdoc_files.include(RDOC_MAIN)
  end

J
Jeremy Kemper 已提交
89 90
  rdoc.rdoc_dir = 'doc/rdoc'
  rdoc.title    = "Ruby on Rails Documentation"
J
Jeremy Kemper 已提交
91

A
Aaron Patterson 已提交
92
  rdoc.options << '-f' << 'horo'
93
  rdoc.options << '-c' << 'utf-8'
94
  rdoc.options << '-m' << RDOC_MAIN
J
Jeremy Kemper 已提交
95 96 97

  rdoc.rdoc_files.include('railties/CHANGELOG')
  rdoc.rdoc_files.include('railties/MIT-LICENSE')
98
  rdoc.rdoc_files.include('railties/README.rdoc')
99
  rdoc.rdoc_files.include('railties/lib/**/*.rb')
100
  rdoc.rdoc_files.exclude('railties/lib/rails/generators/**/templates/**/*.rb')
J
Jeremy Kemper 已提交
101

102
  rdoc.rdoc_files.include('activerecord/README.rdoc')
J
Jeremy Kemper 已提交
103 104 105 106
  rdoc.rdoc_files.include('activerecord/CHANGELOG')
  rdoc.rdoc_files.include('activerecord/lib/active_record/**/*.rb')
  rdoc.rdoc_files.exclude('activerecord/lib/active_record/vendor/*')

107
  rdoc.rdoc_files.include('activeresource/README.rdoc')
J
Jeremy Kemper 已提交
108 109 110 111
  rdoc.rdoc_files.include('activeresource/CHANGELOG')
  rdoc.rdoc_files.include('activeresource/lib/active_resource.rb')
  rdoc.rdoc_files.include('activeresource/lib/active_resource/*')

112
  rdoc.rdoc_files.include('actionpack/README.rdoc')
J
Jeremy Kemper 已提交
113
  rdoc.rdoc_files.include('actionpack/CHANGELOG')
114
  rdoc.rdoc_files.include('actionpack/lib/abstract_controller/**/*.rb')
J
Jeremy Kemper 已提交
115
  rdoc.rdoc_files.include('actionpack/lib/action_controller/**/*.rb')
116
  rdoc.rdoc_files.include('actionpack/lib/action_dispatch/**/*.rb')
J
Jeremy Kemper 已提交
117 118 119
  rdoc.rdoc_files.include('actionpack/lib/action_view/**/*.rb')
  rdoc.rdoc_files.exclude('actionpack/lib/action_controller/vendor/*')

120
  rdoc.rdoc_files.include('actionmailer/README.rdoc')
J
Jeremy Kemper 已提交
121 122
  rdoc.rdoc_files.include('actionmailer/CHANGELOG')
  rdoc.rdoc_files.include('actionmailer/lib/action_mailer/base.rb')
123
  rdoc.rdoc_files.include('actionmailer/lib/action_mailer/mail_helper.rb')
J
Jeremy Kemper 已提交
124 125
  rdoc.rdoc_files.exclude('actionmailer/lib/action_mailer/vendor/*')

126
  rdoc.rdoc_files.include('activesupport/README.rdoc')
J
Jeremy Kemper 已提交
127 128 129
  rdoc.rdoc_files.include('activesupport/CHANGELOG')
  rdoc.rdoc_files.include('activesupport/lib/active_support/**/*.rb')
  rdoc.rdoc_files.exclude('activesupport/lib/active_support/vendor/*')
X
Xavier Noria 已提交
130

131
  rdoc.rdoc_files.include('activemodel/README.rdoc')
X
Xavier Noria 已提交
132 133
  rdoc.rdoc_files.include('activemodel/CHANGELOG')
  rdoc.rdoc_files.include('activemodel/lib/active_model/**/*.rb')
J
Jeremy Kemper 已提交
134 135 136 137
end

# Enhance rdoc task to copy referenced images also
task :rdoc do
J
Jeremy Kemper 已提交
138 139
  FileUtils.mkdir_p "doc/rdoc/files/examples/"
  FileUtils.copy "activerecord/examples/associations.png", "doc/rdoc/files/examples/associations.png"
J
Jeremy Kemper 已提交
140 141
end

142
desc 'Bump all versions to match version.rb'
143
task :update_versions do
144 145 146 147 148 149
  require File.dirname(__FILE__) + "/version"

  File.open("RAILS_VERSION", "w") do |f|
    f.write Rails::VERSION::STRING + "\n"
  end

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
  constants = {
    "activesupport"   => "ActiveSupport",
    "activemodel"     => "ActiveModel",
    "actionpack"      => "ActionPack",
    "actionmailer"    => "ActionMailer",
    "activeresource"  => "ActiveResource",
    "activerecord"    => "ActiveRecord",
    "railties"        => "Rails"
  }

  version_file = File.read("version.rb")

  PROJECTS.each do |project|
    Dir["#{project}/lib/*/version.rb"].each do |file|
      File.open(file, "w") do |f|
        f.write version_file.gsub(/Rails/, constants[project])
      end
    end
  end
end
170 171 172 173 174 175 176 177 178 179 180 181

#
# We have a webhook configured in Github that gets invoked after pushes.
# This hook triggers the following tasks:
#
#   * updates the local checkout
#   * updates Rails Contributors
#   * generates and publishes edge docs
#   * if there's a new stable tag, generates and publishes stable docs
#
# Everything is automated and you do NOT need to run this task normally.
#
S
Santiago Pastorino 已提交
182
# We publish a new version by tagging, and pushing a tag does not trigger
183 184 185 186 187 188 189 190 191 192 193
# that webhook. Stable docs would be updated by any subsequent regular
# push, but if you want that to happen right away just run this.
#
desc 'Publishes docs, run this AFTER a new stable tag has been pushed'
task :publish_docs do
  Net::HTTP.new('rails-hooks.hashref.com').start do |http|
    request  = Net::HTTP::Post.new('/rails-master-hook')
    response = http.request(request)
    puts response.body
  end
end