mirror of
https://github.com/go-task/task.git
synced 2025-11-25 22:32:55 +02:00
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Improve performance of `--list` and `--summary` by skipping running shell
|
||||||
|
variables for these flags
|
||||||
|
([#332](https://github.com/go-task/task/issues/332)).
|
||||||
- Fixed a bug where an environment in a Taskfile was not always overridable
|
- Fixed a bug where an environment in a Taskfile was not always overridable
|
||||||
by the system environment
|
by the system environment
|
||||||
([#425](https://github.com/go-task/task/issues/425)).
|
([#425](https://github.com/go-task/task/issues/425)).
|
||||||
|
|||||||
2
help.go
2
help.go
@@ -30,7 +30,7 @@ func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) {
|
|||||||
tasks = make([]*taskfile.Task, 0, len(e.Taskfile.Tasks))
|
tasks = make([]*taskfile.Task, 0, len(e.Taskfile.Tasks))
|
||||||
for _, task := range e.Taskfile.Tasks {
|
for _, task := range e.Taskfile.Tasks {
|
||||||
if task.Desc != "" {
|
if task.Desc != "" {
|
||||||
compiledTask, err := e.CompiledTask(taskfile.Call{Task: task.Task})
|
compiledTask, err := e.FastCompiledTask(taskfile.Call{Task: task.Task})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
task = compiledTask
|
task = compiledTask
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
// E.g. variable merger, template processing, etc.
|
// E.g. variable merger, template processing, etc.
|
||||||
type Compiler interface {
|
type Compiler interface {
|
||||||
GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error)
|
GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error)
|
||||||
|
FastGetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error)
|
||||||
HandleDynamicVar(v taskfile.Var, dir string) (string, error)
|
HandleDynamicVar(v taskfile.Var, dir string) (string, error)
|
||||||
ResetCache()
|
ResetCache()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ type CompilerV2 struct {
|
|||||||
muDynamicCache sync.Mutex
|
muDynamicCache sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FastGetVariables is a no-op on v2
|
||||||
|
func (c *CompilerV2) FastGetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error) {
|
||||||
|
return c.GetVariables(t, call)
|
||||||
|
}
|
||||||
|
|
||||||
// GetVariables returns fully resolved variables following the priority order:
|
// GetVariables returns fully resolved variables following the priority order:
|
||||||
// 1. Task variables
|
// 1. Task variables
|
||||||
// 2. Call variables
|
// 2. Call variables
|
||||||
|
|||||||
@@ -30,6 +30,14 @@ type CompilerV3 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *CompilerV3) GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error) {
|
func (c *CompilerV3) GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error) {
|
||||||
|
return c.getVariables(t, call, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CompilerV3) FastGetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error) {
|
||||||
|
return c.getVariables(t, call, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CompilerV3) getVariables(t *taskfile.Task, call taskfile.Call, evaluateShVars bool) (*taskfile.Vars, error) {
|
||||||
result := compiler.GetEnviron()
|
result := compiler.GetEnviron()
|
||||||
result.Set("TASK", taskfile.Var{Static: t.Task})
|
result.Set("TASK", taskfile.Var{Static: t.Task})
|
||||||
|
|
||||||
@@ -37,6 +45,11 @@ func (c *CompilerV3) GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfi
|
|||||||
return func(k string, v taskfile.Var) error {
|
return func(k string, v taskfile.Var) error {
|
||||||
tr := templater.Templater{Vars: result, RemoveNoValue: true}
|
tr := templater.Templater{Vars: result, RemoveNoValue: true}
|
||||||
|
|
||||||
|
if !evaluateShVars {
|
||||||
|
result.Set(k, taskfile.Var{Static: tr.Replace(v.Static)})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
v = taskfile.Var{
|
v = taskfile.Var{
|
||||||
Static: tr.Replace(v.Static),
|
Static: tr.Replace(v.Static),
|
||||||
Sh: tr.Replace(v.Sh),
|
Sh: tr.Replace(v.Sh),
|
||||||
|
|||||||
2
task.go
2
task.go
@@ -71,7 +71,7 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
|
|||||||
|
|
||||||
if e.Summary {
|
if e.Summary {
|
||||||
for i, c := range calls {
|
for i, c := range calls {
|
||||||
compiledTask, err := e.CompiledTask(c)
|
compiledTask, err := e.FastCompiledTask(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
19
variables.go
19
variables.go
@@ -13,12 +13,27 @@ import (
|
|||||||
// CompiledTask returns a copy of a task, but replacing variables in almost all
|
// CompiledTask returns a copy of a task, but replacing variables in almost all
|
||||||
// properties using the Go template package.
|
// properties using the Go template package.
|
||||||
func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
||||||
|
return e.compiledTask(call, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FastCompiledTask is like CompiledTask, but it skippes dynamic variables.
|
||||||
|
func (e *Executor) FastCompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
||||||
|
return e.compiledTask(call, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Executor) compiledTask(call taskfile.Call, evaluateShVars bool) (*taskfile.Task, error) {
|
||||||
origTask, ok := e.Taskfile.Tasks[call.Task]
|
origTask, ok := e.Taskfile.Tasks[call.Task]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, &taskNotFoundError{call.Task}
|
return nil, &taskNotFoundError{call.Task}
|
||||||
}
|
}
|
||||||
|
|
||||||
vars, err := e.Compiler.GetVariables(origTask, call)
|
var vars *taskfile.Vars
|
||||||
|
var err error
|
||||||
|
if evaluateShVars {
|
||||||
|
vars, err = e.Compiler.GetVariables(origTask, call)
|
||||||
|
} else {
|
||||||
|
vars, err = e.Compiler.FastGetVariables(origTask, call)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -59,6 +74,7 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
|||||||
new.Env = &taskfile.Vars{}
|
new.Env = &taskfile.Vars{}
|
||||||
new.Env.Merge(r.ReplaceVars(e.Taskfile.Env))
|
new.Env.Merge(r.ReplaceVars(e.Taskfile.Env))
|
||||||
new.Env.Merge(r.ReplaceVars(origTask.Env))
|
new.Env.Merge(r.ReplaceVars(origTask.Env))
|
||||||
|
if evaluateShVars {
|
||||||
err = new.Env.Range(func(k string, v taskfile.Var) error {
|
err = new.Env.Range(func(k string, v taskfile.Var) error {
|
||||||
static, err := e.Compiler.HandleDynamicVar(v, new.Dir)
|
static, err := e.Compiler.HandleDynamicVar(v, new.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -70,6 +86,7 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(origTask.Cmds) > 0 {
|
if len(origTask.Cmds) > 0 {
|
||||||
new.Cmds = make([]*taskfile.Cmd, len(origTask.Cmds))
|
new.Cmds = make([]*taskfile.Cmd, len(origTask.Cmds))
|
||||||
|
|||||||
Reference in New Issue
Block a user