Open JonZeolla opened 1 year ago
I was hopeful that reordering the Taskfile.yml
to put vars
before the includes
section but that didn't work either.
In doing more testing, it seems that the problem is that includes
may be running before vars
. Here's a test diff which shows the issue:
diff --git a/testdata/include_with_vars/Taskfile.yml b/testdata/include_with_vars/Taskfile.yml
index aee8f51..96c799a 100644
--- a/testdata/include_with_vars/Taskfile.yml
+++ b/testdata/include_with_vars/Taskfile.yml
@@ -1,5 +1,8 @@
version: "3"
+vars:
+ VAR_2: included2-var2
+
includes:
included1:
taskfile: include/Taskfile.include.yml
@@ -9,6 +12,7 @@ includes:
taskfile: include/Taskfile.include.yml
vars:
VAR_1: included2-var1
+ VAR_2: '{{.VAR_2}}'
included3:
taskfile: include/Taskfile.include.yml
diff --git a/testdata/include_with_vars/include/Taskfile.include.yml b/testdata/include_with_vars/include/Taskfile.include.yml
index 3bb7a68..f902f91 100644
--- a/testdata/include_with_vars/include/Taskfile.include.yml
+++ b/testdata/include_with_vars/include/Taskfile.include.yml
@@ -2,7 +2,8 @@ version: "3"
vars:
VAR_1: '{{.VAR_1 | default "included-default-var1"}}'
- VAR_2: '{{.VAR_2 | default "included-default-var2"}}'
+ VAR_2:
+ sh: 'echo {{.VAR_2 | default "included-default-var2"}}'
tasks:
task1:
And this one works as expected:
diff --git a/testdata/include_with_vars/Taskfile.yml b/testdata/include_with_vars/Taskfile.yml
index aee8f51..aa3ecb4 100644
--- a/testdata/include_with_vars/Taskfile.yml
+++ b/testdata/include_with_vars/Taskfile.yml
@@ -9,6 +9,7 @@ includes:
taskfile: include/Taskfile.include.yml
vars:
VAR_1: included2-var1
+ VAR_2: included2-var2
included3:
taskfile: include/Taskfile.include.yml
diff --git a/testdata/include_with_vars/include/Taskfile.include.yml b/testdata/include_with_vars/include/Taskfile.include.yml
index 3bb7a68..f902f91 100644
--- a/testdata/include_with_vars/include/Taskfile.include.yml
+++ b/testdata/include_with_vars/include/Taskfile.include.yml
@@ -2,7 +2,8 @@ version: "3"
vars:
VAR_1: '{{.VAR_1 | default "included-default-var1"}}'
- VAR_2: '{{.VAR_2 | default "included-default-var2"}}'
+ VAR_2:
+ sh: 'echo {{.VAR_2 | default "included-default-var2"}}'
tasks:
task1:
This was also unexpected (with the below patch). I expected bar:lib:greet
to be Hello bar_local
but want it to be Hello bar_global
:
$ go run ./cmd/task --dir ./testdata/include_with_vars_multi_level default
task: [lib:greet] echo 'Hello world'
Hello world
task: [foo:lib:greet] echo 'Hello foo'
Hello foo
task: [bar:lib:greet] echo 'Hello world'
Hello world
diff --git a/testdata/include_with_vars_multi_level/bar/Taskfile.yml b/testdata/include_with_vars_multi_level/bar/Taskfile.yml
index f280f3f..b2495bb 100644
--- a/testdata/include_with_vars_multi_level/bar/Taskfile.yml
+++ b/testdata/include_with_vars_multi_level/bar/Taskfile.yml
@@ -1,7 +1,10 @@
version: "3"
+vars:
+ RECEIVER: 'bar_global'
+
includes:
lib:
taskfile: ../lib/Taskfile.yml
vars:
- RECEIVER: "bar"
+ RECEIVER: '{{.RECEIVER | default "bar_local"}}'
Still an issue as of 3.36.0
I expected the included taskfile to exit 1 because it uses the passed
CODE
var that was passed to it, but it seems to be unset and uses thedefault
instead.Taskfile.yml
:Taskfile.included.yml
:Expected output
Actual output