Dynamic variable resolution does not take into account current directory
Description
when creating dynamic variables like files: sh: "find ." in multiple subfolders, they won't be correctly evaluated. Due to internal caching, only the first result will be used.
Posted PR with reproduction and fix: https://github.com/go-task/task/pull/2160
Sample input
Folder structure:
root/
├── Taskfile.yaml
└── sub1/
├── Taskfile.yaml
└── a
└── sub2/
├── Taskfile.yaml
└── b
Taskfile.yml
version: '3'
run: when_changed
silent: true
output: prefixed
includes:
s1:
taskfile: sub1
dir: sub1
s2:
taskfile: sub2
dir: sub2
tasks:
all:
deps:
- s1:all
- s2:all
sub1/Taskfile.yaml, sub2/Taskfile.yaml:
version: '3'
vars:
files:
sh: "find ."
tasks:
all:
cmds:
- cmd: 'echo "{{.files}}"'
Actual output:
$ task all
[s2:all] .
[s2:all] ./Taskfile.yml
[s2:all] ./b
[s1:all] .
[s1:all] ./Taskfile.yml
[s1:all] ./b
Note how "s1" lists file "b", which is incorrect.
The annoying thing I found about this bug is that it can be intermittent/randomly reproducible. It's definitely a regression too as it wasn't an issue before.
Using the TASK_DIR special variable has helped avoid cached values.
E.g.:
vars:
files:
sh: "find {{.TASK_DIR}}/."
There might be other cases that can't be fixed this way, but in my case I'm just going to stick to this fix regardless of any go-task bug fixes.
@viktorasm this is likely fixed by #1649 .
Could you retest with the latest version of Task and confirm.