Skip to content

Commit e086b65

Browse files
committed
Environment from .env file should be available as variables
Fixes #379
1 parent 1107f69 commit e086b65

File tree

6 files changed

+17
-0
lines changed

6 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Fixed environment from .env files not being available as variables
6+
([#379](https://github.com/go-task/task/issues/379)).
7+
38
## v3.2.1
49

510
- Fixed some bugs and regressions regarding dynamic variables and directories

internal/compiler/v3/compiler_v3.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var _ compiler.Compiler = &CompilerV3{}
2020
type CompilerV3 struct {
2121
Dir string
2222

23+
TaskfileEnv *taskfile.Vars
2324
TaskfileVars *taskfile.Vars
2425

2526
Logger *logger.Logger
@@ -54,6 +55,9 @@ func (c *CompilerV3) GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfi
5455
}
5556
rangeFunc := getRangeFunc(c.Dir)
5657

58+
if err := c.TaskfileEnv.Range(rangeFunc); err != nil {
59+
return nil, err
60+
}
5761
if err := c.TaskfileVars.Range(rangeFunc); err != nil {
5862
return nil, err
5963
}

task.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ func (e *Executor) Setup() error {
168168
} else {
169169
e.Compiler = &compilerv3.CompilerV3{
170170
Dir: e.Dir,
171+
TaskfileEnv: e.Taskfile.Env,
171172
TaskfileVars: e.Taskfile.Vars,
172173
Logger: e.Logger,
173174
}

task_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func TestVarsV3(t *testing.T) {
126126
"var-order.txt": "ABCDEF\n",
127127
"dependent-sh.txt": "123456\n",
128128
"with-call.txt": "Hi, ABC123!\n",
129+
"from-dot-env.txt": "From .env file\n",
129130
},
130131
}
131132
tt.Run(t)

testdata/vars/v3/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DOT_ENV_VAR=From .env file

testdata/vars/v3/Taskfile.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
version: '3'
22

3+
dotenv: [.env]
4+
35
vars:
46
VAR_A: A
57
VAR_B: '{{.VAR_A}}B'
@@ -15,6 +17,7 @@ tasks:
1517
- task: var-order
1618
- task: dependent-sh
1719
- task: with-call
20+
- task: from-dot-env
1821

1922
missing-var: echo '{{.NON_EXISTING_VAR}}' > missing-var.txt
2023

@@ -44,3 +47,5 @@ tasks:
4447
MESSAGE: Hi, {{.ABC123}}!
4548
cmds:
4649
- echo "{{.MESSAGE}}" > with-call.txt
50+
51+
from-dot-env: echo '{{.DOT_ENV_VAR}}' > from-dot-env.txt

0 commit comments

Comments
 (0)