go-task / task

A task runner / simpler Make alternative written in Go
https://taskfile.dev
MIT License
11.01k stars 584 forks source link

TASKFILE_DIR not appropriately set when in include vars #1684

Open jselleck-sans opened 3 months ago

jselleck-sans commented 3 months ago

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 commented 3 months ago

The change of behavior seems to have been introduced in 3.35.1 Prior to that the behavior of setting it within includes..vars worked, but setting it in the task deps..vars was not correct.