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

mix - Alias to run multiple tasks from different environments #7162

Closed
dylan-chong opened this issue Dec 31, 2017 · 5 comments
Closed

mix - Alias to run multiple tasks from different environments #7162

dylan-chong opened this issue Dec 31, 2017 · 5 comments

Comments

@dylan-chong
Copy link
Contributor

Precheck

  • Do not use the issues tracker for help or support (try Elixir Forum, Stack Overflow, IRC, etc.)
  • For proposing a new feature, please start a discussion on the Elixir Core mailing list
  • For bugs, do a quick search and make sure the bug has not yet been reported
  • Finally, be nice and have fun!

Environment

  • Elixir & Erlang versions (elixir --version):
Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.5.3
  • Operating system: mac 10.13.2

Current behavior

In my mix.exs :

  defp aliases do
    [
      check: [
        "dialyzer",
        "credo",
        "test",
      ],
    ]
  end

Running mix check from the command line yields ** (Mix) "mix test" is running on environment "dev". If you are running tests along another task, please set MIX_ENV explicitly (this error is silently suppressed if "test" is the last task in the list, so you have to move to the top of the list to see this error).

However, running MIX_ENV=test mix check yields ** (Mix) The task "dialyzer" could not be found. Presumably the dialyzer task is not in the test environment, only dev.

Expected behavior

Firstly, the error above should not be silently suppressed if the task is the last on the list.

There should be some way to run multiple tasks from multiple environments together. Or maybe not? The alternative could just be to write a bash script?

@josevalim
Copy link
Member

josevalim commented Jan 1, 2018 via email

@dylan-chong
Copy link
Contributor Author

dylan-chong commented Jan 1, 2018

Can you please provide a minimal mix.exs that reproduces the error?

Sure https://github.com/dylan-chong/elixir_environment_error_test

I put 2 different tasks there with different orderings of the tasks - check1, check2

You can add dialyzer to
the test environment though.

Good idea!

@josevalim
Copy link
Member

I am getting the proper error in both tasks:

~/OSS/elixir_environment_error_test[master]$ mix check1
** (Mix) "mix test" is running on environment "dev". If you are running tests along another task, please set MIX_ENV explicitly
~/OSS/elixir_environment_error_test[master]$ mix check2
Checking PLT...
[:compiler, :elixir, :kernel, :logger, :stdlib]
PLT is up to date!
Starting Dialyzer
dialyzer args: [
  check_plt: false,
  init_plt: '/Users/jose/OSS/elixir_environment_error_test/_build/dev/dialyxir_erlang-20.0_elixir-1.7.0-dev_deps-dev.plt',
  files_rec: ['/Users/jose/OSS/elixir_environment_error_test/_build/dev/lib/elixir_environment_error_test/ebin'],
  warnings: [:unknown]
]
done in 0m1.27s
done (passed successfully)
Checking 1 source file ...

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.03 seconds (0.00s to load, 0.03s running checks)
2 mods/funs, found no issues.

Use `--strict` to show all issues, `--help` for options.
** (Mix) "mix test" is running on environment "dev". If you are running tests along another task, please set MIX_ENV explicitly

Please let us know if there is anything else to reproduce this issue. Thank you!

@bartoszgorka
Copy link

@dylan-chong Hi.
I prepared for my project alias to check dynamic code.

mix.exs

defp deps do
    [
      {:credo, "~> 0.8", only: [:dev, :test], runtime: false},
      {:dialyxir, "~> 0.5", only: [:dev, :test], runtime: false},
      {:excoveralls, "~> 0.7", only: [:dev, :test], runtime: false},
    ]
  end

  defp aliases do
    [
      "credo": ["credo --strict"],
      "coveralls": ["coveralls --umbrella"],
      "coveralls.detail": ["coveralls.detail --umbrella"],
      "full_check": ["credo", "dialyzer", "test --listen-on-stdin --stale"],
      "check": ["credo", "test --listen-on-stdin --stale"],
    ]
  end

  defp dialyzer do
    [
      flags: [:error_handling, :race_conditions, :underspecs, :unmatched_returns],
      plt_add_apps: [:ex_unit, :mix],
    ]
  end

Remember about add dialyzer also do :test env.
Commit in my repo

@dylan-chong
Copy link
Contributor Author

@josevalim Strange, the error messages a showing today for me as well. Not sure what changed since yesterday. I'll reopen this issue if there is a more reliable way to replicate the issue

@bartoszgorka Yes adding dialyser to the test environment works for me

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

No branches or pull requests

3 participants