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

Run after_bundle blocks with app:template command #48269

Conversation

jonathanhefner
Copy link
Member

App templates may contain after_bundle blocks which should be run after the template is executed, after running bundle install. For example:

gem "devise"

after_bundle do
  generate "devise:install"
end

Prior to this commit, bundle install and after_bundle blocks were run only when applying a template via rails new. This commit makes bin/rails app:template run them as well.


/cc @gerrywastaken I've added you as a co-author for your work on #40197.
/cc @quintrino Since you expressed interest #40197.

App templates may contain `after_bundle` blocks which should be run
after the template is executed, after running `bundle install`.  For
example:

  ```ruby
  gem "devise"

  after_bundle do
    generate "devise:install"
  end
  ```

Prior to this commit, `bundle install` and `after_bundle` blocks were
run only when applying a template via `rails new`.  This commit makes
`bin/rails app:template` run them as well.

Co-authored-by: "Gerard (Gerry) Caulfield" <git@caulfield.me>
@jonathanhefner jonathanhefner force-pushed the app_template-command-run-after_bundle-blocks branch from 6c6fb81 to 83e69c2 Compare May 21, 2023 19:35
@guilleiguaran guilleiguaran merged commit 844adad into rails:main May 21, 2023
9 checks passed
@gerrywastaken
Copy link
Contributor

gerrywastaken commented May 22, 2023

Thank you @jonathanhefner 😅

@ansonhoyt
Copy link
Contributor

ansonhoyt commented May 26, 2023

This makes me so happy! I won't miss re-running rails new my-app --template ... after an error reminds me that my template the needs the bundle stuff.

zzak added a commit to zzak/rails that referenced this pull request Oct 31, 2023
When rails#48269 was merged any gem installed during `rails new` which calls `app:template` would cause the install command to be executed and consequently `bundle install` would also run.

We want to avoid running these commands in our tests because they are very expensive.

It is up to the gem (importmap, etc) to test the behavior of the install command, not railties.

Before

```
$ bin/test test/generators/plugin_generator_test.rb test/generators/app_generator_test.rb
Finished in 320.803659s, 0.8541 runs/s, 7.1913 assertions/s.
274 runs, 2307 assertions, 14 failures, 0 errors, 0 skips
```

After

```
Finished in 70.316250s, 3.9251 runs/s, 34.3164 assertions/s.
276 runs, 2413 assertions, 0 failures, 0 errors, 0 skips
```
zzak added a commit to zzak/rails that referenced this pull request Dec 1, 2023
When rails#48269 was merged any gem installed during `rails new` which calls `app:template` would cause the install command to be executed and consequently `bundle install` would also run.

We want to avoid running these commands in our tests because they are very expensive.

It is up to the gem (importmap, etc) to test the behavior of the install command, not railties.

Before

```
$ bin/test test/generators/plugin_generator_test.rb test/generators/app_generator_test.rb
Finished in 320.803659s, 0.8541 runs/s, 7.1913 assertions/s.
274 runs, 2307 assertions, 14 failures, 0 errors, 0 skips
```

After

```
Finished in 70.316250s, 3.9251 runs/s, 34.3164 assertions/s.
276 runs, 2413 assertions, 0 failures, 0 errors, 0 skips
```
zzak added a commit to zzak/rails that referenced this pull request Dec 31, 2023
When rails#48269 was merged any gem installed during `rails new` which calls `app:template` would cause the install command to be executed and consequently `bundle install` would also run.

We want to avoid running these commands in our tests because they are very expensive.

It is up to the gem (importmap, etc) to test the behavior of the install command, not railties.

Before

```
$ bin/test test/generators/plugin_generator_test.rb test/generators/app_generator_test.rb
Finished in 320.803659s, 0.8541 runs/s, 7.1913 assertions/s.
274 runs, 2307 assertions, 14 failures, 0 errors, 0 skips
```

After

```
Finished in 70.316250s, 3.9251 runs/s, 34.3164 assertions/s.
276 runs, 2413 assertions, 0 failures, 0 errors, 0 skips
```
zzak added a commit to zzak/rails that referenced this pull request Jan 10, 2024
When rails#48269 was merged any gem installed during `rails new` which calls `app:template` would cause the install command to be executed and consequently `bundle install` would also run.

We want to avoid running these commands in our tests because they are very expensive.

It is up to the gem (importmap, etc) to test the behavior of the install command, not railties.

Before

```
$ bin/test test/generators/plugin_generator_test.rb test/generators/app_generator_test.rb
Finished in 320.803659s, 0.8541 runs/s, 7.1913 assertions/s.
274 runs, 2307 assertions, 14 failures, 0 errors, 0 skips
```

After

```
Finished in 70.316250s, 3.9251 runs/s, 34.3164 assertions/s.
276 runs, 2413 assertions, 0 failures, 0 errors, 0 skips
```
zzak added a commit to zzak/rails that referenced this pull request Apr 19, 2024
When rails#48269 was merged any gem installed during `rails new` which calls `app:template` would cause the install command to be executed and consequently `bundle install` would also run.

We want to avoid running these commands in our tests because they are very expensive.

It is up to the gem (importmap, etc) to test the behavior of the install command, not railties.

Before

```
$ bin/test test/generators/plugin_generator_test.rb test/generators/app_generator_test.rb
Finished in 320.803659s, 0.8541 runs/s, 7.1913 assertions/s.
274 runs, 2307 assertions, 14 failures, 0 errors, 0 skips
```

After

```
Finished in 70.316250s, 3.9251 runs/s, 34.3164 assertions/s.
276 runs, 2413 assertions, 0 failures, 0 errors, 0 skips
```
zzak added a commit to zzak/rails that referenced this pull request May 18, 2024
When rails#48269 was merged any gem installed during `rails new` which calls `app:template` would cause the install command to be executed and consequently `bundle install` would also run.

We want to avoid running these commands in our tests because they are very expensive.

It is up to the gem (importmap, etc) to test the behavior of the install command, not railties.

Before

```
$ bin/test test/generators/plugin_generator_test.rb test/generators/app_generator_test.rb
Finished in 320.803659s, 0.8541 runs/s, 7.1913 assertions/s.
274 runs, 2307 assertions, 14 failures, 0 errors, 0 skips
```

After

```
Finished in 70.316250s, 3.9251 runs/s, 34.3164 assertions/s.
276 runs, 2413 assertions, 0 failures, 0 errors, 0 skips
```
zzak added a commit to zzak/rails that referenced this pull request May 18, 2024
When rails#48269 was merged any gem installed during `rails new` which calls `app:template` would cause the install command to be executed and consequently `bundle install` would also run.

We want to avoid running these commands in our tests because they are very expensive.

It is up to the gem (importmap, etc) to test the behavior of the install command, not railties.

Before

```
$ bin/test test/generators/plugin_generator_test.rb test/generators/app_generator_test.rb
Finished in 320.803659s, 0.8541 runs/s, 7.1913 assertions/s.
274 runs, 2307 assertions, 14 failures, 0 errors, 0 skips
```

After

```
Finished in 70.316250s, 3.9251 runs/s, 34.3164 assertions/s.
276 runs, 2413 assertions, 0 failures, 0 errors, 0 skips
```

Change railties default log_level to :error

The default of :info generates a ton of unnecessary noise in the
railties logs.

This change greatly reduces the amount of noise in the railties tests.

**After**

```
$ bundle exec rake test >> railties_output_patched 2>&1
$ wc -l railties_output_patched
    1491 railties_output_patched
```

**Before**

```
$ bundle exec rake test >> railties_output_unpatched 2>&1
$ wc -l railties_output_unpatched
   19023 railties_output_unpatched
```
zzak added a commit that referenced this pull request May 18, 2024
When #48269 was merged any gem installed during `rails new` which calls `app:template` would cause the install command to be executed and consequently `bundle install` would also run.

We want to avoid running these commands in our tests because they are very expensive.

It is up to the gem (importmap, etc) to test the behavior of the install command, not railties.

Before

```
$ bin/test test/generators/plugin_generator_test.rb test/generators/app_generator_test.rb
Finished in 320.803659s, 0.8541 runs/s, 7.1913 assertions/s.
274 runs, 2307 assertions, 14 failures, 0 errors, 0 skips
```

After

```
Finished in 70.316250s, 3.9251 runs/s, 34.3164 assertions/s.
276 runs, 2413 assertions, 0 failures, 0 errors, 0 skips
```

Change railties default log_level to :error

The default of :info generates a ton of unnecessary noise in the
railties logs.

This change greatly reduces the amount of noise in the railties tests.

**After**

```
$ bundle exec rake test >> railties_output_patched 2>&1
$ wc -l railties_output_patched
    1491 railties_output_patched
```

**Before**

```
$ bundle exec rake test >> railties_output_unpatched 2>&1
$ wc -l railties_output_unpatched
   19023 railties_output_unpatched
```
zzak added a commit that referenced this pull request May 18, 2024
When #48269 was merged any gem installed during `rails new` which calls `app:template` would cause the install command to be executed and consequently `bundle install` would also run.

We want to avoid running these commands in our tests because they are very expensive.

It is up to the gem (importmap, etc) to test the behavior of the install command, not railties.

Before

```
$ bin/test test/generators/plugin_generator_test.rb test/generators/app_generator_test.rb
Finished in 320.803659s, 0.8541 runs/s, 7.1913 assertions/s.
274 runs, 2307 assertions, 14 failures, 0 errors, 0 skips
```

After

```
Finished in 70.316250s, 3.9251 runs/s, 34.3164 assertions/s.
276 runs, 2413 assertions, 0 failures, 0 errors, 0 skips
```

Change railties default log_level to :error

The default of :info generates a ton of unnecessary noise in the
railties logs.

This change greatly reduces the amount of noise in the railties tests.

**After**

```
$ bundle exec rake test >> railties_output_patched 2>&1
$ wc -l railties_output_patched
    1491 railties_output_patched
```

**Before**

```
$ bundle exec rake test >> railties_output_unpatched 2>&1
$ wc -l railties_output_unpatched
   19023 railties_output_unpatched
```
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