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] Global Taskfile with local dotenv file not loading Taskfile variables using USER_WORKING_DIR path reference #1629

Open
rrmistry opened this issue May 1, 2024 · 1 comment
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@rrmistry
Copy link

rrmistry commented May 1, 2024

With this Taskfile:

# Global Taskfile: ~/Taskfile.yaml
version: "3"
dotenv:
  - "{{.USER_WORKING_DIR}}/.env" # <<<< Does not work (but it should)
  # - "~/repos/my-project/.env"  # <<<< Works
tasks:
  build:
    dir: '{{.USER_WORKING_DIR}}'
    dotenv: ["{{.USER_WORKING_DIR}}/.env"] # <<<< Does not load Taskfile Variable either but it does load env variable
    cmds:
      # Should print: "value = testABC123"
      - echo value = {{.DOT_ENV_VAR}}

And .env file:

# Local .env file: ~/repos/my-project/.env
DOT_ENV_VAR=testABC123

Then running this:

mkdir -p ~/repos/my-project
cd ~/repos/my-project
echo "DOT_ENV_VAR=testABC123" > .env
task -g build

Should print:

task: [build] echo value = testABC123
value = testABC123

But prints:

task: [build] echo value = 
value = 

This is not a blocker as we can still use script variables (instead of Taskfile variables):

# Global Taskfile: ~/Taskfile.yaml
version: "3"
tasks:
  build:
    dir: '{{.USER_WORKING_DIR}}'
    dotenv: ["{{.USER_WORKING_DIR}}/.env"] # <<<< Workaround loads env variables but not as Taskfile variables
    cmds:
      # Will print: "value = testABC123"
      - echo value = $DOT_ENV_VAR # Workaround

But it is not ideal as it prints:

task: [build] echo value = $DOT_ENV_VAR 
value = testABC123

We would like to see task output with variable values replaced in the script like below:

task: [build] echo value = testABC123
value = testABC123

Task Version Output:

 task --version
Task version: v3.36.0 (h1:XVJ5hQ5hdzTAulHpAGzbUMUuYr9MUOEQFOFazI3hUsY=)
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label May 1, 2024
@rrmistry rrmistry changed the title [Bug] Global Taskfile with local dotenv file not load variables using USER_WORKING_DIR path reference [Bug] Global Taskfile with local dotenv file not loading Taskfile variables using USER_WORKING_DIR path reference May 1, 2024
@meoyawn
Copy link

meoyawn commented May 31, 2024

unfortunately local dotenvs don't work at all #997

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

3 participants