Cannot programmatically generate dependencies for a task
- Task version: v3.12.0 (h1:viFy8kdDZ2iTcpTuxzzJCeKtTGt9U+5iXMVIpLjvIro=)
- Operating System: Linux 5.10.16.3-microsoft-standard-WSL2
Example Taskfile showing the issue
I want to programmatically generate deps in a task based on the content of a variable, but it seems to be some problems when converting the string to a list. Here is a basic example:
version: '3'
env:
DEPS: "foo bar"
tasks:
default:
deps: {{ splitList " " .DEPS }}
cmds:
- echo default
foo:
cmds:
- echo foo
bar:
cmds:
- echo bar
Which generates this error:
$ ./build
yaml: unmarshal errors:
line 8: cannot unmarshal !!map into []*taskfile.Dep
I assume something like this should work?
You will have to quote {{ splitList " " .DEPS }} as currently it is picked up as a map by the YAML parser, and consequently Go text templating won't be ran for it.
Furthermore, the thing you have to remember, these are Go text templates, the result is text (i.e. a string), I'm not that familiar with Taskfile but I'm not aware of any functionality it that will unmarshal a YAML string to a YAML like structure which is what you will need in this case.
I'm working on a v4 that will be able to handle this functionality