Skip to content

Using -d option brakes path resolution within includes #2080

@0xn3va

Description

@0xn3va

Description

Hello team,

I tried to set the working directory using the -d option and include task file from another directory but Task incorrectly resolves the path for the included task file. You can follow the next steps to reproduce the issue:

  1. Create temp directory cd $(mktemp -d)

  2. Add shared task file to common.yml:

    version: '3'
    tasks:
      work:
        cmds:
          - echo 'Hello World from Task!'
  3. Add task file to Taskfile.yml:

    version: '3'
    includes:
      common:
        taskfile: "{{.DIR_PATH}}/common.yml"
    tasks:
      default:
        cmds:
          - task common:work
  4. Run the following command to confirm that everything working as expected when -d is not set:

    $ DIR_PATH="$(pwd)" task -t Taskfile.yml
    Hello World from Task!
    
  5. Run the following command to reproduce the error:

    $ DIR_PATH="$(pwd)" task -d "$(mktemp -d)" -t Taskfile.yml 
    task: No Taskfile found at "/var/folders/yp/syl984812xsdsc7qv3zr7y4c0000gp/T/tmp.1inKucKbvp"
    task: Failed to run task "default": exit status 100
    

I tried to set dir within includes but nothing worked.

Version

Task version: 3.41.0 (pypi)

Operating system

macos

Experiments Enabled

No response

Example Taskfile

# common.yml
version: '3'
tasks:
  work:
    cmds:
      - echo 'Hello World from Task!'

# Taskfile.yml
version: '3'
includes:
  common:
    taskfile: "{{.DIR_PATH}}/common.yml"
tasks:
  default:
    cmds:
      - task common:work

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions