1
0
mirror of https://github.com/go-task/task.git synced 2025-03-05 15:05:42 +02:00

Environment from .env file should be available as variables

Fixes #379
This commit is contained in:
Andrey Nering 2021-01-12 11:09:46 -03:00
parent 1107f691ea
commit e086b654aa
6 changed files with 17 additions and 0 deletions

View File

@ -1,5 +1,10 @@
# Changelog
## Unreleased
- Fixed environment from .env files not being available as variables
([#379](https://github.com/go-task/task/issues/379)).
## v3.2.1
- Fixed some bugs and regressions regarding dynamic variables and directories

View File

@ -20,6 +20,7 @@ var _ compiler.Compiler = &CompilerV3{}
type CompilerV3 struct {
Dir string
TaskfileEnv *taskfile.Vars
TaskfileVars *taskfile.Vars
Logger *logger.Logger
@ -54,6 +55,9 @@ func (c *CompilerV3) GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfi
}
rangeFunc := getRangeFunc(c.Dir)
if err := c.TaskfileEnv.Range(rangeFunc); err != nil {
return nil, err
}
if err := c.TaskfileVars.Range(rangeFunc); err != nil {
return nil, err
}

View File

@ -168,6 +168,7 @@ func (e *Executor) Setup() error {
} else {
e.Compiler = &compilerv3.CompilerV3{
Dir: e.Dir,
TaskfileEnv: e.Taskfile.Env,
TaskfileVars: e.Taskfile.Vars,
Logger: e.Logger,
}

View File

@ -126,6 +126,7 @@ func TestVarsV3(t *testing.T) {
"var-order.txt": "ABCDEF\n",
"dependent-sh.txt": "123456\n",
"with-call.txt": "Hi, ABC123!\n",
"from-dot-env.txt": "From .env file\n",
},
}
tt.Run(t)

1
testdata/vars/v3/.env vendored Normal file
View File

@ -0,0 +1 @@
DOT_ENV_VAR=From .env file

View File

@ -1,5 +1,7 @@
version: '3'
dotenv: [.env]
vars:
VAR_A: A
VAR_B: '{{.VAR_A}}B'
@ -15,6 +17,7 @@ tasks:
- task: var-order
- task: dependent-sh
- task: with-call
- task: from-dot-env
missing-var: echo '{{.NON_EXISTING_VAR}}' > missing-var.txt
@ -44,3 +47,5 @@ tasks:
MESSAGE: Hi, {{.ABC123}}!
cmds:
- echo "{{.MESSAGE}}" > with-call.txt
from-dot-env: echo '{{.DOT_ENV_VAR}}' > from-dot-env.txt