Skip to content
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

Regression: default directory for included taskfiles incorrect. #1579

Closed
wburningham opened this issue Apr 4, 2024 · 2 comments
Closed

Regression: default directory for included taskfiles incorrect. #1579

wburningham opened this issue Apr 4, 2024 · 2 comments

Comments

@wburningham
Copy link

Task v3.35.1 sets the directory of included taskfiles to the directory where the taskfile lives. In task v3.34.1 the directory had to explicitly be set with dir when including the taskfile.

If this is the intended behavior, I likely misunderstand what the real-world use of dir would be when including taskfiles.

A simple repro case:

---
version: 3

includes:
    sub_with_dir:
        taskfile: ./sub_with_dir
        dir: ./sub_with_dir
    sub_without_dir:
        taskfile: ./sub_without_dir

tasks:
  default:
    cmds:
      - cmd: echo "root        | ROOT_DIR =     '{{.ROOT_DIR}}'"
        silent: true
      - cmd: echo "root        | TASKFILE_DIR = '{{.TASKFILE_DIR}}'"
        silent: true
      - task: sub_with_dir
      - task: sub_without_dir

The taskfiles in the sub* directories print the same variables

With 3.34.1:

❯ go run github.com/go-task/task/v3/cmd/[email protected]
root        | ROOT_DIR =     '/tmp.ylQuJeHdXa'
root        | TASKFILE_DIR = '/tmp.ylQuJeHdXa'
sub with    | ROOT_DIR =     '/tmp.ylQuJeHdXa'
sub with    | TASKFILE_DIR = '/tmp.ylQuJeHdXa/sub_with_dir'
sub without | ROOT_DIR =     '/tmp.ylQuJeHdXa'
sub without | TASKFILE_DIR = '/tmp.ylQuJeHdXa'

With 3.35.1:

❯ go run github.com/go-task/task/v3/cmd/[email protected]
root        | ROOT_DIR =     '/tmp.ylQuJeHdXa'
root        | TASKFILE_DIR = '/tmp.ylQuJeHdXa'
sub with    | ROOT_DIR =     '/tmp.ylQuJeHdXa'
sub with    | TASKFILE_DIR = '/tmp.ylQuJeHdXa/sub_with_dir'
sub without | ROOT_DIR =     '/tmp.ylQuJeHdXa'
sub without | TASKFILE_DIR = '/tmp.ylQuJeHdXa/sub_without_dir'

Notice how the TASKFILE_DIR variable is different for the taskfile included from sub_with_dir and with dir set.

  • Task version: 3.34.1 vs 3.35.1
  • Operating system: macOS 14.2
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Apr 4, 2024
@pd93
Copy link
Member

pd93 commented Apr 4, 2024

@wburningham This was a bug fix and is intended behaviour. The TASKFILE_DIR variable is supposed to hold the value of the path to the Taskfile in which the current task is stored.

If this is the intended behavior, I likely misunderstand what the real-world use of dir would be when including taskfiles.

If you extend the cmds section in your example to include an echo of $PWD, it becomes somewhat clearer what dir actually does in an includes. For example:

...
    cmds:
      - cmd: echo "root        | ROOT_DIR =     '{{.ROOT_DIR}}'"
        silent: true
      - cmd: echo "root        | TASKFILE_DIR = '{{.TASKFILE_DIR}}'"
        silent: true
      - cmd: echo "root        | PWD =          '$PWD'"
        silent: true
...

obviously update the sub* Taskfiles too

Outputs:

root        | ROOT_DIR =     '/home/pete/dev/github.com/go-task/task/tmp/1579'
root        | TASKFILE_DIR = '/home/pete/dev/github.com/go-task/task/tmp/1579'
root        | PWD =          '/home/pete/dev/github.com/go-task/task'
sub with    | ROOT_DIR =     '/home/pete/dev/github.com/go-task/task/tmp/1579'
sub with    | TASKFILE_DIR = '/home/pete/dev/github.com/go-task/task/tmp/1579/sub_with_dir'
sub with    | PWD =          '/home/pete/dev/github.com/go-task/task/tmp/1579/sub_with_dir'
sub without | ROOT_DIR =     '/home/pete/dev/github.com/go-task/task/tmp/1579'
sub without | TASKFILE_DIR = '/home/pete/dev/github.com/go-task/task/tmp/1579/sub_without_dir'
sub without | PWD =          '/home/pete/dev/github.com/go-task/task/tmp/1579'

You can see that the execution directory changes to ./sub_with_dir when the dir is included, but stays the same as the root Taskfile when omitted.

@pd93 pd93 closed this as completed Apr 4, 2024
@pd93 pd93 added type: question Further information is requested. and removed state: needs triage Waiting to be triaged by a maintainer. labels Apr 4, 2024
@wburningham
Copy link
Author

Got it. Thanks for explaining how setting dir affects {{.TASKFILE_DIR}} and $PWD. Cheers.

@pd93 pd93 removed the type: question Further information is requested. label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants