Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Rails 7 and Ruby 3 #1106

Merged
merged 1 commit into from
Jan 13, 2023
Merged

Support Rails 7 and Ruby 3 #1106

merged 1 commit into from
Jan 13, 2023

Conversation

stevepolitodesign
Copy link
Contributor

@stevepolitodesign stevepolitodesign commented Aug 20, 2022

🚀 Support Rails 7 and Ruby 3

This is a major upgrade that aims to make it so generated Rails applications with suspenders are running on Rails version 7 and Ruby version 3. We took the approach of making the least amount of changes possible.

Special thanks to @emilford, @stefannibrasil and @DoodlingDev for their help!

🏗 What changed?

❓What next?

  1. We'll keep this pull-request open long enough to capture initial feedback. Feel free to add a to-do to the list below.
  2. Once approved, we'll squash everything down into a single commit, since all these changes are related and can't easily be grouped.
  3. Bump the version and update the README.

🙏 How to contribute and review

This helps us determine if suspenders is generating an error free application.

  1. Checkout the support_rails_7 branch.
  2. Once you are in the suspenders directory, run ./bin/suspenders some_app_name to generate a Rails app from the current state of suspenders.
  3. Change directories into some_app_name.
  4. Run rails g scaffold some_model some_attribute followed by rails db:migrate.
  5. Run rails s

Open up the app and ensure that it is loaded correctly. Try filing out the forms generated from the scaffold. If you run into an error, please follow the steps below.

  1. Open a new issue.
  2. Tag it as Rails 7
  3. Add it to the to-do section below.

✅ To-do

@stevepolitodesign stevepolitodesign self-assigned this Aug 20, 2022
@DoodlingDev
Copy link
Contributor

DoodlingDev commented Nov 4, 2022

I think for sure ruby 3, can't let the underlying runtime stagnate.

Generally I'd expect something like suspenders to have strong default opinions, with options if a project needs to deviate.

So probably... import maps? option for esbuild, option for typescript? webpacker's deprecated, and if we're moving to rails 7 it's not getting more attention than security issues.

@stevehanson
Copy link

Thanks for getting this started! I feel like Suspenders being outdated is a big barrier for usage, so I lean toward finding simple solutions now to get Suspenders back up-to-date before spending too much time tackling larger decisions. With that in mind, what is the simplest path toward Rails 7 support?

Which JS engine is simplest to support for the sake of this PR? Rails defaults to importmap as the JavaScript engine but the rails new command allows passing a --javascript option, which can be one of importmap (default), webpack, esbuild, rollup. It'd be nice if Suspenders could support options like this eventually, since individual app requirements might make one option better than others in certain scenarios, though that's probably outside the scope of this PR.

Would it make sense to default to import maps for now just to match Rails? Then we can revisit this in a separate issue/PR? If apps need to use esbuild, it should be simple enough for now to follow the installation steps after initializing the app.

I agree on defaulting to Ruby 3.

@thiagoa
Copy link
Contributor

thiagoa commented Nov 7, 2022

I agree with @stevehanson that we should follow the path of least resistance to get this upgrade working. We could tackle the bigger decisions later. Maybe it would make sense to default to Webpack for some backward compatibility and avoid more drastic changes?

As a future default, I vote on Hotwire/importmaps, and on updating the "API" option with newer defaults for React/Rails projects.

@stevepolitodesign
Copy link
Contributor Author

I was able to get a passing test suite when upgrading to Ruby 3.0.0, but CI fails on 3.1.2.

I wonder if we just support 3.0.0 for how, and add support for the latest version later? I didn't have too much time to dig into this, but I think the error is related to the version of bundler and/or gems we're using.

@stefannibrasil
Copy link
Contributor

Just a heads up:

/Users/stefannibrasil/.asdf/installs/ruby/3.0.0/lib/ruby/3.0.0/rubygems/dependency.rb:307:in `to_specs': Could not find 'rails' (~> 7.0.0) among 85 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/Users/stefannibrasil/.gem/ruby/3.0.0:/Users/stefannibrasil/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0' , execute `gem env` for more information
	from /Users/stefannibrasil/.asdf/installs/ruby/3.0.0/lib/ruby/3.0.0/rubygems/dependency.rb:319:in `to_spec'
	from /Users/stefannibrasil/.asdf/installs/ruby/3.0.0/lib/ruby/3.0.0/rubygems/specification.rb:974:in `find_by_name'

I then remembered I probably didn't have Rails 7 installed locally. After running bundle install, I was able to generate a Rails 7 app with suspenders.

.ruby-version Outdated Show resolved Hide resolved
Copy link
Contributor Author

@stevepolitodesign stevepolitodesign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few things to consider.

lib/suspenders/generators/app_generator.rb Show resolved Hide resolved
lib/suspenders/version.rb Show resolved Hide resolved
@stevepolitodesign
Copy link
Contributor Author

We'll need to bump the Gem version. Is this a good opportunity to bump to v2?

suspenders.gemspec Outdated Show resolved Hide resolved
@stevepolitodesign stevepolitodesign marked this pull request as ready for review December 15, 2022 20:46
@stevepolitodesign
Copy link
Contributor Author

I think we can remove this line

generate("suspenders:stylesheet_base") unless options[:api]

Copy link
Contributor

@stefannibrasil stefannibrasil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alt Text

@mike-burns
Copy link
Contributor

We'll need to bump the Gem version. Is this a good opportunity to bump to v2?

Is that a good time to move to calver instead of semver?

Since this project is a compilation of other projects, every release is a potential breaking change. Therefore, something like calver might make more sense.

@stevepolitodesign
Copy link
Contributor Author

We'll need to bump the Gem version. Is this a good opportunity to bump to v2?

Is that a good time to move to calver instead of semver?

Since this project is a compilation of other projects, every release is a potential breaking change. Therefore, something like calver might make more sense.

@mike-burns I'm open to this if you think it's a good recommendation. If we go with this approach, do we need to add any additional documentation noting the change in semantics?

@mike-burns
Copy link
Contributor

If we go with this approach, do we need to add any additional documentation noting the change in semantics?

It should transparently work for current users, but it might be worth announcing via the blog.

@stevepolitodesign
Copy link
Contributor Author

@mike-burns how would I use CalVar to version this latest release? If we were to release on January 13, 2023 would I simply version it as 23.01.13?

@mike-burns
Copy link
Contributor

Personally I'd version it as 20230113. If anyone asks, that's the major, and the minor and patch are 0.

@stevepolitodesign stevepolitodesign force-pushed the support_rails_7 branch 2 times, most recently from 83a6896 to b7cbcde Compare January 13, 2023 14:36
RUBY_VERSION = IO
.read("#{File.dirname(__FILE__)}/../../.ruby-version")
.strip
.freeze
VERSION = "1.56.1".freeze
VERSION = "20230113".freeze
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mike-burns this good?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. Honestly I haven't tried calver in a Ruby gem yet so I don't know what it'll do. But I hope this will work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting, we opted for yyymmdd.minor_version to account for cases where we needed to release patches on the same day.

@stevepolitodesign stevepolitodesign changed the title Support Rails 7 Support Rails 7 and Ruby 3 Jan 13, 2023
This is a major upgrade that aims to make it so generated Rails
applications with suspenders are running on Rails version 7 and Ruby
version 3. We took the approach of making the least amount of changes
possible.

We were unable to support the latest version of Ruby because of a
[failing build][]. A future commit could explore how to solve for this,
but for now, we decided to just stick with version `3.0.5`. We settled
on `3.0.5` and not `3.0.0` in an effort to suppress parser warnings.

The biggest change is that we drop support for deprecated CSS tooling by
removing [Bourbon][] and introduce [PostCSS][] and
[cssbundling-rails][]. We also drop [Bitters][] as a runtime dependency.

Add PostCSS Normalize
---------------------

In order to use [normalize][], we need to use [PostCSS Normalize][]
since we are using [cssbundling-rails][].

We need to move the invocation of the `suspenders:stylesheet_base`
to the `leftovers` method because this method is invoked _after_
`finish_template` is called. We do this because we were running into
issues where the call to `rails css:install:postcss` had not yet run,
but our generator assumes that command has already run. The method must
be named `leftovers` since that's what the [finish_template][] method
expects.

Additionally, we only call this generator if the caller has not
passed anything to the `--css` option when generating a new app. This is
because Rails handles other css frameworks like `bootstrap` and
`tailwind` differently.

Finally, we move the invocation of `outro` to the `leftovers` method
since it ensures the message will be the last thing to be printed to the
console.

Add bin/yarn
------------

Now that we have moved off of [Webpacker][], the [bin/yarn][] binstub is
no longer generated. Because of this, we need to manually have it added
during a new app build.

Introduce CalVer
----------------

Because this upgrade was a breaking change, we thought it was a good
time to switch to [CalVer][]. Since this project is composed of other
projects, every release is a potential breaking change. Using the date
as the `major` version encodes this risk.

Improve console output
----------------------

Ensures the invocation of all generator methods happens _before_ we
print the outro. This is because a generator invokes all methods in the
class in the order they are declared. Specifically, this meant invoking
`generate_views` in the `suspenders_customization` method. Prior to
this, `generate_views` was invoked after the `outro` was printed.

[Webpacker]: https://github.com/rails/webpacker
[failing build]: https://github.com/thoughtbot/suspenders/actions/runs/3418310707
[Bourbon]: https://github.com/thoughtbot/bourbon
[PostCSS]: https://postcss.org
[cssbundling-rails]: https://github.com/rails/cssbundling-rails
[Bitters]: https://github.com/thoughtbot/bitters
[normalize]: https://necolas.github.io/normalize.css/
[PostCSS Normalize]: https://github.com/csstools/postcss-normalize
[finish_template]: https://github.com/rails/rails/blob/d5124b2522130785378238ba714029ce8ef9de97/railties/lib/rails/generators/rails/plugin/plugin_generator.rb#L283-L285
[bin/yarn]: https://github.com/rails/webpacker/blob/master/lib/install/bin/yarn
[CalVer]: https://calver.org

Co-authored-by: Aji Slater <aji@thoughtbot.com>
Co-authored-by: Eric Milford <ericmilford@gmail.com>
Co-authored-by: Stefanni Brasil <stefanni@thoughtbot.com>
@stevepolitodesign stevepolitodesign merged commit 1712f3e into main Jan 13, 2023
@stevepolitodesign stevepolitodesign deleted the support_rails_7 branch January 13, 2023 18:55
@stevepolitodesign stevepolitodesign mentioned this pull request Mar 31, 2023
stevepolitodesign added a commit that referenced this pull request May 16, 2024
With the merge of #1135 and some subsequent follow-ups, we are ready to
officially release the next version of Suspenders.

Because we moved to [calver][] in #1106, we need to continue using
calver, since the latest release `20230113.0` is greater than `3.0.0`,
which was set in haste in ab3eb97

In an effort to better brand this release, we give it the code name
"Tailored".

[calver]: https://calver.org
stevepolitodesign added a commit that referenced this pull request May 16, 2024
With the merge of #1135 and some subsequent follow-ups, we are ready to
officially release the next version of Suspenders.

Because we moved to [calver][] in #1106, we need to continue using
calver, since the latest release `20230113.0` is greater than `3.0.0`,
which was set in haste in ab3eb97

In an effort to better brand this release, we give it the code name
"Tailored".

[calver]: https://calver.org
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants