mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
Reintroduce template evaluation in variables
With a recent commit, template evaluation for variables in tasks got broken. This reindroudces temmplate evaluation in taks, and resolves a series of issues that where previouisly present on master, such as: - Taskvars did not get evaluated as templates. - Taskvars would, in contrast to the documentation, _override_ task variables for the taks called directly via `Executor.Run(args ...string)`. This caused different behaviour in the "default" task v.s. other tasks. This commit ensures: - Priority order for variables is now according to the documentation, also for the "default" task. - Variables gets resolved in a particular order to ensure logical access to varaibles on template compile time, and that template compilation finds place _before_ resolution of dynamic variables. This change also allows the following to work: task: vars: A: "52" B: "{{.A}}" However, the following will always replace C with the uncompiled `{{.A}}`: task: vars: A: "52" C: "{{.B}}" B: "{{.A}}" Several tests have also been added to prevent this feature from breaking again. This should hopefully finally resolve issue #40.
This commit is contained in:
committed by
Sindre Røkenes Myren
parent
55672410cd
commit
31faf05c3a
13
testdata/params/Taskfile.yml
vendored
13
testdata/params/Taskfile.yml
vendored
@@ -1,7 +1,8 @@
|
||||
default:
|
||||
vars:
|
||||
SPANISH: ¡Holla mundo!
|
||||
PORTUGUESE: "{{.PORTUGUESE}}"
|
||||
PORTUGUESE: "{{.PORTUGUESE_HELLO_WORLD}}"
|
||||
GERMAN: "Welt!"
|
||||
deps:
|
||||
- task: write-file
|
||||
vars: {CONTENT: Dependence1, FILE: dep1.txt}
|
||||
@@ -20,7 +21,17 @@ default:
|
||||
vars: {CONTENT: "{{.SPANISH}}", FILE: spanish.txt}
|
||||
- task: write-file
|
||||
vars: {CONTENT: "{{.PORTUGUESE}}", FILE: portuguese.txt}
|
||||
- task: write-file
|
||||
vars: {CONTENT: "{{.GERMAN}}", FILE: german.txt}
|
||||
- task: non-default
|
||||
|
||||
write-file:
|
||||
cmds:
|
||||
- echo {{.CONTENT}} > {{.FILE}}
|
||||
|
||||
non-default:
|
||||
vars:
|
||||
PORTUGUESE: "{{.PORTUGUESE_HELLO_WORLD}}"
|
||||
cmds:
|
||||
- task: write-file
|
||||
vars: {CONTENT: "{{.PORTUGUESE}}", FILE: portuguese2.txt}
|
||||
|
3
testdata/params/Taskvars.yml
vendored
3
testdata/params/Taskvars.yml
vendored
@@ -1 +1,2 @@
|
||||
PORTUGUESE: Olá, mundo!
|
||||
PORTUGUESE_HELLO_WORLD: Olá, mundo!
|
||||
GERMAN: "Hello"
|
||||
|
32
testdata/vars/Taskfile.yml
vendored
32
testdata/vars/Taskfile.yml
vendored
@@ -7,17 +7,49 @@ hello:
|
||||
- echo {{.FOO}} > foo.txt
|
||||
- echo {{.BAR}} > bar.txt
|
||||
- echo {{.BAZ}} > baz.txt
|
||||
- echo '{{.TMPL_FOO}}' > tmpl_foo.txt
|
||||
- echo '{{.TMPL_BAR}}' > tmpl_bar.txt
|
||||
- echo '{{.TMPL_FOO2}}' > tmpl_foo2.txt
|
||||
- echo '{{.TMPL_BAR2}}' > tmpl_bar2.txt
|
||||
- echo '{{.SHTMPL_FOO}}' > shtmpl_foo.txt
|
||||
- echo '{{.SHTMPL_FOO2}}' > shtmpl_foo2.txt
|
||||
- echo '{{.NESTEDTMPL_FOO}}' > nestedtmpl_foo.txt
|
||||
- echo '{{.NESTEDTMPL_FOO2}}' > nestedtmpl_foo2.txt
|
||||
- echo {{.FOO2}} > foo2.txt
|
||||
- echo {{.BAR2}} > bar2.txt
|
||||
- echo {{.BAZ2}} > baz2.txt
|
||||
- echo '{{.TMPL2_FOO}}' > tmpl2_foo.txt
|
||||
- echo '{{.TMPL2_BAR}}' > tmpl2_bar.txt
|
||||
- echo '{{.TMPL2_FOO2}}' > tmpl2_foo2.txt
|
||||
- echo '{{.TMPL2_BAR2}}' > tmpl2_bar2.txt
|
||||
- echo '{{.SHTMPL2_FOO}}' > shtmpl2_foo.txt
|
||||
- echo '{{.SHTMPL2_FOO2}}' > shtmpl2_foo2.txt
|
||||
- echo '{{.NESTEDTMPL2_FOO2}}' > nestedtmpl2_foo2.txt
|
||||
- echo {{.EQUAL}} > equal.txt
|
||||
- echo {{.OVERRIDE}} > override.txt
|
||||
vars:
|
||||
FOO: foo
|
||||
BAR: $echo bar
|
||||
BAZ:
|
||||
sh: echo baz
|
||||
TMPL_FOO: "{{.FOO}}"
|
||||
TMPL_BAR: "{{.BAR}}"
|
||||
TMPL_FOO2: "{{.FOO2}}"
|
||||
TMPL_BAR2: "{{.BAR2}}"
|
||||
SHTMPL_FOO:
|
||||
sh: "echo '{{.FOO}}'"
|
||||
SHTMPL_FOO2:
|
||||
sh: "echo '{{.FOO2}}'"
|
||||
NESTEDTMPL_FOO: "{{.TMPL_FOO}}"
|
||||
NESTEDTMPL_FOO2: "{{.TMPL2_FOO2}}"
|
||||
OVERRIDE: "bar"
|
||||
|
||||
set-equal:
|
||||
set: EQUAL
|
||||
cmds:
|
||||
- echo foo=bar
|
||||
|
||||
invalid-var-tmpl:
|
||||
vars:
|
||||
CHARS: "abcd"
|
||||
INVALID: "{{range .CHARS}}no end"
|
||||
|
8
testdata/vars/Taskvars.yml
vendored
8
testdata/vars/Taskvars.yml
vendored
@@ -2,3 +2,11 @@ FOO2: foo2
|
||||
BAR2: $echo bar2
|
||||
BAZ2:
|
||||
sh: echo baz2
|
||||
TMPL2_FOO: "{{.FOO}}"
|
||||
TMPL2_BAR: "{{.BAR}}"
|
||||
TMPL2_FOO2: "{{.FOO2}}"
|
||||
TMPL2_BAR2: "{{.BAR2}}"
|
||||
SHTMPL2_FOO2:
|
||||
sh: "echo '{{.FOO2}}'"
|
||||
NESTEDTMPL2_FOO2: "{{.TMPL2_FOO2}}"
|
||||
OVERRIDE: "foo"
|
||||
|
Reference in New Issue
Block a user