Skip to content

Commit 725f929

Browse files
authored
fix: included variable merging (#1649)
1 parent 8266b28 commit 725f929

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

task_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,34 @@ func TestIncludesInterpolation(t *testing.T) {
12371237
}
12381238
}
12391239

1240+
func TestIncludedTaskfileVarMerging(t *testing.T) {
1241+
const dir = "testdata/included_taskfile_var_merging"
1242+
tests := []struct {
1243+
name string
1244+
task string
1245+
expectedOutput string
1246+
}{
1247+
{"foo", "foo:pwd", "included_taskfile_var_merging/foo\n"},
1248+
{"bar", "bar:pwd", "included_taskfile_var_merging/bar\n"},
1249+
}
1250+
for _, test := range tests {
1251+
t.Run(test.name, func(t *testing.T) {
1252+
var buff bytes.Buffer
1253+
e := task.Executor{
1254+
Dir: dir,
1255+
Stdout: &buff,
1256+
Stderr: &buff,
1257+
Silent: true,
1258+
}
1259+
require.NoError(t, e.Setup())
1260+
1261+
err := e.Run(context.Background(), &ast.Call{Task: test.task})
1262+
require.NoError(t, err)
1263+
assert.Contains(t, buff.String(), test.expectedOutput)
1264+
})
1265+
}
1266+
}
1267+
12401268
func TestInternalTask(t *testing.T) {
12411269
const dir = "testdata/internal_task"
12421270
tests := []struct {

taskfile/ast/tasks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (t1 *Tasks) Merge(t2 Tasks, include *Include, includedTaskfileVars *Vars) {
9090
task.IncludeVars = &Vars{}
9191
}
9292
task.IncludeVars.Merge(include.Vars, nil)
93-
task.IncludedTaskfileVars = includedTaskfileVars
93+
task.IncludedTaskfileVars = includedTaskfileVars.DeepCopy()
9494
}
9595

9696
// Add the task to the merged taskfile
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: "3"
2+
3+
includes:
4+
foo:
5+
taskfile: ./foo/Taskfile.yaml
6+
bar:
7+
taskfile: ./bar/Taskfile.yaml
8+
9+
tasks:
10+
stub:
11+
cmds:
12+
- echo 0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3"
2+
3+
vars:
4+
DIR: bar
5+
6+
tasks:
7+
pwd:
8+
dir: ./{{ .DIR }}
9+
cmds:
10+
- echo "{{ .DIR }}"
11+
- pwd
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3"
2+
3+
vars:
4+
DIR: foo
5+
6+
tasks:
7+
pwd:
8+
dir: ./{{ .DIR }}
9+
cmds:
10+
- echo "{{ .DIR }}"
11+
- pwd

0 commit comments

Comments
 (0)