-
-
Notifications
You must be signed in to change notification settings - Fork 671
dotenv:
should override Taskfile env:
just like the OS's environment does.
#521
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
Comments
I commented in #482
|
Hi @d3dc, I'm not sure what is the most expected behavior here. I think hearing opinions from more users would be nice before changing. In the meantime, you can use the version: '3'
tasks:
echo:
env:
TEST: '{{default "foobar" .TEST}}'
cmds:
- echo $TEST |
@andreynering I want to set environment for all of my tasks. I’m not sure what you’re suggesting addresses my concern. I want to use the Shell’s environment. I also want to use a dotenv. Why should I specify another call var? |
Personally my "general" expectation with If we look at the The question worth asking is: Is the version: '3'
dotenv: ['.env'] # ---> contains FOO=1 & BAR=2
tasks:
example-optin:
env:
FOO: "{{.FOO}}"
cmds:
- echo $FOO # ---> "1"
- echo $BAR # ---> ""
example-include:
dotenv: ['.env']
cmds:
- echo $FOO # ---> "1"
- echo $BAR # ---> "2"
example-include-override:
dotenv: ['.env']
env:
BAR: "3"
cmds:
- echo $FOO # ---> "1"
- echo $BAR # ---> "3" For now though, I would prefer to explicitly opt-in if the I'm yet to use the Edit.. noticed this related feature request. |
How do we do this for global scoped envs? Dotenv doesn't seem to be available within Vars, and is disregarded when evaluating the global env. I know v4 is in the works, but could we see a subset introduced into v3.9 to allow better access to scopes in gotemplates, or a way to have dotenv explicitly override the global scope? dotenv:
- file: .env
override: true |
What needs to happen is that vars of all sorts need to define their own expectations, similar to This variable will always have the value
This variable will have the value of
The same thing needs to apply broadly. The typical CLI behavior for config is usually this priority (highest takes precedence):
I think Vars need to have the option of being considered I would consider an Though, for additional flexibility, Task could also just give access to the various locations a variable could come from, and let the user make the decision in code as well, similar to github actions contexts: https://docs.github.com/en/actions/learn-github-actions/contexts |
I am not quite sure how does it relate to dotfiles, default only works with variables. Is there any workaround? Looks like currently dotenv files can't be used, as there is no way to define defaults (except on some bash level). Edit: Looks like setting default env on taskfile level, and dotenv on task level works, but it is very verbose |
Just as a bump, something like this would be really helpful for a problem I'm currently facing too. An optional test:ui:
desc: Run the Vitest test suite with browser UI
dotenv: [".env.test"]
cmds:
- ... |
I'm also confused by the current behaviour. Taskfile is primarily a tool our developers use locally and occasionally in CI. I'd expect it to prioritise convenience. In terms of overriding values, I'd anticipate it working from the outside in, as this setup aligns with most users' experiences with other tools. The order, from least to most precedence, should be:
At the moment, we're using dotenv-cli as a workaround, which operates in exactly this manner. |
I am finding dotenv essentially useless. If an env was defined when executing task, there seems to be no way to use dotenv to override the value. LIke @mjftw, I use direnv and tend to run task from nested directories that have .envrc and .env, but want to run task from the parent directory and then down into several environemnts each with their own .env context. Well, I can ensure that the task runs from the parent, but the envs are already polluted by the nested dir .env. |
Even trying to fork a new task carries with it all the env
|
And I can't even raise an error if run from the wrong directory
because task will run the taskfile in the parent directory, but all subdirectory .envs are already defined. |
strike that, this does it
|
.env files exist to supply a non-default value in a given deployment. If the default value just swallows them, what's the point?
(edit: I really like the tool that's been built and it's almost perfect, but it's driving me crazy when switching context 😅)
The text was updated successfully, but these errors were encountered: