Skip to content

Commit

Permalink
Fail ember:compile if build subprocess fails
Browse files Browse the repository at this point in the history
Closes [#417].

The following is the command `ember-cli-rails` generates for `rake
ember:compile`. It was generated using [the example application][repo].

```bash
/Users/seanpdoyle/src/ember-cli-rails-heroku-example/frontend/node_modules/.bin/ember build --environment 'development' --output-path '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/tmp/ember-cli/apps/frontend' | /usr/bin/tee -a '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/log/ember-frontend.development.log'

Pipes are streaming, so the pipe to `tee` will open before the first
program finishes writing, potentially ignoring a non-zero exit status.

The solution is to set the [`pipefail`][docs] option for the generated
sub-command.

[repo]: https://github.com/seanpdoyle/ember-cli-rails-heroku-example
[#417]: #417
[docs]: http://www.gnu.org/software/bash/manual/html_node/Pipelines.html
  • Loading branch information
seanpdoyle committed Mar 17, 2016
1 parent b70fe1a commit 89912d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ember_cli/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test
end

def build(watch: false)
"#{ember_build(watch: watch)} | #{tee}"
"set -o pipefail; #{ember_build(watch: watch)} | #{tee}"
end

private
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/ember_cli/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
expect(command.build).to match(%r{\| path/to/tee -a 'path/to/log'})
end

it "sets pipefail" do
paths = build_paths(tee: "path/to/tee", log: "path/to/log")
command = build_command(paths: paths)

expect(command.build).to match(%r{\Aset -o pipefail;})
end

context "when building in production" do
it "includes the `--environment production` flag" do
paths = build_paths
Expand Down

0 comments on commit 89912d2

Please sign in to comment.