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

Included Taskfiles have wrong working directory with USER_WORKING_DIR #1250

Closed
idelchi opened this issue Jul 1, 2023 · 2 comments · Fixed by #1309
Closed

Included Taskfiles have wrong working directory with USER_WORKING_DIR #1250

idelchi opened this issue Jul 1, 2023 · 2 comments · Fixed by #1309
Labels
area: variables Changes related to variables.

Comments

@idelchi
Copy link

idelchi commented Jul 1, 2023

I am having trouble executing tasks from an included file in the current working directory while using Taskfile.yml.

My goal is to be able to navigate to any sub-folder, run a task command, which would use the Taskfile.yml at the root, which in turn includes utilities and commands from other folders.

Here's a minimal example:

Taskfile.yml:

version: '3'

includes:
  info:
    taskfile: 'subfolder/Taskfile.yml'
    # dir: '{{.USER_WORKING_DIR}}

tasks:
  default: 
    cmds:
      - echo {{.USER_WORKING_DIR}}
      - pwd

subfolder/Taskfile.info.yml:

version: '3'

tasks:
  default: 
    cmds:
      - echo {{.USER_WORKING_DIR}}
      - pwd
    # dir: '{{.USER_WORKING_DIR}}'


When I'm inside the subfolder and run task info, the output is (as expected):

/home/user/ws/subfolder
/home/user/ws

Adding dir: '{{.USER_WORKING_DIR}}' to the include statement in Taskfile.yml, has no effect, while I would have expected it to resolve to /home/user/ws/subfolder.

Adding dir: '{{.USER_WORKING_DIR}}' to the task in subfolder/Taskfile.info.yml yields:

/home/user/ws/subfolder
/home/user/ws/home/user/ws/subfolder   (?)

It seems that USER_WORKING_DIR resolves to the correct directory, but the commands are not running there. Perhaps I'm using the functionality incorrectly?

A use-case is where I'm using the "--global" flag and have the aforementioned structure in my $HOME folder.
I can only get tasks in the 'root' Taskfile to execute in the current working context, but not the included ones.

  • Task version: v3.26.0
  • Operating system: Linux / Debian Bookworm
  • Experiments enabled: No
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Jul 1, 2023
andarto pushed a commit to andarto/task that referenced this issue Jul 21, 2023
…les (go-task#1250)

When using `dir: '{{.USER_WORKING_DIR}}'` in an included task, the working
directory was set incorrectly by concatenating the base Taskfile directory
and the USER_WORKING_DIR.
andreynering added a commit that referenced this issue Aug 18, 2023
andreynering added a commit that referenced this issue Aug 18, 2023
Closes #1046
Closes #1205
Closes #1250
Closes #1293
Closes #1274
Closes #1309

Co-authored-by: Marcus Spading <[email protected]>
@andreynering andreynering added type: bug Something not working as intended. area: variables Changes related to variables. and removed state: needs triage Waiting to be triaged by a maintainer. labels Aug 18, 2023
andreynering added a commit that referenced this issue Aug 26, 2023
Closes #1046
Closes #1205
Closes #1250
Closes #1293
Closes #1274
Closes #1309
Closes #1312

Co-authored-by: Marcus Spading <[email protected]>
andreynering added a commit that referenced this issue Aug 26, 2023
Closes #1046
Closes #1205
Closes #1250
Closes #1293
Closes #1274
Closes #1309
Closes #1312

Co-authored-by: Marcus Spading <[email protected]>
andreynering added a commit that referenced this issue Aug 26, 2023
Closes #1046
Closes #1205
Closes #1250
Closes #1293
Closes #1274
Closes #1309
Closes #1312

Co-authored-by: Marcus Spading <[email protected]>
@idelchi
Copy link
Author

idelchi commented Aug 27, 2023

The combination

Taskfile.yml

includes:
  info:
    taskfile: 'subfolder/Taskfile.yml'
    dir: '{{.USER_WORKING_DIR}}'

subfolder/Taskfile.yml

tasks:
  default:
    cmds:
      - echo {{.USER_WORKING_DIR}}
      - pwd

Will still run the cmds in the top-level Taskfile.yml folder, and not in the current working directory.

user@host:/var$ task -g info
task: [info:default] echo /var
/var
task: [info:default] pwd
/home/user

I'm no longer sure if this is the intended behavior though! I can work around this by assigning dir: $PWD

Although I guess the issue is that USER_WORKING_DIR variable is not available in the include statement.

@lucasfcnunes
Copy link
Contributor

@idelchi I too want to do something similar.

# <top_level_folder>/Taskfile.yaml
version: '3'
...
includes:
  current:
    # internal: true
    dir: '{{.USER_WORKING_DIR}}'
    taskfile: '{{.USER_WORKING_DIR}}/_Taskfile.yaml'
    # optional: true
...
# <top_level_folder>/<...>/_Taskfile.yaml
version: '3'
...
tasks:
  pwd: pwd
...

@pd93 pd93 removed the type: bug Something not working as intended. label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: variables Changes related to variables.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants