-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
Ability to use the dotenv key inside included Taskfiles #1075
Comments
@apgrucza This doesn't solve your problem per se, but you could take a look at the problem/solution in #920 to see if the scenario described there could work for you. You may find that it helps to reduce the number of Taskfiles that you need to include in your project too. However, this probably isn't practical if the Taskfiles in your subdirectories are very specific (i.e. cannot be generalised). |
Thanks for the suggestion @pd93. In my case the Taskfiles in the subdirectories are indeed very specific and so cannot be generalised. I could of course move all tasks into the root and have just a single Taskfile, but I prefer the separation of concerns that my current structure provides. |
Yep, that's understandable. Just thought I'd see if there was a solution that could work for you in the meantime. Also, see this related PR and comment where this topic has come up before: #904 (comment) |
Regarding this comment from #904:
I didn’t show it in my example above, but I also have a common Taskfile that’s included from all other Taskfiles. The common Taskfile defines shared variables, some of which need to be based on content from .env files. So scoping dotenv to individual Taskfiles would not work for me. #1030 covers the topic of Taskfile-scoped variables, so I’ve added my thoughts in a comment over there. |
I am running into the same organizational question, see below:
|
FWIW I found a workaround for this that works okay for my use case. I have some variables that I want to be common across all tasks, but I want each folder to have its own Taskfile, and I want them to be usable from a hierarchical include (for rollup tasks) as well as locally from the folder. With the structure below, I can run the task from either location and it works fine. The secret is putting the tasks in the .actual files . $ task dep:deploymenta:tryout
foo
./deployments/deploymenta $ task tryout
foo and a rollup task: . $ task tryout-all
Do something big with foo
foo for a
foo for b
taskfile.env
main folder taskfile version: '3'
dotenv: [ "Taskfile.env" ]
includes:
dep:
taskfile: ./deployments/Taskfile.yml
dir: ./deployments
tasks:
#example of a rollup task
tryout-all:
cmds:
- echo "Do something big with {{.REMOTE_STUB_NAME}}"
- task: dep:deployementa:tryout
- task: dep:deployementb:tryout
deployments taskfile version: '3'
includes:
deploymenta:
taskfile: ./deploymenta/Taskfile.yml.actual
dir: ./deploymenta
deploymentb:
taskfile: ./deploymentb/Taskfile.yml.actual
dir: ./deploymentb deploymentsa taskfile.actual version: '3'
tasks:
tryout:
cmds:
- echo "{{.REMOTE_NAME_STUB}} for a" deploymentsa Taskfile.yml version: '3'
includes:
actual:
taskfile: Taskfile.yml.actual
flatten: true
dotenv: ["../../Taskfile.env"] deploymentsb have the same structure as deployments a Some notes:
|
Currently the
dotenv
key cannot be used inside included Taskfiles. Doing so gives the following error:Suppose I have the below structure, where the root Taskfile
includes
the Taskfiles in the subdirectories:I find it useful to be able to have the choice to run Task from either:
task app:build
, orapp
subdirectory, e.g.task build
I can't do this and also make use of the
dotenv
feature. If I placedotenv
in the root Taskfile, it will be ignored in case 2. If I placedotenv
in the included Taskfile, I get an error in case 1. I'd likedotenv
declarations in included files to be processed without error. If the same.env
file is referenced in multiple included Taskfiles, this should also not produce an error.This does raise a question about order of precedence when different
.env
files are specified across different Taskfiles. Perhaps we could have a rule whereby values in a.env
file override values from an included.env
file. Or if it's simpler, just return an error if different Taskfiles reference different.env
files.The text was updated successfully, but these errors were encountered: