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

TASKFILE_DIR with incorrect value #1755

Closed
yz89122 opened this issue Aug 12, 2024 · 2 comments
Closed

TASKFILE_DIR with incorrect value #1755

yz89122 opened this issue Aug 12, 2024 · 2 comments

Comments

@yz89122
Copy link

yz89122 commented Aug 12, 2024

# /Users/user/includes/Taskfile.yml
version: '3'

envs:
  PROJECT_ROOT: '{{.TASKFILE_DIR}}'

tasks:
  test:
    cmds:
      - cmd: echo '{{.PROJECT_ROOT}}'
# /Users/user/Taskfile.yml
version: '3'

includes:
  included:
    taskfile: 'includes'

output: prefixed

tasks:
  test:
    deps: ['included:test']
    cmds:
     - cmd: echo '{{.PROJECT_ROOT}}'
cd /Users/user && task test

output:

task: [included:test] echo '/Users/user/includes'
[included:test] /Users/user/includes
task: [test] echo '/Users/user'
[test] /Users/user

expected output:

task: [included:test] echo '/Users/user/includes'
[included:test] /Users/user/includes
task: [test] echo '/Users/user/includes'
[test] /Users/user/includes
  • Task version: Task version: 3.38.0 ()
  • Operating system: macOS
  • Experiments enabled: false
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Aug 12, 2024
@vmaerten
Copy link
Member

Hello!
First of all, even if it works because variables are global, it's not recommanded to use variable declared in a children.

Back to your question, it's intended. We load all variables / envs when we read all the Taskfiles in the DAG. Then, each time we run a task (here we run included:test and test) we compile variables / envs , so:

  • first run (included:test) we compile PROJECT_ROOT to TASKFILE_DIR (=> '/Users/user/includes')
  • second run (test) we we compile PROJECT_ROOT to TASKFILE_DIR (=> '/Users/user/')

Why do we that ? because some variables rely on special variables (TASKFILE_DIR & co) or rely on sh variable which need to be compiled at runtime.

If you want to achieve this, I recommand to declare the variable / env in the Taskfile you want to use it

@task-bot task-bot removed the state: needs triage Waiting to be triaged by a maintainer. label Aug 14, 2024
@vmaerten vmaerten added type: question Further information is requested. state: needs triage Waiting to be triaged by a maintainer. and removed state: needs triage Waiting to be triaged by a maintainer. labels Aug 14, 2024
@yz89122
Copy link
Author

yz89122 commented Aug 14, 2024

Hi, @vmaerten

Thanks, I totally understand how it happened.

IMHO, if it's not recommended to use global variable / env from included taskfile, I'll strongly suggest that do not make the variables / envs from an included taskfile accessible outside of it. This is misleading and easily accidentally referenced it.

Thanks for your answering.

@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

4 participants