1
0
mirror of https://github.com/go-task/task.git synced 2024-12-12 10:45:49 +02:00

fix: interpolate dynamic vars in defer (#1818)

This commit is contained in:
Valentin Maerten 2024-09-19 14:22:39 +02:00 committed by GitHub
parent 56f3735b38
commit 5eaf0b2dcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 5 deletions

View File

@ -330,7 +330,7 @@ func (e *Executor) runDeferred(t *ast.Task, call *ast.Call, i int, deferredExitC
}
cmd := t.Cmds[i]
vars, _ := e.Compiler.FastGetVariables(origTask, call)
vars, _ := e.Compiler.GetVariables(origTask, call)
cache := &templater.Cache{Vars: vars}
extra := map[string]any{}

View File

@ -1788,7 +1788,7 @@ func TestExitCodeZero(t *testing.T) {
require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "exit-zero"}))
assert.Equal(t, "FOO=bar - EXIT_CODE=", strings.TrimSpace(buff.String()))
assert.Equal(t, "FOO=bar - DYNAMIC_FOO=bar - EXIT_CODE=", strings.TrimSpace(buff.String()))
}
func TestExitCodeOne(t *testing.T) {
@ -1802,7 +1802,7 @@ func TestExitCodeOne(t *testing.T) {
require.NoError(t, e.Setup())
require.Error(t, e.Run(context.Background(), &ast.Call{Task: "exit-one"}))
assert.Equal(t, "FOO=bar - EXIT_CODE=1", strings.TrimSpace(buff.String()))
assert.Equal(t, "FOO=bar - DYNAMIC_FOO=bar - EXIT_CODE=1", strings.TrimSpace(buff.String()))
}
func TestIgnoreNilElements(t *testing.T) {

View File

@ -9,13 +9,17 @@ tasks:
exit-zero:
vars:
FOO: bar
DYNAMIC_FOO:
sh: echo 'bar'
cmds:
- defer: echo FOO={{.FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
- defer: echo FOO={{.FOO}} - DYNAMIC_FOO={{.DYNAMIC_FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
- exit 0
exit-one:
vars:
FOO: bar
DYNAMIC_FOO:
sh: echo 'bar'
cmds:
- defer: echo FOO={{.FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
- defer: echo FOO={{.FOO}} - DYNAMIC_FOO={{.DYNAMIC_FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
- exit 1