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:
parent
56f3735b38
commit
5eaf0b2dcd
2
task.go
2
task.go
@ -330,7 +330,7 @@ func (e *Executor) runDeferred(t *ast.Task, call *ast.Call, i int, deferredExitC
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd := t.Cmds[i]
|
cmd := t.Cmds[i]
|
||||||
vars, _ := e.Compiler.FastGetVariables(origTask, call)
|
vars, _ := e.Compiler.GetVariables(origTask, call)
|
||||||
cache := &templater.Cache{Vars: vars}
|
cache := &templater.Cache{Vars: vars}
|
||||||
extra := map[string]any{}
|
extra := map[string]any{}
|
||||||
|
|
||||||
|
@ -1788,7 +1788,7 @@ func TestExitCodeZero(t *testing.T) {
|
|||||||
require.NoError(t, e.Setup())
|
require.NoError(t, e.Setup())
|
||||||
|
|
||||||
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "exit-zero"}))
|
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) {
|
func TestExitCodeOne(t *testing.T) {
|
||||||
@ -1802,7 +1802,7 @@ func TestExitCodeOne(t *testing.T) {
|
|||||||
require.NoError(t, e.Setup())
|
require.NoError(t, e.Setup())
|
||||||
|
|
||||||
require.Error(t, e.Run(context.Background(), &ast.Call{Task: "exit-one"}))
|
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) {
|
func TestIgnoreNilElements(t *testing.T) {
|
||||||
|
8
testdata/exit_code/Taskfile.yml
vendored
8
testdata/exit_code/Taskfile.yml
vendored
@ -9,13 +9,17 @@ tasks:
|
|||||||
exit-zero:
|
exit-zero:
|
||||||
vars:
|
vars:
|
||||||
FOO: bar
|
FOO: bar
|
||||||
|
DYNAMIC_FOO:
|
||||||
|
sh: echo 'bar'
|
||||||
cmds:
|
cmds:
|
||||||
- defer: echo FOO={{.FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
|
- defer: echo FOO={{.FOO}} - DYNAMIC_FOO={{.DYNAMIC_FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
|
||||||
- exit 0
|
- exit 0
|
||||||
|
|
||||||
exit-one:
|
exit-one:
|
||||||
vars:
|
vars:
|
||||||
FOO: bar
|
FOO: bar
|
||||||
|
DYNAMIC_FOO:
|
||||||
|
sh: echo 'bar'
|
||||||
cmds:
|
cmds:
|
||||||
- defer: echo FOO={{.FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
|
- defer: echo FOO={{.FOO}} - DYNAMIC_FOO={{.DYNAMIC_FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
|
||||||
- exit 1
|
- exit 1
|
||||||
|
Loading…
Reference in New Issue
Block a user