Coder Social home page Coder Social logo

Comments (5)

adamwight avatar adamwight commented on June 19, 2024

Perhaps the git_hooks configuration could support a general environment override like,

environment:
  MIX_ENV: test

... or a specific one like,

mix_env: test

For me, a reasonable workaround is to manually edit .git/hooks/pre_push to include the line,

MIX_ENV=test mix git_hooks.run pre_push "$@"

but it would be better to set the environment within the git_hooks.run mix task, to make it dynamically configurable without having to reinstall the hook.

from elixir_git_hooks.

qgadrian avatar qgadrian commented on June 19, 2024

@adamwight can you post your git_hooks configuration?

If you use a string to run the mix task, you will need to declare the mix environment, as in your example. But instead of that, you can use {:mix_task, :test} and you won't need to do anything else.

The README states that are the preferred option but feel free to submit any PR if you believe it's not clear enough ☺️

from elixir_git_hooks.

adamwight avatar adamwight commented on June 19, 2024

I see what you mean, now. "mix test" was a bad example because it correctly assumes it should be running in the test environment. However, I have other tasks which still need the environment set explicitly—maybe the problem is in how I've configured these tasks, not in how git_hooks runs them.

My configuration looks like this,

if Mix.env() == :test do
  config :git_hooks,
    verbose: true,
    hooks: [
      pre_push: [
        tasks: [
          {:mix_task, :clean},
          {:mix_task, :compile, ["--warnings-as-errors"]},
          {:mix_task, :format, ["--check-formatted"]},
          {:mix_task, :credo, ["--strict"]},
          {:mix_task, :test},
          {:mix_task, :coveralls},
          {:mix_task, :dialyzer},
          {:mix_task, :doctor}
        ]
      ]
    ],
    extra_success_returns: [
      # The compile step is being obstinate, it seems to give a special result
      # when run with --warnings-as-errors.
      {:ok, []}
    ]

and in my mix.exs, I have deps like:

{:credo, "~> 1.0", only: :test, runtime: false}

So the "mix credo" task is only accessible when MIX_ENV=test.

from elixir_git_hooks.

adamwight avatar adamwight commented on June 19, 2024

This is the magic I was looking for... feel free to close the issue!

# mix.exs
def project do
  [
    # ...
    preferred_cli_env: [{:"git_hooks.run", :test}]
  ]
end

from elixir_git_hooks.

qgadrian avatar qgadrian commented on June 19, 2024

I checked how to change the mix environment at runtime some time ago but couldn't find a way.

You could use credo on dev environment as an alternative, but glad you worked it out!

from elixir_git_hooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.