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

Inconsistent Variable Expansion When Using {{.VAR}} in .env Files with Nested Variables #1847

Open
WinkelCode opened this issue Sep 30, 2024 · 0 comments
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@WinkelCode
Copy link

WinkelCode commented Sep 30, 2024

When using a .env file to define environment variables that rely on other variables using {{.VAR}} template syntax, the variables sometimes expand inconsistently across task runs. The issue becomes more apparent as the variables become more deeply nested.


Steps to Reproduce:

  1. Create a Taskfile.yml:

    version: "3"
    
    dotenv: [".env"]
    
    vars:
      BASE_DIR_VAR: "/home/user"
      MID_DIR_VAR: "{{.BASE_DIR_VAR}}/nested"
      FINAL_DIR_VAR: "{{.MID_DIR_VAR}}/deeper"
      FULL_PATH_VAR: "{{.FINAL_DIR_VAR}}/file.txt"
    
    env:
      BASE_DIR_ENV: "/home/user"
      MID_DIR_ENV: "{{.BASE_DIR_ENV}}/nested"
      FINAL_DIR_ENV: "{{.MID_DIR_ENV}}/deeper"
      FULL_PATH_ENV: "{{.FINAL_DIR_ENV}}/file.txt"
    
    tasks:
      show_vars:
        cmds:
          - 'echo "FULL_PATH:     $FULL_PATH"'
          - 'echo "FULL_PATH2:    $FULL_PATH_2"'
          - 'echo "FULL_PATH_VAR: {{.FULL_PATH_VAR}}"'
          - 'echo "FULL_PATH_ENV: {{.FULL_PATH_ENV}}"'
        silent: true
  2. Create a .env File:

    BASE_DIR=/home/user
    MID_DIR=$BASE_DIR/nested
    FINAL_DIR=$MID_DIR/deeper
    FULL_PATH=$FINAL_DIR/file.txt
    MID_DIR_2={{.BASE_DIR}}/nested
    FINAL_DIR_2={{.MID_DIR_2}}/deeper
    FULL_PATH_2={{.FINAL_DIR_2}}/file.txt
  3. Run the task multiple times:

    task show_vars

Sample Outputs:

$ task show_vars
FULL_PATH:     /home/user/nested/deeper/file.txt
FULL_PATH2:    /home/user/nested/deeper/file.txt
FULL_PATH_VAR: /home/user/nested/deeper/file.txt
FULL_PATH_ENV: /home/user/nested/deeper/file.txt

$ task show_vars
FULL_PATH:     /home/user/nested/deeper/file.txt
FULL_PATH2:    /nested/deeper/file.txt
FULL_PATH_VAR: /home/user/nested/deeper/file.txt
FULL_PATH_ENV: /home/user/nested/deeper/file.txt

$ task show_vars
FULL_PATH:     /home/user/nested/deeper/file.txt
FULL_PATH2:    /nested/deeper/file.txt
FULL_PATH_VAR: /home/user/nested/deeper/file.txt
FULL_PATH_ENV: /home/user/nested/deeper/file.txt

$ task show_vars
FULL_PATH:     /home/user/nested/deeper/file.txt
FULL_PATH2:    /deeper/file.txt
FULL_PATH_VAR: /home/user/nested/deeper/file.txt
FULL_PATH_ENV: /home/user/nested/deeper/file.txt

  • Task version:
$ task --version
Task version: 3.39.2 ()
  • Operating system: macOS 15.1
  • Experiments enabled: None
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

2 participants