mirror of
https://github.com/go-task/task.git
synced 2025-11-25 22:32:55 +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
14
task.go
14
task.go
@@ -102,7 +102,7 @@ func (e *Executor) Run(args ...string) error {
|
||||
}
|
||||
|
||||
for _, a := range args {
|
||||
if err := e.RunTask(context.Background(), Call{Task: a, Vars: e.taskvars}); err != nil {
|
||||
if err := e.RunTask(context.Background(), Call{Task: a, Vars: nil}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -111,22 +111,20 @@ func (e *Executor) Run(args ...string) error {
|
||||
|
||||
// RunTask runs a task by its name
|
||||
func (e *Executor) RunTask(ctx context.Context, call Call) error {
|
||||
task, ok := e.Tasks[call.Task]
|
||||
origTask, ok := e.Tasks[call.Task]
|
||||
if !ok {
|
||||
return &taskNotFoundError{call.Task}
|
||||
}
|
||||
|
||||
if atomic.AddInt32(e.taskCallCount[call.Task], 1) >= MaximumTaskCall {
|
||||
return &MaximumTaskCallExceededError{task: call.Task}
|
||||
}
|
||||
|
||||
var err error
|
||||
call.Vars, err = e.getVariables(task, call)
|
||||
vars, err := e.getVariables(call)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t, err := task.ReplaceVariables(call.Vars)
|
||||
t, err := origTask.ReplaceVariables(vars)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -138,11 +136,11 @@ func (e *Executor) RunTask(ctx context.Context, call Call) error {
|
||||
// FIXME: doing again, since a var may have been overriden
|
||||
// using the `set:` attribute of a dependecy.
|
||||
// Remove this when `set` (that is deprecated) be removed
|
||||
call.Vars, err = e.getVariables(task, call)
|
||||
vars, err = e.getVariables(call)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t, err = task.ReplaceVariables(call.Vars)
|
||||
t, err = origTask.ReplaceVariables(vars)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user