Skip to content

Commit

Permalink
fix: expand task-level dotenv in brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed May 3, 2024
1 parent cd259a7 commit 4cb0450
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,18 @@ func TestTaskDotenv(t *testing.T) {
tt.Run(t)
}

func TestTaskDotenvWithBrackets(t *testing.T) {
tt := fileContentTest{
Dir: "testdata/dotenv_task/default",
Target: "dotenv",
TrimSpace: true,
Files: map[string]string{
"dotenv-2.txt": "foo",
},
}
tt.Run(t)
}

func TestTaskDotenvFail(t *testing.T) {
tt := fileContentTest{
Dir: "testdata/dotenv_task/default",
Expand Down
1 change: 1 addition & 0 deletions testdata/dotenv_task/default/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tasks:
dotenv: ['.env']
cmds:
- echo "$FOO" > dotenv.txt
- echo "{{.FOO}}" > dotenv-2.txt

dotenv-overridden-by-env:
dotenv: ['.env']
Expand Down
3 changes: 2 additions & 1 deletion variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task,
return nil, err
}
}
envCache := new.Env.ToCacheMap()

if len(origTask.Cmds) > 0 {
new.Cmds = make([]*ast.Cmd, 0, len(origTask.Cmds))
Expand Down Expand Up @@ -161,7 +162,7 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task,
continue
}
newCmd := cmd.DeepCopy()
newCmd.Cmd = templater.Replace(cmd.Cmd, cache)
newCmd.Cmd = templater.ReplaceWithExtra(cmd.Cmd, cache, envCache)
newCmd.Task = templater.Replace(cmd.Task, cache)
newCmd.Vars = templater.ReplaceVars(cmd.Vars, cache)
new.Cmds = append(new.Cmds, newCmd)
Expand Down

0 comments on commit 4cb0450

Please sign in to comment.