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

Exit before assets:precompile task if yarn:install fails #36852

Conversation

juliantrueflynn
Copy link

Summary

I made this change to Webpacker and was recommended by @gauravtiwari to make it to Rails itself:
rails/webpacker#2192

Reason for change: When doing yarn:install if it failed the assets:precompile task would still be invoked. This PR ensures that on failure with yarn:install that assets:precompile will not be invoked.

Other Information

Link to original issue for person who spotted this: rails/webpacker#2185

@juliantrueflynn
Copy link
Author

juliantrueflynn commented Aug 3, 2019

I'm unsure why CI failed on this one with the change I did. Any ideas? They seem to be unrelated to what this PR is about (i.e. actioncable for example).

@sarcas
Copy link
Contributor

sarcas commented Aug 12, 2019

I was interested in this, and so I had a dig around.

It seems like the test failures stem from the dummy package.json that is set up for railties testing. When testing asset concatenation, we run the asset:precompile rake task. While the test is running, we set up a temporary rails app (see the test/isolation folders), including this package.json file.

Our yarn installation step can't find the packages it is looking for here, and so fails. Previously, it didn't fail at this step and so the test passed. Happily, this means that the test failures are related to your change. Unhappily, I don't know enough about yarn or the Rails testing setup to know if this is something we can fix by adjusting the test package.json, or if we need to change something else.

Incidentally, it feels like we might want to have a deeper look at the test cases here, in case we're missing other examples that are passing by coincidence. But that feels like another PR.

@juliantrueflynn
Copy link
Author

@sarcas Thank you, that was helpful. I will take a look at the specs. I will take a crack at updating the specs in this PR this week and see how big of a task this is. Maybe the webpacker gem tests can give me an idea of how to solve this.

@sarcas
Copy link
Contributor

sarcas commented Aug 13, 2019

@juliantrueflynn you're welcome! I had more time this evening, and it looks like the file in question was introduced here: #35184. Interestingly that PR was about yarn install running in these tests. It might be worth talking to the author there and see if they can give some pointers. Good luck!

@@ -9,6 +9,7 @@ namespace :yarn do
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
end
system({ "NODE_ENV" => node_env }, "#{Rails.root}/bin/yarn install --no-progress --frozen-lockfile")
exit(1) unless $?.success?
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
exit(1) unless $?.success?
system({ "NODE_ENV" => node_env }, "#{Rails.root}/bin/yarn install --no-progress --frozen-lockfile") || raise

I think raise is more appropriate than exit. This allows to switch to the using exception: true option when only support Ruby >= 2.6.

@rails-bot
Copy link

rails-bot bot commented Feb 13, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Feb 13, 2020
@rails-bot rails-bot bot closed this Feb 20, 2020
jaredbeck added a commit to jaredbeck/rails that referenced this pull request Apr 13, 2021
@jaredbeck
Copy link
Contributor

Fixed by #41824

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants