1
0
mirror of https://github.com/go-task/task.git synced 2025-01-20 04:59:37 +02:00

fix: propagate include vars in multi-level includes (#1256)

This commit is contained in:
Hudson Clark 2023-07-08 08:42:38 -06:00 committed by GitHub
parent 2a0c99b5d8
commit 8a0689328b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 1 deletions

View File

@ -1798,6 +1798,29 @@ VAR_2 is included-default-var2
assert.Equal(t, strings.TrimSpace(buff.String()), expectedOutputOrder)
}
func TestIncludedVarsMultiLevel(t *testing.T) {
const dir = "testdata/include_with_vars_multi_level"
var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
}
require.NoError(t, e.Setup())
expectedOutputOrder := strings.TrimSpace(`
task: [lib:greet] echo 'Hello world'
Hello world
task: [foo:lib:greet] echo 'Hello foo'
Hello foo
task: [bar:lib:greet] echo 'Hello bar'
Hello bar
`)
require.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "default"}))
t.Log(buff.String())
assert.Equal(t, strings.TrimSpace(buff.String()), expectedOutputOrder)
}
func TestErrorCode(t *testing.T) {
const dir = "testdata/error_code"

View File

@ -149,7 +149,10 @@ func Taskfile(readerNode *ReaderNode) (*taskfile.Taskfile, string, error) {
for _, task := range includedTaskfile.Tasks.Values() {
task.Dir = filepathext.SmartJoin(dir, task.Dir)
task.IncludeVars = includedTask.Vars
if task.IncludeVars == nil {
task.IncludeVars = &taskfile.Vars{}
}
task.IncludeVars.Merge(includedTask.Vars)
task.IncludedTaskfileVars = includedTaskfile.Vars
task.IncludedTaskfile = &includedTask
}

View File

@ -0,0 +1,17 @@
version: "3"
includes:
lib:
taskfile: lib/Taskfile.yml
internal: true
foo:
taskfile: foo/Taskfile.yml
bar:
taskfile: bar/Taskfile.yml
tasks:
default:
cmds:
- task: lib:greet
- task: foo:lib:greet
- task: bar:lib:greet

View File

@ -0,0 +1,7 @@
version: "3"
includes:
lib:
taskfile: ../lib/Taskfile.yml
vars:
RECEIVER: "bar"

View File

@ -0,0 +1,7 @@
version: "3"
includes:
lib:
taskfile: ../lib/Taskfile.yml
vars:
RECEIVER: "foo"

View File

@ -0,0 +1,9 @@
version: "3"
vars:
RECEIVER: "world"
tasks:
greet:
cmds:
- echo 'Hello {{.RECEIVER}}'