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

Frontend installers with app-templates #4629

Merged
merged 12 commits into from
Sep 23, 2022

Conversation

elia
Copy link
Member

@elia elia commented Sep 15, 2022

Summary

This change makes it trivial to add/remove/change frontend or to pass a custom template to be used. This among other use-cases can become handy for testing out branches of solidus_starter_frontend without touching the code of the installer.

  • It's closer to what you would expect coming from rails new options.
  • --frontend=none was fixed and now properly removes solidus_frontend.
  • The bundler splitter was compacted into a single file and always adds solidus_frontend leaving the choice to other templates if to keep it.
  • A job testing the installer has been added to the CI

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

  • I have written a thorough PR description.
  • I have kept my commits small and atomic.
  • I have used clear, explanatory commit messages.

The following are not always needed (cross them out if they are not):

  • I have added automated tests to cover my changes.
  • I have attached screenshots to demo visual changes.
  • I have opened a PR to update the guides.
  • I have updated the readme to account for my changes.

@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Sep 15, 2022
@elia elia force-pushed the elia/frontend-templates branch 4 times, most recently from 21cacdb to 7271b2c Compare September 15, 2022 16:40
Copy link
Contributor

@forkata forkata left a comment

Choose a reason for hiding this comment

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

Nice work here @elia! This is probably not in scope for this PR, but I am curious if we have plans to enable similar behaviour for the dummy app generator as well. We've run into some challenges adding the solidus_starter_frontend to a dummy app (for extension testing) post generation due to the fact that there is no Gemfile.

@elia elia force-pushed the elia/frontend-templates branch 4 times, most recently from 0b5136f to bee4078 Compare September 16, 2022 15:24
@elia
Copy link
Member Author

elia commented Sep 16, 2022

@forkata that's a good point, can you please help give me the ropes on how to replicate that issue?

(on the same topic I'm also experimenting with using app-templates for more stuff in the installer and for turning some extensions into a sort of recipes, I'll send another PR for that if I end up with something viable)

@elia elia marked this pull request as ready for review September 16, 2022 16:45
bin/sandbox Outdated
@@ -3,6 +3,10 @@
# Used in the sandbox rake task in Rakefile

set -e
if [ ! -z $DEBUG ]
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but I think it won't catch when $DEBUG is set to the empty string:

> [ ! -z '' ]
> echo $?
1

I've usually seen to check for the presence of an env variable is if [ -z ${var+x} ], which returns false if the variable is set to the empty string or any other string.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's ok to assume it will have some contents when set, that said maybe I'm doing some bash mistake here:

solidus:elia/frontend-templates ⤑ bash -l -c 'DEBUGz="asdf" test -z ${DEBUG+x}; echo $?'
0
solidus:elia/frontend-templates ⤑ bash -l -c 'DEBUG="asdf" test -z ${DEBUG+x}; echo $?'
0
solidus:elia/frontend-templates ⤑ bash -l -c 'DEBUG="" test -z ${DEBUG+x}; echo $?'
0

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the parameter expansion is evaluated before the command, so $DEBUG is never defined at that point. But if you run it as part of a script, it'll work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the explanation, let me know if you would still prefer to support an empty string there

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 it makes sense to support them. I know the code looks weirder, but it's not our fault that bash is bizarre 😄 Up to you! 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! TIL 🙏

bin/sandbox Outdated Show resolved Hide resolved

# `solidus_frontend` is not sourced from rubygems if the solidus gem was not.
github_solidus_frontend = '--github solidusio/solidus_frontend' unless solidus.source.is_a? Bundler::Source::Rubygems
bundle_command("add solidus_frontend --skip-install #{github_solidus_frontend}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of adding and later removing, why not add only when solidus_frontend is chosen? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

This way we have a common baseline that is supposedly equivalent to the original but with exploded list of components, up to the scripts that don't require solidus_frontend to remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Given that is the component we want to deprecate and that I wouldn't say undoing an action (or definition of action) is a good pattern for expansion, I would still have it only where it's needed. But not a blocker. I'll be fine with whatever you decide 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, now the starter_frontend just adds the gem, and the break-down recipe doesn't do that anymore.

solidus
])

# `solidus_frontend` is not sourced from rubygems if the solidus gem was not.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I get it. Could you explain it to me? 🙏

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is that if you have added solidus from rubygems you want to take the latest compatible solidus_frontend from rubygems as well.

On the contrary if you added it from git/github/path then it's better if we add it from GitHub as well.

You think it's fine to always get it from Rubygems?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, yeah, it makes sense.

However, we should skip adding it when it's already in the Gemfile, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding solidus_frontend was removed from this app-template.

Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks for working on it, @elia! There are very nice improvements here.

However, I think something is wrong when installing solidus_starter_frontend, as when I go to http:https://localhost:3000 I see Rails' welcome page instead. It's quite possible the error is on solidus_starter_frontend's side, but we need to investigate it.

I see the benefits of using rails templates for the frontend installers, but I'm afraid we lose proper encapsulation in this way. For instance, we're now duplicating how we check for gems being present in the Gemfile and, more importantly, we no longer respect --auto-accept when delegating to the solidus_frontend installer. What do you think about it?

@waiting-for-dev waiting-for-dev requested a review from a team September 19, 2022 05:26
@elia elia force-pushed the elia/frontend-templates branch 2 times, most recently from f4c69f0 to 29fc8f4 Compare September 19, 2022 09:24
@elia
Copy link
Member Author

elia commented Sep 19, 2022

Thanks for the review @waiting-for-dev 🙏

I solved the the issue with the welcome page, it was applying the engine route to the Core routes block that is prepended by the SSF. I added running of the sandbox specs in the solidus-installer CI job, still a sort of smoke test but should be able to catch similar errors in the future.

Also now it forwards both --auto-accept (from options[:auto_accept]) and --auto-run-migrations (from options[:migrate]).

Use `bundle info [gemname]` to see where a bundled gem is installed.
    generate    solidus_frontend:install
       rails    generate solidus_frontend:install --auto-accept --auto-run-migrations
      create  config/initializers/solidus_frontend.rb

@elia elia force-pushed the elia/frontend-templates branch 2 times, most recently from ab01d1e to e91118b Compare September 19, 2022 10:47
@elia elia marked this pull request as draft September 19, 2022 11:51
command: |
cd /tmp/my_app
bundle add solidus --git "file:https://$(ruby -e"puts File.expand_path ENV['CIRCLE_WORKING_DIRECTORY']")"
export SKIP_SOLIDUS_BOLT='true' # workaround for solidus_frontend not respecting --auto-accept when asking about bolt
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we're respecting --auto-accept, we can:

  • Remove the comment and keep skipping solidus_bolt.
  • Remove the line and install solidus_bolt.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opted for removing the line altogether, we should test things as close as possible to the final usage

Tried removing the line, but fails with this error, somehow I think bundle_cleanly in the solidus_frontend gem has a bad interaction with the main script, so I'm adding it back, but updating the comment.

Using solidus 3.3.0.alpha from file:https:///home/circleci/solidus (at elia/frontend-templates@34468ee)
    generate    solidus_frontend:install
       rails    generate solidus_frontend:install --auto-accept --auto-run-migrations
      create  config/initializers/solidus_frontend.rb
       exist  app/assets/images
      create  vendor/assets/javascripts/spree/frontend
      create  vendor/assets/stylesheets/spree/frontend
      create  vendor/assets/images/spree/frontend
      create  vendor/assets/javascripts/spree/frontend/all.js
      create  vendor/assets/stylesheets/spree/frontend/all.css
     gemfile  solidus_bolt
    generate  solidus_bolt:install --auto-run-migrations
       rails  generate solidus_bolt:install --auto-run-migrations 
Could not find solidus_bolt-0.7.2, coffee-rails-5.0.0, httparty-0.20.0, multi_json-1.15.0, omniauth-bolt-0.3.0, solidus_social-1.5.0, tweetnacl-1.0.0, coffee-script-2.4.1, multi_xml-0.6.0, omniauth-oauth-1.2.0, oa-core-0.3.2, omniauth-2.1.0, omniauth-facebook-9.0.0, omniauth-github-2.0.0, omniauth-google-oauth2-0.8.0, omniauth-rails_csrf_protection-1.0.1, coffee-script-source-1.12.2, oauth-1.1.0, hashie-5.0.0, rack-protection-2.2.2, omniauth-oauth2-1.7.3, jwt-2.5.0, oauth-tty-1.0.5, snaky_hash-2.0.0, version_gem-1.1.1, oauth2-2.0.9, faraday-2.5.2, faraday-net_http-3.0.0, ruby2_keywords-0.0.5 in any of the sources
Run `bundle install` to install missing gems.

Exited with code exit status 1

https://app.circleci.com/pipelines/github/nebulab/solidus/391/workflows/05b8d862-a54b-4c2d-a00e-ce9304e8c7fe/jobs/4875

@elia elia force-pushed the elia/frontend-templates branch 5 times, most recently from 34468ee to 3caefd0 Compare September 21, 2022 14:29
Copy link
Member Author

@elia elia left a comment

Choose a reason for hiding this comment

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

@waiting-for-dev thanks for the reviews, I should have addressed everything 🙏

command: |
cd /tmp/my_app
bundle add solidus --git "file:https://$(ruby -e"puts File.expand_path ENV['CIRCLE_WORKING_DIRECTORY']")"
export SKIP_SOLIDUS_BOLT='true' # workaround for solidus_frontend not respecting --auto-accept when asking about bolt
Copy link
Member Author

Choose a reason for hiding this comment

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

Opted for removing the line altogether, we should test things as close as possible to the final usage

Tried removing the line, but fails with this error, somehow I think bundle_cleanly in the solidus_frontend gem has a bad interaction with the main script, so I'm adding it back, but updating the comment.

Using solidus 3.3.0.alpha from file:https:///home/circleci/solidus (at elia/frontend-templates@34468ee)
    generate    solidus_frontend:install
       rails    generate solidus_frontend:install --auto-accept --auto-run-migrations
      create  config/initializers/solidus_frontend.rb
       exist  app/assets/images
      create  vendor/assets/javascripts/spree/frontend
      create  vendor/assets/stylesheets/spree/frontend
      create  vendor/assets/images/spree/frontend
      create  vendor/assets/javascripts/spree/frontend/all.js
      create  vendor/assets/stylesheets/spree/frontend/all.css
     gemfile  solidus_bolt
    generate  solidus_bolt:install --auto-run-migrations
       rails  generate solidus_bolt:install --auto-run-migrations 
Could not find solidus_bolt-0.7.2, coffee-rails-5.0.0, httparty-0.20.0, multi_json-1.15.0, omniauth-bolt-0.3.0, solidus_social-1.5.0, tweetnacl-1.0.0, coffee-script-2.4.1, multi_xml-0.6.0, omniauth-oauth-1.2.0, oa-core-0.3.2, omniauth-2.1.0, omniauth-facebook-9.0.0, omniauth-github-2.0.0, omniauth-google-oauth2-0.8.0, omniauth-rails_csrf_protection-1.0.1, coffee-script-source-1.12.2, oauth-1.1.0, hashie-5.0.0, rack-protection-2.2.2, omniauth-oauth2-1.7.3, jwt-2.5.0, oauth-tty-1.0.5, snaky_hash-2.0.0, version_gem-1.1.1, oauth2-2.0.9, faraday-2.5.2, faraday-net_http-3.0.0, ruby2_keywords-0.0.5 in any of the sources
Run `bundle install` to install missing gems.

Exited with code exit status 1

https://app.circleci.com/pipelines/github/nebulab/solidus/391/workflows/05b8d862-a54b-4c2d-a00e-ce9304e8c7fe/jobs/4875

bin/sandbox Outdated
@@ -3,6 +3,10 @@
# Used in the sandbox rake task in Rakefile

set -e
if [ ! -z $DEBUG ]
Copy link
Member Author

Choose a reason for hiding this comment

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

Done! TIL 🙏


# `solidus_frontend` is not sourced from rubygems if the solidus gem was not.
github_solidus_frontend = '--github solidusio/solidus_frontend' unless solidus.source.is_a? Bundler::Source::Rubygems
bundle_command("add solidus_frontend --skip-install #{github_solidus_frontend}")
Copy link
Member Author

Choose a reason for hiding this comment

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

Done, now the starter_frontend just adds the gem, and the break-down recipe doesn't do that anymore.

solidus
])

# `solidus_frontend` is not sourced from rubygems if the solidus gem was not.
Copy link
Member Author

Choose a reason for hiding this comment

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

Adding solidus_frontend was removed from this app-template.

@benjaminwil
Copy link
Contributor

@elia:

@forkata that's a good point, can you please help give me the ropes on how to replicate that issue?

We just created reproduction instructions and started a discussion for it: #4634

bin/sandbox Outdated
@@ -3,6 +3,7 @@
# Used in the sandbox rake task in Rakefile

set -e
test -z "${DEBUG+empty_string}" && set -x
Copy link
Contributor

@waiting-for-dev waiting-for-dev Sep 22, 2022

Choose a reason for hiding this comment

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

Careful! Length is zero (-z) when $DEBUG is not set, so it's actually doing the opposite that we want.

Copy link
Member Author

Choose a reason for hiding this comment

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

🤦‍♂️ thanks, fixed

Mostly fixing the double space.
Rather than custom `puts` and `Kernel#\`` use helpers like `rake`, `route`, and `say_status`.
Move it before installing the frontend so it's not hindered by routes
added to the Core engine, which are confusing for the helper.
Persisting the solidus version to a file was there just to support
stoplight.

The was job added in 334e773.
Spotlight was removed in 8f499b2.
Includes a smoke test ensuring the application starts and has the
expected copy on the home page.
Generators supporting those options will now be able to respect the
intent given in the original install command.
That handling was added at a time in which the sandbox couldn't
function without it. Now it just confuses the frontend installers
skipping the solidus_auth_devise plugin installation if it is already
in the Gemfile.
This change makes it trivial to add/remove/change frontend or to pass
a custom template to be used. This among other use-cases can become
handy for testing out branches of solidus_starter_frontend without
touching the code of the installer.

It's also closer to what you would expect coming from `rails new`
options.

In the process `--frontend=none` was fixed and now properly removes
`solidus_frontend`.

The bundler splitter was compacted into a single file and always adds
`solidus_frontend` leaving the choice to other templates if to keep it.
Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks, @elia! You're great.

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Wow, thanks Elia!

@kennyadsl kennyadsl merged commit 992b288 into solidusio:master Sep 23, 2022
@kennyadsl kennyadsl deleted the elia/frontend-templates branch September 23, 2022 14:34
@waiting-for-dev waiting-for-dev added the type:enhancement Proposed or newly added feature label Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem type:enhancement Proposed or newly added feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants