From 2c938108d6f2b95f6b7f4abf0fd9dda66a66d3a5 Mon Sep 17 00:00:00 2001 From: Reegan Viljoen <62689748+reeganviljoen@users.noreply.github.com> Date: Thu, 21 Nov 2024 21:58:54 +0200 Subject: [PATCH] Add rails 8 support (#2167) * add rails 8 appraisal * add rails 8 ci * fix lint * updatre gemfile * fix lint * fix specs * fix specx=cs again * fix specs * fix specs * f*** these specs already * fix lint * fix benchmarks * f*** these specs already * fix lint * fis spcs * fix ci * Update test/sandbox/test/rendering_test.rb Co-authored-by: Cameron Dutro * fix ci * fix lint * fix lint * try fix benchmark ci * Apply suggestions from code review * Update test/sandbox/test/rendering_test.rb --------- Co-authored-by: Cameron Dutro Co-authored-by: Joel Hawksley --- .github/workflows/ci.yml | 12 +++++++++-- Appraisals | 10 ++++++++++ Gemfile.lock | 8 -------- docs/CHANGELOG.md | 4 ++++ gemfiles/rails_6.1.gemfile | 1 + gemfiles/rails_7.0.gemfile | 1 + gemfiles/rails_7.1.gemfile | 1 + gemfiles/rails_7.2.gemfile | 2 ++ gemfiles/rails_8.0.gemfile | 10 ++++++++++ gemfiles/rails_main.gemfile | 1 + test/sandbox/config/application.rb | 3 ++- test/sandbox/config/initializers/assets.rb | 2 +- test/sandbox/test/rendering_test.rb | 23 +++++++++++++++------- view_component.gemspec | 1 - 14 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 gemfiles/rails_8.0.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0e94f1df..fd901df25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,8 @@ on: jobs: benchmark: runs-on: ubuntu-latest + env: + BUNDLE_GEMFILE: gemfiles/rails_8.0.gemfile steps: - uses: actions/checkout@v4.1.1 - name: Setup Ruby @@ -18,8 +20,8 @@ jobs: bundler-cache: true - name: Run benchmarks run: | - bundle exec rake partial_benchmark - bundle exec rake translatable_benchmark + bundle exec appraisal rails-8.0 rake partial_benchmark + bundle exec appraisal rails-8.0 rake translatable_benchmark test: name: test (${{ matrix.rails_version }}, ${{ matrix.ruby_version }}, ${{ matrix.mode }}) runs-on: ubuntu-latest @@ -51,6 +53,12 @@ jobs: - ruby_version: "3.3" rails_version: "7.2" mode: "capture_patch_enabled" + - ruby_version: "3.3" + rails_version: "8.0" + mode: "capture_patch_disabled" + - ruby_version: "3.3" + rails_version: "8.0" + mode: "capture_patch_enabled" - ruby_version: "head" rails_version: "main" mode: "capture_patch_disabled" diff --git a/Appraisals b/Appraisals index 97a25f8e0..b89853039 100644 --- a/Appraisals +++ b/Appraisals @@ -3,6 +3,7 @@ appraise "rails-6.1" do gem "rails", "~> 6.1" gem "tailwindcss-rails", "~> 2.0" + gem "sprockets-rails", "~> 3.4.2" # Required for Ruby 3.1.0 gem "net-smtp", require: false @@ -15,17 +16,26 @@ appraise "rails-7.0" do gem "rails", "~> 7.0" gem "tailwindcss-rails", "~> 2.0" gem "turbo-rails", "~> 1" + gem "sprockets-rails", "~> 3.4.2" end appraise "rails-7.1" do gem "rails", "~> 7.1" gem "tailwindcss-rails", "~> 2.0" gem "turbo-rails", "~> 1" + gem "sprockets-rails", "~> 3.4.2" end appraise "rails-7.2" do gem "rails", "~> 7.2" gem "tailwindcss-rails", "~> 2.0" + gem "sprockets-rails", "~> 3.4.2" +end + +appraise "rails-8.0" do + gem "rails", "~> 8.0" + gem "tailwindcss-rails", "~> 2.0" + gem "propshaft", "~> 1.1.0" end appraise "rails-main" do diff --git a/Gemfile.lock b/Gemfile.lock index b70346e73..776cd76aa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -284,13 +284,6 @@ GEM temple (~> 0.10.0) tilt (>= 2.1.0) smart_properties (1.17.0) - sprockets (4.2.1) - concurrent-ruby (~> 1.0) - rack (>= 2.2.4, < 4) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) standard (1.41.1) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) @@ -364,7 +357,6 @@ DEPENDENCIES simplecov (~> 0.22.0) simplecov-console (~> 0.9.1) slim (~> 5.1) - sprockets-rails (~> 3.4.2) standard (~> 1) turbo-rails (~> 1) view_component! diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2f552937f..909950f3f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -22,6 +22,10 @@ nav_order: 5 *Reegan Viljoen* +* Add rails 8 support to CI. + + *Reegan Viljoen* + ## 3.20.0 * Allow rendering `with_collection` to accept an optional `spacer_component` to be rendered between each item. diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index d78c28030..184a53ffa 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -8,5 +8,6 @@ gem "net-smtp", require: false gem "net-imap", require: false gem "net-pop", require: false gem "turbo-rails", "~> 1" +gem "sprockets-rails", "~> 3.4.2" gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index a703d2cc6..da308880c 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -5,5 +5,6 @@ source "https://rubygems.org" gem "rails", "~> 7.0" gem "tailwindcss-rails", "~> 2.0" gem "turbo-rails", "~> 1" +gem "sprockets-rails", "~> 3.4.2" gemspec path: "../" diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile index 105811883..a6a5d6021 100644 --- a/gemfiles/rails_7.1.gemfile +++ b/gemfiles/rails_7.1.gemfile @@ -5,5 +5,6 @@ source "https://rubygems.org" gem "rails", "~> 7.1" gem "tailwindcss-rails", "~> 2.0" gem "turbo-rails", "~> 1" +gem "sprockets-rails", "~> 3.4.2" gemspec path: "../" diff --git a/gemfiles/rails_7.2.gemfile b/gemfiles/rails_7.2.gemfile index b7eadcc95..840b6a532 100644 --- a/gemfiles/rails_7.2.gemfile +++ b/gemfiles/rails_7.2.gemfile @@ -12,6 +12,8 @@ gem "debug" gem "tailwindcss-rails", "~> 2.0" +gem "sprockets-rails", "~> 3.4.2" + group :test do gem "cuprite", "~> 0.15" gem "puma", "~> 6" diff --git a/gemfiles/rails_8.0.gemfile b/gemfiles/rails_8.0.gemfile new file mode 100644 index 000000000..6280d60ba --- /dev/null +++ b/gemfiles/rails_8.0.gemfile @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 8.0" +gem "tailwindcss-rails", "~> 2.0" +gem "turbo-rails", "~> 1" +gem "propshaft", "~> 1.1.0" + +gemspec path: "../" diff --git a/gemfiles/rails_main.gemfile b/gemfiles/rails_main.gemfile index 7a2bff157..5c92f2cf5 100644 --- a/gemfiles/rails_main.gemfile +++ b/gemfiles/rails_main.gemfile @@ -5,5 +5,6 @@ source "https://rubygems.org" gem "rails", github: "rails/rails", branch: "main" gem "tailwindcss-rails", "~> 2.0" gem "turbo-rails", "~> 1" +gem "propshaft", "~> 1.1.0" gemspec path: "../" diff --git a/test/sandbox/config/application.rb b/test/sandbox/config/application.rb index a23c1fba6..a92e48278 100644 --- a/test/sandbox/config/application.rb +++ b/test/sandbox/config/application.rb @@ -7,7 +7,8 @@ require "action_controller/railtie" require "action_mailer/railtie" require "action_view/railtie" -require "sprockets/railtie" +require "sprockets/railtie" if Rails.version.to_f < 8.0 +require "propshaft" if Rails.version.to_f >= 8.0 require "turbo-rails" diff --git a/test/sandbox/config/initializers/assets.rb b/test/sandbox/config/initializers/assets.rb index 8b7b89611..5b2fa7a75 100644 --- a/test/sandbox/config/initializers/assets.rb +++ b/test/sandbox/config/initializers/assets.rb @@ -1,3 +1,3 @@ # frozen_string_literal: true -Rails.application.config.assets.precompile += %w[admin.css] +Rails.application.config.assets.precompile += %w[admin.css] if Rails.version.to_f <= 7.2 diff --git a/test/sandbox/test/rendering_test.rb b/test/sandbox/test/rendering_test.rb index bd39865b7..95854912f 100644 --- a/test/sandbox/test/rendering_test.rb +++ b/test/sandbox/test/rendering_test.rb @@ -15,7 +15,11 @@ def test_render_inline_allocations ViewComponent::CompileCache.cache.delete(MyComponent) MyComponent.ensure_compiled - assert_allocations("3.4.0" => 109, "3.3.6" => 115, "3.3.0" => 127, "3.2.6" => 114, "3.1.6" => 114, "3.0.7" => 123) do + allocations = (Rails.version.to_f >= 8.0) ? + {"3.4.0" => 109, "3.3.6" => 124, "3.3.0" => 127, "3.2.6" => 114, "3.1.6" => 114, "3.0.7" => 123} : + {"3.4.0" => 109, "3.3.6" => 115, "3.3.0" => 127, "3.2.6" => 114, "3.1.6" => 114, "3.0.7" => 123} + + assert_allocations(**allocations) do render_inline(MyComponent.new) end @@ -332,14 +336,19 @@ def test_renders_component_with_asset_url component = AssetComponent.new assert_match(%r{http://assets.example.com/assets/application-\w+.css}, render_inline(component).text) - component.config.asset_host = nil - assert_match(%r{/assets/application-\w+.css}, render_inline(component).text) + if Rails.version.to_f < 8.0 - component.config.asset_host = "http://assets.example.com" - assert_match(%r{http://assets.example.com/assets/application-\w+.css}, render_inline(component).text) + # Propshaft doesn't allow setting custom hosts so this only works in Rails < 8 + # TODO: Revisit this comment for v4 to see if we need to make any deprecations + component.config.asset_host = nil + assert_match(%r{/assets/application-\w+.css}, render_inline(component).text) - component.config.asset_host = "assets.example.com" - assert_match(%r{http://assets.example.com/assets/application-\w+.css}, render_inline(component).text) + component.config.asset_host = "http://assets.example.com" + assert_match(%r{http://assets.example.com/assets/application-\w+.css}, render_inline(component).text) + + component.config.asset_host = "assets.example.com" + assert_match(%r{http://assets.example.com/assets/application-\w+.css}, render_inline(component).text) + end end def test_template_changes_are_not_reflected_if_cache_is_not_cleared diff --git a/view_component.gemspec b/view_component.gemspec index 711abf550..8b693635a 100644 --- a/view_component.gemspec +++ b/view_component.gemspec @@ -55,7 +55,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "simplecov", "~> 0.22.0" spec.add_development_dependency "simplecov-console", "~> 0.9.1" spec.add_development_dependency "slim", "~> 5.1" - spec.add_development_dependency "sprockets-rails", "~> 3.4.2" spec.add_development_dependency "turbo-rails", "~> 1" spec.add_development_dependency "warning" spec.add_development_dependency "yard", "~> 0.9.34"