1
0
mirror of https://github.com/go-task/task.git synced 2025-08-08 22:36:57 +02:00

fix: interpolate vars in defer (#2173)

This commit is contained in:
Valentin Maerten
2025-04-21 18:43:20 +02:00
committed by GitHub
parent 84cd4dfdad
commit 7169bf6434
3 changed files with 20 additions and 0 deletions

View File

@@ -297,6 +297,8 @@ func (e *Executor) runDeferred(t *ast.Task, call *Call, i int, deferredExitCode
}
cmd.Cmd = templater.ReplaceWithExtra(cmd.Cmd, cache, extra)
cmd.Task = templater.ReplaceWithExtra(cmd.Task, cache, extra)
cmd.Vars = templater.ReplaceVarsWithExtra(cmd.Vars, cache, extra)
if err := e.runCommand(ctx, t, call, i); err != nil {
e.Logger.VerboseErrf(logger.Yellow, "task: ignored error in deferred cmd: %s\n", err.Error())

View File

@@ -1809,6 +1809,9 @@ task-1 ran successfully
`)
require.Error(t, e.Run(context.Background(), &task.Call{Task: "task-2"}))
assert.Contains(t, buff.String(), expectedOutputOrder)
buff.Reset()
require.NoError(t, e.Run(context.Background(), &task.Call{Task: "parent"}))
assert.Contains(t, buff.String(), "child task deferred value-from-parent")
}
func TestExitCodeZero(t *testing.T) {

View File

@@ -12,3 +12,18 @@ tasks:
- defer: echo 'failing' && exit 2
- echo 'cmd ran'
- exit 1
parent:
vars:
VAR1: "value-from-parent"
cmds:
- defer:
task: child
vars:
VAR1: 'task deferred {{.VAR1}}'
- task: child
vars:
VAR1: 'task immediate {{.VAR1}}'
child:
cmds:
- cmd: echo "child {{.VAR1}}"