Skip to content

Commit

Permalink
Environment from .env file should be available as variables
Browse files Browse the repository at this point in the history
Fixes #379
  • Loading branch information
andreynering committed Jan 12, 2021
1 parent 1107f69 commit e086b65
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions internal/compiler/v3/compiler_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var _ compiler.Compiler = &CompilerV3{}
type CompilerV3 struct {
Dir string

TaskfileEnv *taskfile.Vars
TaskfileVars *taskfile.Vars

Logger *logger.Logger
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions testdata/vars/v3/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DOT_ENV_VAR=From .env file
5 changes: 5 additions & 0 deletions testdata/vars/v3/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
version: '3'

dotenv: [.env]

vars:
VAR_A: A
VAR_B: '{{.VAR_A}}B'
Expand All @@ -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

Expand Down Expand Up @@ -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

0 comments on commit e086b65

Please sign in to comment.