go-task / task

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

Dynamic variables not working inside includes #1690

Open simonrouse9461 opened 3 months ago

simonrouse9461 commented 3 months ago

Taskfile:

version: '3'

vars:
  ENV_NAME: 
    sh: echo $(hostname)_$(users)

includes:
  test_import: 
    taskfile: '{{.ENV_NAME}}.yml'

tasks:
  test:
    cmds:
      - echo {{.ENV_NAME}}

This will fail with:

stat /path/to/my/workspace/.yml: no such file or directory

It seems that ENV_NAME evaluates to an empty string inside test_import.

simonrouse9461 commented 2 months ago

This won't work either:

version: '3'

dotenv:
  - .env

includes:
  test_import: 
    taskfile: '{{.ENV_NAME}}.yml'

tasks:
  test:
    cmds:
      - echo {{.ENV_NAME}}

where .env file contains:

ENV_NAME=my_env
cbrown1234 commented 2 months ago

I see similar behaviour with the special variables too

❯ ll
total 8.0K
-rw-r--r-- 1 chris chris 285 Jul  2 23:05 LocalTaskfile.yml
-rw-r--r-- 1 chris chris 176 Jul  2 23:06 Taskfile.yml

❯ cat Taskfile.yml
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: '3'

includes:
  local:
    taskfile: "{{.USER_WORKING_DIR}}/LocalTaskfile.yml"
    # optional: true

❯ task --list-all
stat /LocalTaskfile.yml: no such file or directory

Task version: v3.38.0 (h1:O7kgA6BfwktXHPrheByQO46p3teKtRuq1EpGnFxNzbo=) Operating system: "Ubuntu 22.04.4 LTS (on WSL2) Experiments enabled: N/A

vmaerten commented 2 months ago

Indeed dynamic variables and special variables are not evaluated before the include