1
0
mirror of https://github.com/go-task/task.git synced 2025-11-23 22:24:45 +02:00

fix: do not re-evaluate variables for defer: (#2418)

This commit is contained in:
Timothy Rule
2025-11-11 19:50:01 +01:00
committed by GitHub
parent af1e755196
commit 0052ad2309

10
task.go
View File

@@ -210,7 +210,7 @@ func (e *Executor) RunTask(ctx context.Context, call *Call) error {
for i := range t.Cmds { for i := range t.Cmds {
if t.Cmds[i].Defer { if t.Cmds[i].Defer {
defer e.runDeferred(t, call, i, &deferredExitCode) defer e.runDeferred(t, call, i, t.Vars, &deferredExitCode)
continue continue
} }
@@ -277,17 +277,11 @@ func (e *Executor) runDeps(ctx context.Context, t *ast.Task) error {
return g.Wait() return g.Wait()
} }
func (e *Executor) runDeferred(t *ast.Task, call *Call, i int, deferredExitCode *uint8) { func (e *Executor) runDeferred(t *ast.Task, call *Call, i int, vars *ast.Vars, deferredExitCode *uint8) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
origTask, err := e.GetTask(call)
if err != nil {
return
}
cmd := t.Cmds[i] cmd := t.Cmds[i]
vars, _ := e.Compiler.GetVariables(origTask, call)
cache := &templater.Cache{Vars: vars} cache := &templater.Cache{Vars: vars}
extra := map[string]any{} extra := map[string]any{}