Elixir mix auto acknowledge
Asked Answered
W

2

14

I want to run tests of my Phoenix app on Travis-CI.

Log excerpt:

$ MIX_ENV=test mix do deps.get, compile, test

Could not find hex, which is needed to build dependency :phoenix

Shall I install hex? [Yn] 

When it comes to fetching and installing dependencies, it asks if it should install hex. I was wondering if I can pass a --yes option to mix so that it doesn't ask but just installs?

Ware answered 18/9, 2014 at 11:23 Comment(0)
M
31

As with any unix command, you could pipe yes into the mix command:

yes | MIX_ENV=test mix do deps.get, compile, test

But there are some warnings about this solution in the comments below. I recommend using the top voted solution!

Mathur answered 18/9, 2014 at 11:26 Comment(3)
This just blew my mind. Suddenly the very existence of this command makes so much senseJarib
There is a problem with this in Docker (and probably other contexts too) - Erlang buffers any input so a constant stream of 'yes' input can cause an overflow. See this answer: #36523059 I suggest the answer from Fred the Magic Wonder Dog is a better answer.Baillie
Indeed.. even in small applications this will make your beam process blow up to Gigabytes of RAM until an OOM is triggeredHarrar
B
33

You can add this command to your before_install section in .travis.yml

  • mix local.hex --force

After of course, you've already installed elixir in a previous command. I cargo culted this .travis.yml from an existing elixir project on github.

language: erlang
env:
  - ELIXIR="v1.0.0"
otp_release:
  - 17.1
before_install:
  - mkdir -p vendor/elixir
  - wget -q https://github.com/elixir-lang/elixir/releases/download/$ELIXIR/Precompiled.zip && unzip -qq Precompiled.zip -d vendor/elixir
  - export PATH="$PATH:$PWD/vendor/elixir/bin"
  - mix local.hex --force
script: "MIX_ENV=test mix do deps.get, test"
Broome answered 18/9, 2014 at 20:11 Comment(1)
I think this is the better solution and should be accepted as answer!Mathur
M
31

As with any unix command, you could pipe yes into the mix command:

yes | MIX_ENV=test mix do deps.get, compile, test

But there are some warnings about this solution in the comments below. I recommend using the top voted solution!

Mathur answered 18/9, 2014 at 11:26 Comment(3)
This just blew my mind. Suddenly the very existence of this command makes so much senseJarib
There is a problem with this in Docker (and probably other contexts too) - Erlang buffers any input so a constant stream of 'yes' input can cause an overflow. See this answer: #36523059 I suggest the answer from Fred the Magic Wonder Dog is a better answer.Baillie
Indeed.. even in small applications this will make your beam process blow up to Gigabytes of RAM until an OOM is triggeredHarrar

© 2022 - 2024 — McMap. All rights reserved.