1
0
mirror of https://github.com/go-task/task.git synced 2025-01-22 05:10:17 +02:00

fix: expand task-level dotenv in brackets

This commit is contained in:
Amin Yahyaabadi 2024-04-28 01:25:15 -07:00
parent cd259a741f
commit 4cb0450dee
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
3 changed files with 15 additions and 1 deletions

View File

@ -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",

View File

@ -8,6 +8,7 @@ tasks:
dotenv: ['.env']
cmds:
- echo "$FOO" > dotenv.txt
- echo "{{.FOO}}" > dotenv-2.txt
dotenv-overridden-by-env:
dotenv: ['.env']

View File

@ -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))
@ -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)