Comments (5)
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.
@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.
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.
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.
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)
- With older git returns an error HOT 2
- Don't run the hook when nothing in the project root has changed HOT 1
- 0.6.5 release HOT 2
- Add support to mix tasks results HOT 1
- Compilation error when export `deps_path` is set HOT 13
- mono-repo with multiple applications HOT 5
- git_hooks.run not found HOT 1
- mix compile --warnings-as-errors succeeds, but git_hooks registers as a failure HOT 3
- Pre commit/push hooks fail in the latest version HOT 13
- feature request: allow tasks to be configured to run in parallel HOT 1
- Confusion after rebuilding dependencies until git_hooks.install HOT 7
- Seeing please ensure :git_hooks exists or remove the configuration. HOT 2
- Using && within a :cmd appears to be a problem?
- Running pre-commit hook only for staged files
- Cut a new release with updated dependencies HOT 2
- Pre-commit hook appears execute after commit has taken place HOT 10
- [Feature request] overriding the git hook so that we can make it run mix tasks inside of docker compose HOT 6
- Configurability to run hooks only on a certain branch HOT 1
- Invalid hook path and script when using git_path HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elixir_git_hooks.