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

{{.USER_WORKING_DIR}} evaluated after dotenv #1312

Closed
ttudre977 opened this issue Aug 23, 2023 · 0 comments · Fixed by #1309
Closed

{{.USER_WORKING_DIR}} evaluated after dotenv #1312

ttudre977 opened this issue Aug 23, 2023 · 0 comments · Fixed by #1309
Labels
area: variables Changes related to variables. type: bug Something not working as intended.

Comments

@ttudre977
Copy link

ttudre977 commented Aug 23, 2023

I'm assuming that the issue is due to the order of evaluation at startup.

The following dotenv directive, does not source in the local .env, when the Taskfile.yaml resides in a parent directory (no local Taskfile.yaml), and using the {{.USER_WORKING_DIR}} in the path to the .env file.

dotenv:
    - "{{.USER_WORKING_DIR}}/.env" 

I'm trying to use a parent directory Taskfile.yaml for multiple environments:

.
├── Taskfile.yaml
├── env1
│   ├── .env
│   ├── myscript1.sh
├── env2
│   ├── .env
│   ├── myscript2.sh
├── env3
│   ├── .env
│   ├── myscript3.sh

The use case is to cd into any one of the env* directories, then run task X:

>cd env1
>task mytask

Where env1/.env contents are something like:

DOTENV_VAR="env1 specific value"

and where env2/.env contents are something like:

DOTENV_VAR="env2 specific value"

etc.

# Taskfile.yaml:
---
version: "3"

dotenv:
  - "env1/.env"  # works, but static, need to evaluate based on dir from which `task` command was run (child env1,2,3 dir).
  # - "<full_dir_path_to_env1>/.env"  # works
  # Options below, DO NOT WORK
  # - "{{.USER_WORKING_DIR}}/.env"  # does NOT work


tasks:
    mytask:
        dir: "{{.USER_WORKING_DIR}}"
        env:
          DEV: '{{.DOTENV_VAR}}'
        cmds:
          - echo "my local env DOTENV_VAR = $DEV"
...

The trick I'm using to get around this for now is that from #1008 (comment) :

tasks:
    mytask:
        dir: "{{.USER_WORKING_DIR}}"
        cmds:
            - |
              dotenv -f "{{.USER_WORKING_DIR}}/.env" run -- bash -c \
                'echo "getting the dotenv the hard way, LOCAL_DOTENV_VAR = [$DOTENV_VAR]"'

OR

tasks:
    mytask:
        dir: "{{.USER_WORKING_DIR}}"
        vars:
          LDV_BY_VARS:
            sh: dotenv -f "{{.USER_WORKING_DIR}}/.env" get DOTENV_VAR
    
        cmds:
          - echo ".env LDV_BY_VARS = [{{.LDV_BY_VARS}}]"
  • Task version: 3.27.1
  • Operating system: MacOS Ventura 13.3.1 (a) (22E772610a)
  • Experiments enabled: No
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Aug 23, 2023
@andreynering andreynering added type: bug Something not working as intended. area: variables Changes related to variables. and removed state: needs triage Waiting to be triaged by a maintainer. labels Aug 26, 2023
andreynering added a commit that referenced this issue Aug 26, 2023
Closes #1046
Closes #1205
Closes #1250
Closes #1293
Closes #1274
Closes #1309
Closes #1312

Co-authored-by: Marcus Spading <ms@fragmentum.net>
andreynering added a commit that referenced this issue Aug 26, 2023
Closes #1046
Closes #1205
Closes #1250
Closes #1293
Closes #1274
Closes #1309
Closes #1312

Co-authored-by: Marcus Spading <ms@fragmentum.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: variables Changes related to variables. type: bug Something not working as intended.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants