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

[BUG] Enable dotenv will make go template pipeline be invalid. #1232

Closed
100gle opened this issue Jun 23, 2023 · 4 comments · Fixed by #1810
Closed

[BUG] Enable dotenv will make go template pipeline be invalid. #1232

100gle opened this issue Jun 23, 2023 · 4 comments · Fixed by #1810
Assignees
Labels
area: templating Changes related to the templating engine. type: bug Something not working as intended.

Comments

@100gle
Copy link

100gle commented Jun 23, 2023

  • Task version: v3.25.0 (h1:XtIEtWpQSbIf2FGU+44/QB1whFf2sBUB/02W7ZQSz0U=)
  • Operating system: Windows 10
  • Experiments enabled: false

How to reproduce it?

When I don't include dotenv key in config file, all things work well:

version: '3'

vars:
  ROOT: 
    sh: echo {{toSlash .ROOT_DIR}}
  DOCKER: 
    sh: echo {{.ROOT}}/docker

tasks:
  foo:
    cmds: 
      - echo {{.DOCKER}}
# in my directory: D:/Reops/test
$ task foo
task: [foo] echo D:/Repos/test/docker
D:/Repos/test/docker

But when I add dotenv keys in config file with an empty .env file(created but no content):

version: '3'

dotenv: 
  - .env

vars:
  ROOT: 
    sh: echo {{toSlash .ROOT_DIR}}
  DOCKER: 
    sh: echo {{.ROOT}}/docker

tasks:
  foo:
    cmds: 
      - echo {{.DOCKER}}

then run task again and the console will show:

$ task foo
template: :1:15: executing "" at <.ROOT_DIR>: invalid value; expected string
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Jun 23, 2023
@dennybaa
Copy link

+1 Well it seems more like that all taskfile defined env is simply not substituted in dynamic vars.

env:
   IMAGE_DIR: "HELLO"

# or
# dotenv: [".env"]

tasks:
  mkdisk:
    vars:
      imageDir: '{{ env "IMAGE_DIR" }}'
    cmds:
      - echo '{{.imageDir}}'  

@MuriloGhignatti
Copy link

This is also happening to me, the following doesn't work as well:

vars:
  TEST: "{{.USER_WORKING_DIR | toSlash}}"

dotenv:
  - ".env"

tasks:
  test:
    desc: "A test task"
    cmds:
      - echo 'This is a test!'

@lukasphase
Copy link

  • Task version: v3.38.0 (h1:O7kgA6BfwktXHPrheByQO46p3teKtRuq1EpGnFxNzbo=)
  • Operating System: Windows 11
  • Experiments Enabled: no

This works as expected when defining vars at the task level:

dotenv:
  - sandwich.env

vars:
  SANDWICH: '{{ env "SANDWICH" | default .DEFAULT_SANDWICH }}.sandwich'

tasks:
  sandwich:
    vars:
      SANDWICH_PATH: '{{ joinPath .ROOT_DIR .SANDWICH_DIR .SANDWICH | osClean }}'
    cmds:
      - echo {{ relPath .ROOT_DIR .SANDWICH_PATH | toSlash }}
$ task sandwich
task: [sandwich] echo sandwiches/cheese-and-pickle.sandwich
sandwiches/cheese-and-pickle.sandwich

It breaks when a template pipeline is used at the global var level:

dotenv:
  - sandwich.env

vars:
  SANDWICH: '{{ env "SANDWICH" | default .DEFAULT_SANDWICH }}.sandwich'
  SANDWICH_PATH: '{{ joinPath .ROOT_DIR .SANDWICH_DIR .SANDWICH | osClean }}'

tasks:
  sandwich:
    cmds:
      - echo {{ relPath .ROOT_DIR .SANDWICH_PATH | toSlash }}
$ task sandwich
template: :1:12: executing "" at <.ROOT_DIR>: invalid value; expected string

sandwich.env for reference:

SANDWICH_DIR=sandwiches
DEFAULT_SANDWICH=cheese-and-pickle

@vmaerten
Copy link
Member

I took some times to investigate this.
This is because special variable are not available when dotEnv are read. In your example, what cause the issue is ROOT_DIR or USER_WORKING_DIR

@vmaerten vmaerten added type: bug Something not working as intended. area: templating Changes related to the templating engine. and removed state: needs triage Waiting to be triaged by a maintainer. labels Sep 15, 2024
@vmaerten vmaerten self-assigned this Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: templating Changes related to the templating engine. type: bug Something not working as intended.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants