diff options
Diffstat (limited to 'tasks')
-rw-r--r-- | tasks/release.rb | 99 | ||||
-rw-r--r-- | tasks/release_announcement_draft.erb | 10 |
2 files changed, 92 insertions, 17 deletions
diff --git a/tasks/release.rb b/tasks/release.rb index 6ff06f3c4a..82d1fb6a68 100644 --- a/tasks/release.rb +++ b/tasks/release.rb @@ -1,6 +1,20 @@ # frozen_string_literal: true -FRAMEWORKS = %w( activesupport activemodel activerecord actionview actionpack activejob actionmailer actioncable activestorage railties ) +# Order dependent. E.g. Action Mailbox depends on Active Record so it should be after. +FRAMEWORKS = %w( + activesupport + activemodel + activerecord + actionview + actionpack + activejob + actionmailer + actioncable + activestorage + actionmailbox + actiontext + railties +) FRAMEWORK_NAMES = Hash.new { |h, k| k.split(/(?<=active|action)/).map(&:capitalize).join(" ") } root = File.expand_path("..", __dir__) @@ -89,7 +103,7 @@ npm_version = version.gsub(/\./).with_index { |s, i| i >= 2 ? "-" : s } if File.exist?("#{framework}/package.json") Dir.chdir("#{framework}") do - npm_tag = version =~ /[a-z]/ ? "pre" : "latest" + npm_tag = /[a-z]/.match?(version) ? "pre" : "latest" sh "npm publish --tag #{npm_tag}" end end @@ -105,9 +119,9 @@ namespace :changelog do current_contents = File.read(fname) header = "## Rails #{version} (#{Date.today.strftime('%B %d, %Y')}) ##\n\n" - header += "* No changes.\n\n\n" if current_contents =~ /\A##/ + header += "* No changes.\n\n\n" if current_contents.start_with?("##") contents = header + current_contents - File.open(fname, "wb") { |f| f.write contents } + File.write(fname, contents) end end @@ -118,19 +132,28 @@ namespace :changelog do fname = File.join fw, "CHANGELOG.md" contents = File.read(fname).sub(/^(## Rails .*)\n/, replace) - File.open(fname, "wb") { |f| f.write contents } + File.write(fname, contents) end end - task :release_summary do - (FRAMEWORKS + ["guides"]).each do |fw| - puts "## #{fw}" + task :release_summary, [:base_release, :release] do |_, args| + release_regexp = args[:base_release] ? Regexp.escape(args[:base_release]) : /\d+\.\d+\.\d+/ + + puts release + + FRAMEWORKS.each do |fw| + puts "## #{FRAMEWORK_NAMES[fw]}" fname = File.join fw, "CHANGELOG.md" contents = File.readlines fname contents.shift changes = [] - changes << contents.shift until contents.first =~ /^\*Rails \d+\.\d+\.\d+/ - puts changes.reject { |change| change.strip.empty? }.join + until contents.first =~ /^## Rails #{release_regexp}.*$/ || + contents.first =~ /^Please check.*for previous changes\.$/ || + contents.empty? + changes << contents.shift + end + + puts changes.join puts end end @@ -154,15 +177,58 @@ namespace :all do end task verify: :install do - app_name = "pkg/verify-#{version}-#{Time.now.to_i}" + require "tmpdir" + + cd Dir.tmpdir + app_name = "verify-#{version}-#{Time.now.to_i}" sh "rails _#{version}_ new #{app_name} --skip-bundle" # Generate with the right version. cd app_name + substitute = -> (file_name, regex, replacement) do + File.write(file_name, File.read(file_name).sub(regex, replacement)) + end + # Replace the generated gemfile entry with the exact version. - File.write("Gemfile", File.read("Gemfile").sub(/^gem 'rails.*/, "gem 'rails', '#{version}'")) + substitute.call("Gemfile", /^gem 'rails.*/, "gem 'rails', '#{version}'") + substitute.call("Gemfile", /^# gem 'image_processing/, "gem 'image_processing") sh "bundle" + sh "rails action_mailbox:install" + sh "rails action_text:install" + + sh "rails generate scaffold user name description:text admin:boolean" + sh "rails db:migrate" + + # Replace the generated gemfile entry with the exact version. + substitute.call("app/models/user.rb", /end\n\z/, <<~CODE) + has_one_attached :avatar + has_rich_text :description + end + CODE + + substitute.call("app/views/users/_form.html.erb", /text_area :description %>\n <\/div>/, <<~CODE) + rich_text_area :description %>\n </div> + + <div class="field"> + Avatar: <%= form.file_field :avatar %> + </div> + CODE + + substitute.call("app/views/users/show.html.erb", /description %>\n<\/p>/, <<~CODE) + description %>\n</p> - sh "rails generate scaffold user name admin:boolean && rails db:migrate" + <p> + <% if @user.avatar.attached? -%> + <%= image_tag @user.avatar.representation(resize_to_limit: [500, 500]) %> + <% end -%> + </p> + CODE + + # Permit the avatar param. + substitute.call("app/controllers/users_controller.rb", /:admin/, ":admin, :avatar") + + if ENV["EDITOR"] + `#{ENV["EDITOR"]} #{File.expand_path(app_name)}` + end puts "Booting a Rails server. Verify the release by:" puts @@ -247,6 +313,11 @@ task :announce do require "erb" template = File.read("../tasks/release_announcement_draft.erb") - puts ERB.new(template, nil, "<>").result(binding) + + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ + puts ERB.new(template, trim_mode: "<>").result(binding) + else + puts ERB.new(template, nil, "<>").result(binding) + end end end diff --git a/tasks/release_announcement_draft.erb b/tasks/release_announcement_draft.erb index 3dbb8c053f..4840d0b9e2 100644 --- a/tasks/release_announcement_draft.erb +++ b/tasks/release_announcement_draft.erb @@ -12,15 +12,19 @@ If you find one, please open an [issue on GitHub](https://github.com/rails/rails ## CHANGES since <%= version.previous %> To view the changes for each gem, please read the changelogs on GitHub: - <% FRAMEWORKS.sort.each do |framework| %> + <%- FRAMEWORKS.sort.each do |framework| -%> <%= "* [#{FRAMEWORK_NAMES[framework]} CHANGELOG](https://github.com/rails/rails/blob/v#{version}/#{framework}/CHANGELOG.md)" %> - <% end %> + <%- end -%> + +To see a summary of changes, please read the release on GitHub: + +<%= "[#{version} CHANGELOG](https://github.com/rails/rails/releases/tag/v#{version})" %> *Full listing* To see the full list of changes, [check out all the commits on GitHub](https://github.com/rails/rails/compare/v<%= "#{version.previous}...v#{version}" %>). - <% end %> +<% end %> ## SHA-256 If you'd like to verify that your gem is the same as the one I've uploaded, |