Skip to content

Commit 5eaf0b2

Browse files
authored
fix: interpolate dynamic vars in defer (#1818)
1 parent 56f3735 commit 5eaf0b2

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func (e *Executor) runDeferred(t *ast.Task, call *ast.Call, i int, deferredExitC
330330
}
331331

332332
cmd := t.Cmds[i]
333-
vars, _ := e.Compiler.FastGetVariables(origTask, call)
333+
vars, _ := e.Compiler.GetVariables(origTask, call)
334334
cache := &templater.Cache{Vars: vars}
335335
extra := map[string]any{}
336336

task_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ func TestExitCodeZero(t *testing.T) {
17881788
require.NoError(t, e.Setup())
17891789

17901790
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "exit-zero"}))
1791-
assert.Equal(t, "FOO=bar - EXIT_CODE=", strings.TrimSpace(buff.String()))
1791+
assert.Equal(t, "FOO=bar - DYNAMIC_FOO=bar - EXIT_CODE=", strings.TrimSpace(buff.String()))
17921792
}
17931793

17941794
func TestExitCodeOne(t *testing.T) {
@@ -1802,7 +1802,7 @@ func TestExitCodeOne(t *testing.T) {
18021802
require.NoError(t, e.Setup())
18031803

18041804
require.Error(t, e.Run(context.Background(), &ast.Call{Task: "exit-one"}))
1805-
assert.Equal(t, "FOO=bar - EXIT_CODE=1", strings.TrimSpace(buff.String()))
1805+
assert.Equal(t, "FOO=bar - DYNAMIC_FOO=bar - EXIT_CODE=1", strings.TrimSpace(buff.String()))
18061806
}
18071807

18081808
func TestIgnoreNilElements(t *testing.T) {

testdata/exit_code/Taskfile.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ tasks:
99
exit-zero:
1010
vars:
1111
FOO: bar
12+
DYNAMIC_FOO:
13+
sh: echo 'bar'
1214
cmds:
13-
- defer: echo FOO={{.FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
15+
- defer: echo FOO={{.FOO}} - DYNAMIC_FOO={{.DYNAMIC_FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
1416
- exit 0
1517

1618
exit-one:
1719
vars:
1820
FOO: bar
21+
DYNAMIC_FOO:
22+
sh: echo 'bar'
1923
cmds:
20-
- defer: echo FOO={{.FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
24+
- defer: echo FOO={{.FOO}} - DYNAMIC_FOO={{.DYNAMIC_FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
2125
- exit 1

0 commit comments

Comments
 (0)