-
-
Notifications
You must be signed in to change notification settings - Fork 625
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
TASKFILE_DIR always resolves to ROOT_DIR #860
Comments
Hi @postlund, It will return the right directory if you change the execution directory to be the subdir as well: includes:
subdir:
taskfile: ./subdir
dir: ./subdir To me the current behavior is the expected, and we could improve the documentation to make it clearer. But if anyone disagree, let me know. |
@andreynering Ok, then I understand (I think). Is there any reason why it wouldn't always point to the directory of the |
@andreynering Hi, I feel that the default behavior should be that the tasks are run from the location of the specific included taskfile. This is the behavior if you run that specific taskfile on its own. It's also the behavior if you only use one taskfile. For me it is a secondary function to run tasks included in other taskfiles in the root of the parent taskfile. I use task as a build tool and write many separated libraries/projects. Each of them have thier own taskfiles. So when I include these libraries in a main project where the one lib would include the other and so forth, it's natural to expect that the taskfile is run from where it was intended to run, and was probably tested that way too. |
@ameergituser We could consider changing the default behavior in the future, but on v3 it would be a backwards incompatible change, so we need at least to wait for v4 (which I think will take a long time to happen). Also, note that the expected behavior change from user to user. I've seem many people having a directory like Other (like me) more often setup them to run on the Taskfile directory. So this decision is not a matter of right and wrong, but what most people would do most of the time. |
@andreynering Maybe the behavior could be altered via a global setting? Just like you can change |
@andreynering I agree with you on the breaking backwards compatibility issues, and the use case aspect. |
Chiming in... I found this same issue thinking I had found a bug. I expect TASKFILE_DIR to be the dir of the Taskfile for the command I've sent, not the root/including taskfile (which I'd assume was ROOT_DIR) If taskfile1 includes taskfile2 and my command is |
Hello, everyone! I am also found "expected" behavior a little bit unexpected. But for me that is totally ok - just add one more string. And I found another case when I specified In my case I have set of 3
I prefer to have a lot of
And I will run command Let's summarize it. I expect that I can build a tree of any deep and variable should defines correct. But it is looks like I can work only with second level of deep. |
Hi all 👋 - this has confused me too with the expected behaviour. The docs state the following under https://taskfile.dev/api/#special-variables :
The wording does imply what people in this thread expected, and make the current implemented effect sound like a bug 😅. The If I have a nested taskfile containing the following: tasks:
test:
cmds:
- echo {{ .TASKFILE_DIR }}
- echo {{ .ROOT_DIR }}
- echo {{ .USER_WORKING_DIR }} These all output the same directory when invoked, regardless of whether I execute it in the root or from the directory it is defined. I can make it work like others in this thread by specifying the My use case is nested tasks wanting to send output to the same directory relative to where the file is defined, regardless of where it is run, i.e: all goes to tasks:
test:
cmds:
- echo "test" > {{ .TASKFILE_DIR }}/../../task1_output
It also seems that manually specifying the |
This works as expected in the latest version. |
Example Taskfile showing the issue
I'm trying to use
TASKFILE_DIR
in an includedTaskfile.yml
file but it always seems to resolve to the absolute path of the rootTaskfile.yml
file./home/postlund/foo/Taskfile.yml
/home/postlund/foo/subdir/Taskfile.yml
Running task:
I might have misunderstood something, but I would have expected
TASKFILE_DIR
being resolved to/home/postlund/foo/subdir
in this case.The text was updated successfully, but these errors were encountered: