task icon indicating copy to clipboard operation
task copied to clipboard

TASKFILE_DIR not appropriately set when in include vars

Open jselleck-sans opened this issue 8 months ago • 1 comments

  • Task version: v3.37.2
  • Operating system: Ubuntu Nobel
  • Experiments enabled:

The behavior of TASKFILE_DIR has changed when using assignment in include variables.

Having two task files: caller/demo/caller_Taskfile.yml

version: "3"

includes:
  myinc:
    taskfile: ../../include_Taskfile.yml
    internal: true
    vars:
      PATH: "{{.TASKFILE_DIR}}".  ### < This is getting set to the path ../../include_Taskfile.yml is in.  :(

tasks:
  pathvars:
    desc: Show Path
    deps:
      - task: myinc:count
        vars:
          PATH: "{{.TASKFILE_DIR}}"  ### < This is getting set to the path this task file is in. :)
    cmds:
      - |
        echo "pass path"

  path:
    desc: Show Count
    deps:
      - task: myinc:count
    cmds:
      - |
        echo "count on impot vars"

include_Taskfile.yaml

# code: language=yaml
version: "3"

vars:
  COUNT: 3

tasks:
  count:
    internal: true
    silent: false
    requires:
      vars: ["PATH"]
    cmds:
      - |
        echo "{{.PATH}}"

when running path: It echos the directory of the included task file. It's expected to echo the caller Taskfile dir.
when running pathvars: the output is as expected, the callers dir is echoed.

When using other vars within includes.vars they get passed appropriately. I have not tested other go templating behaviors within includes.vars

We have many users using this pattern so this change took us by surprise.

jselleck-sans avatar Jun 05 '24 22:06 jselleck-sans