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 resolved incorrectly in dynamic variables of included Taskfiles #2057

Open
Diaphteiros opened this issue Feb 11, 2025 · 1 comment
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@Diaphteiros
Copy link

Diaphteiros commented Feb 11, 2025

Description

Setup

./
├── Taskfile.yaml
└── common/
    ├── Taskfile.yaml
    └── foo.sh

Taskfile.yaml

version: 3

includes:
  shared:
    taskfile: common

tasks:
  pwd:
    desc: Print the current working directory.
    cmds:
    - pwd

common/Taskfile.yaml

version: 3

vars:
  foo:
    sh: '{{.TASKFILE_DIR}}/foo.sh'

tasks:
  pwd:
    desc: Print the current working directory.
    cmds:
      - pwd

common/foo.sh

The content of this file doesn't really matter.

#!/bin/bash
echo "foo"

Actual Behavior

Calling task shared:pwd works as expected:

task: [shared:pwd] pwd
/var/folders/b8/g43jjlg51gs4h13yf49sjmjm0000gn/T/tmp.6yctrFQfZM/tasktest

However, calling any task from the root Taskfile sets TASKFILE_DIR to the root Taskfile's directory for variable resolution, leading to this error:

stat /var/folders/b8/g43jjlg51gs4h13yf49sjmjm0000gn/T/tmp.6yctrFQfZM/tasktest/foo.sh: no such file or directory
task: Command "/var/folders/b8/g43jjlg51gs4h13yf49sjmjm0000gn/T/tmp.6yctrFQfZM/tasktest/foo.sh" failed: exit status 127

Expected Behavior

{{.TASKFILE_DIR}} in the common/Taskfile.yaml file should always resolve to the common subdirectory, never to the directory of the including Taskfile. The current behavior makes it impossible for the included Taskfile to reference a file next to it (at least without knowing the relative path from including to included Taskfile).

Version

v3.41.0

Operating system

macOS (darwin/arm64)

Experiments Enabled

None

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Feb 11, 2025
@Diaphteiros
Copy link
Author

Possibly related to #1684

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

2 participants