From b2b6a9981c1a3c135aa62ce3a6607db34fd65816 Mon Sep 17 00:00:00 2001 From: Richard Schneeman Date: Mon, 3 Jan 2022 12:50:33 -0600 Subject: [PATCH 1/3] Test Rails 7 app against Heroku CI Added a test for Rails 7 to exercise behavior in https://github.com/heroku/heroku-buildpack-ruby/issues/1254. Update the Rails 7 example app to use the released version instead of alpha. Also update the app to be Heroku CI compat app (adds app.json): - https://github.com/sharpstone/rails-jsbundling/commit/34bd25cef7c09758b3e7763a5d4be6dc94364606 - https://github.com/sharpstone/rails-jsbundling/commit/a98a4e41708b48a36a0adb941df4b7d28d25d5d5 - https://github.com/sharpstone/rails-jsbundling/commit/b4ec664cbe63dd9176884f746f64a46bed879c21 - https://github.com/sharpstone/rails-jsbundling/commit/1fb48b40bf506fbc3fb7c00a67e8f98dce82ac07 Add CI tests against Rails 7 --- hatchet.lock | 2 +- spec/hatchet/rails7_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/hatchet.lock b/hatchet.lock index f91a969da..2efac12d7 100644 --- a/hatchet.lock +++ b/hatchet.lock @@ -46,7 +46,7 @@ - - "./repos/rails_versions/active_storage_non_local" - 86dddf0127043abba1cb2890590a1d38f111edbd - - "./repos/rails_versions/rails-jsbundling" - - 192a71e0931aa00724412521dcad4d1e1db2ec0f + - 34bd25cef7c09758b3e7763a5d4be6dc94364606 - - "./repos/rails_versions/rails3_default_ruby" - a6b44db674c0d3538633989295e2cfd5e8e1ba0d - - "./repos/rails_versions/rails42_default_ruby" diff --git a/spec/hatchet/rails7_spec.rb b/spec/hatchet/rails7_spec.rb index fdce28447..af9da0d6a 100644 --- a/spec/hatchet/rails7_spec.rb +++ b/spec/hatchet/rails7_spec.rb @@ -16,4 +16,11 @@ end end end + + it "Works on Heroku CI" do + Hatchet::Runner.new("rails-jsbundling").run_ci do |test_run| + expect(test_run.output).to match("db:schema:load") + expect(test_run.output).to match("db:migrate") + end + end end From 5cd2c55d380048cd804e57c8ba593cc2693fd13c Mon Sep 17 00:00:00 2001 From: Richard Schneeman Date: Mon, 3 Jan 2022 16:09:39 -0600 Subject: [PATCH 2/3] Specialize Rails7 Database setup In Rails 6.1 the tasks used for database setup in our test pack were deprecated. They were removed in Rails 7 https://edgeguides.rubyonrails.org/7_0_release_notes.html. This commit moves to specialize the tasks for Rails7+ to use `db:schema:load` per deprecation instruction: ``` DEPRECATION WARNING: Using `bin/rails db:schema:load_if_ruby` is deprecated and will be removed in Rails 7.0. Configure the format using `config.active_record.schema_format = :ruby` to use `schema.rb` and run `bin/rails db:schema:load` instead. (called from
at /app/bin/rake:4) ``` --- CHANGELOG.md | 2 ++ lib/language_pack/test.rb | 3 +++ lib/language_pack/test/rails2.rb | 4 ++-- lib/language_pack/test/rails7.rb | 9 +++++++++ lib/language_pack/test/ruby.rb | 7 +++++-- 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 lib/language_pack/test/rails7.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fe471561..8d4101b48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Main (unreleased) +* Fix deprecated rake tasks for Rails 7 on Heroku CI (https://github.com/heroku/heroku-buildpack-ruby/pull/1257) + ## v235 (2022/01/03) * Bundler 2.x is now 2.2.33 (https://github.com/heroku/heroku-buildpack-ruby/pull/1248) diff --git a/lib/language_pack/test.rb b/lib/language_pack/test.rb index fc52af6d4..0f8f7eb07 100644 --- a/lib/language_pack/test.rb +++ b/lib/language_pack/test.rb @@ -3,5 +3,8 @@ module LanguagePack::Test end +# Behavior changes for the test pack work by opening existing language_pack +# classes and over-writing their behavior to extend test functionality require "language_pack/test/ruby" require "language_pack/test/rails2" +require "language_pack/test/rails7" diff --git a/lib/language_pack/test/rails2.rb b/lib/language_pack/test/rails2.rb index 71e2fa766..24d6323e9 100644 --- a/lib/language_pack/test/rails2.rb +++ b/lib/language_pack/test/rails2.rb @@ -1,4 +1,5 @@ -#module LanguagePack::Test::Rails2 +# Opens up the class of the Rails2 language pack and +# overwrites methods defined in `language_pack/test/ruby.rb` class LanguagePack::Rails2 # sets up the profile.d script for this buildpack def setup_profiled(ruby_layer_path: , gem_layer_path: ) @@ -51,7 +52,6 @@ def clear_db_test_tasks end end - private def db_prepare_test_rake_tasks schema_load = rake.task("db:schema:load_if_ruby") structure_load = rake.task("db:structure:load_if_sql") diff --git a/lib/language_pack/test/rails7.rb b/lib/language_pack/test/rails7.rb new file mode 100644 index 000000000..3af3c5010 --- /dev/null +++ b/lib/language_pack/test/rails7.rb @@ -0,0 +1,9 @@ +# Opens up the class of the Rails7 language pack and +# overwrites methods defined in `language_pack/test/ruby.rb` or `language_pack/test/rails2.rb` +class LanguagePack::Rails7 + # Rails removed the db:schema:load_if_ruby and `db:structure:load_if_sql` tasks + # they've been replaced by `db:schema:load` instead + def db_prepare_test_rake_tasks + ["db:schema:load", "db:migrate"].map {|name| rake.task(name) } + end +end diff --git a/lib/language_pack/test/ruby.rb b/lib/language_pack/test/ruby.rb index f1421112d..43498d67e 100644 --- a/lib/language_pack/test/ruby.rb +++ b/lib/language_pack/test/ruby.rb @@ -1,4 +1,8 @@ -#module LanguagePack::Test::Ruby +# Opens up the class of the Ruby language pack and +# overwrites methods defined in `language_pack/ruby.rb` +# +# Other "test packs" futher extend this behavior by hooking into +# methods or over writing methods defined here. class LanguagePack::Ruby def compile new_app? @@ -26,7 +30,6 @@ def compile super end - private def db_prepare_test_rake_tasks ["db:schema:load", "db:migrate"].map {|name| rake.task(name) } end From 1c518d7eaeecf4eaa530af80bdb55abf3fdb6571 Mon Sep 17 00:00:00 2001 From: Richard Schneeman Date: Tue, 4 Jan 2022 14:19:54 -0600 Subject: [PATCH 3/3] v236 --- CHANGELOG.md | 2 ++ Rakefile | 5 +++++ lib/language_pack/version.rb | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d4101b48..d23666615 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Main (unreleased) +## v236 (2022/01/04) + * Fix deprecated rake tasks for Rails 7 on Heroku CI (https://github.com/heroku/heroku-buildpack-ruby/pull/1257) ## v235 (2022/01/03) diff --git a/Rakefile b/Rakefile index 5eef001af..a9352ceaa 100644 --- a/Rakefile +++ b/Rakefile @@ -95,6 +95,11 @@ namespace :buildpack do changelog_md.write(contents.gsub("## Main (unreleased)", new_section)) end + + version_rb = Pathname(__dir__).join("lib/language_pack/version.rb") + puts "Updating version.rb" + contents = version_rb.read.gsub(/BUILDPACK_VERSION = .*$/, %Q{BUILDPACK_VERSION = "#{deploy.next_version.to_s}"}) + version_rb.write(contents) end desc "releases the next version of the buildpack" diff --git a/lib/language_pack/version.rb b/lib/language_pack/version.rb index 4eb00c7ba..242186dc9 100644 --- a/lib/language_pack/version.rb +++ b/lib/language_pack/version.rb @@ -2,6 +2,6 @@ module LanguagePack class LanguagePack::Base - BUILDPACK_VERSION = "v234" + BUILDPACK_VERSION = "v236" end end