mirror of
https://github.com/go-task/task.git
synced 2025-05-17 22:32:40 +02:00
fix: advanced import operates on including file instead of included file
This commit is contained in:
parent
8f3180a9fa
commit
e9448bd4be
@ -178,7 +178,7 @@ func run() error {
|
||||
|
||||
globals.Set("CLI_ARGS", ast.Var{Value: cliArgs})
|
||||
globals.Set("CLI_FORCE", ast.Var{Value: flags.Force || flags.ForceAll})
|
||||
e.Taskfile.Vars.Merge(globals)
|
||||
e.Taskfile.Vars.Merge(globals, nil)
|
||||
|
||||
if !flags.Watch {
|
||||
e.InterceptInterruptSignals()
|
||||
|
@ -7,8 +7,6 @@ import (
|
||||
"github.com/dominikbraun/graph"
|
||||
"github.com/dominikbraun/graph/draw"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/go-task/task/v3/internal/filepathext"
|
||||
)
|
||||
|
||||
type TaskfileGraph struct {
|
||||
@ -88,31 +86,6 @@ func (tfg *TaskfileGraph) Merge() (*Taskfile, error) {
|
||||
return fmt.Errorf("task: Failed to get merge options")
|
||||
}
|
||||
|
||||
// Handle advanced imports
|
||||
// i.e. where additional data is given when a Taskfile is included
|
||||
if include.AdvancedImport {
|
||||
includedVertex.Taskfile.Vars.Range(func(k string, v Var) error {
|
||||
o := v
|
||||
o.Dir = include.Dir
|
||||
includedVertex.Taskfile.Vars.Set(k, o)
|
||||
return nil
|
||||
})
|
||||
includedVertex.Taskfile.Env.Range(func(k string, v Var) error {
|
||||
o := v
|
||||
o.Dir = include.Dir
|
||||
includedVertex.Taskfile.Env.Set(k, o)
|
||||
return nil
|
||||
})
|
||||
for _, task := range includedVertex.Taskfile.Tasks.Values() {
|
||||
task.Dir = filepathext.SmartJoin(include.Dir, task.Dir)
|
||||
if task.IncludeVars == nil {
|
||||
task.IncludeVars = &Vars{}
|
||||
}
|
||||
task.IncludeVars.Merge(include.Vars)
|
||||
task.IncludedTaskfileVars = vertex.Taskfile.Vars
|
||||
}
|
||||
}
|
||||
|
||||
// Merge the included Taskfile into the parent Taskfile
|
||||
if err := vertex.Taskfile.Merge(
|
||||
includedVertex.Taskfile,
|
||||
|
@ -52,9 +52,9 @@ func (t1 *Taskfile) Merge(t2 *Taskfile, include *Include) error {
|
||||
if t1.Env == nil {
|
||||
t1.Env = &Vars{}
|
||||
}
|
||||
t1.Vars.Merge(t2.Vars)
|
||||
t1.Env.Merge(t2.Env)
|
||||
t1.Tasks.Merge(t2.Tasks, include)
|
||||
t1.Vars.Merge(t2.Vars, include)
|
||||
t1.Env.Merge(t2.Env, include)
|
||||
t1.Tasks.Merge(t2.Tasks, include, t1.Vars)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/go-task/task/v3/internal/filepathext"
|
||||
"github.com/go-task/task/v3/internal/omap"
|
||||
)
|
||||
|
||||
@ -44,7 +45,7 @@ func (t *Tasks) FindMatchingTasks(call *Call) []*MatchingTask {
|
||||
return matchingTasks
|
||||
}
|
||||
|
||||
func (t1 *Tasks) Merge(t2 Tasks, include *Include) {
|
||||
func (t1 *Tasks) Merge(t2 Tasks, include *Include, includedTaskfileVars *Vars) {
|
||||
_ = t2.Range(func(k string, v *Task) error {
|
||||
// We do a deep copy of the task struct here to ensure that no data can
|
||||
// be changed elsewhere once the taskfile is merged.
|
||||
@ -83,6 +84,15 @@ func (t1 *Tasks) Merge(t2 Tasks, include *Include) {
|
||||
}
|
||||
}
|
||||
|
||||
if include.AdvancedImport {
|
||||
task.Dir = filepathext.SmartJoin(include.Dir, task.Dir)
|
||||
if task.IncludeVars == nil {
|
||||
task.IncludeVars = &Vars{}
|
||||
}
|
||||
task.IncludeVars.Merge(include.Vars, nil)
|
||||
task.IncludedTaskfileVars = includedTaskfileVars
|
||||
}
|
||||
|
||||
// Add the task to the merged taskfile
|
||||
taskNameWithNamespace := taskNameWithNamespace(k, include.Namespace)
|
||||
task.Task = taskNameWithNamespace
|
||||
|
@ -45,11 +45,17 @@ func (vs *Vars) Range(f func(k string, v Var) error) error {
|
||||
}
|
||||
|
||||
// Wrapper around OrderedMap.Merge to ensure we don't get nil pointer errors
|
||||
func (vs *Vars) Merge(other *Vars) {
|
||||
func (vs *Vars) Merge(other *Vars, include *Include) {
|
||||
if vs == nil || other == nil {
|
||||
return
|
||||
}
|
||||
vs.OrderedMap.Merge(other.OrderedMap)
|
||||
other.Range(func(key string, value Var) error {
|
||||
if include != nil && include.AdvancedImport {
|
||||
value.Dir = include.Dir
|
||||
}
|
||||
vs.Set(key, value)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Wrapper around OrderedMap.Len to ensure we don't get nil pointer errors
|
||||
|
@ -104,9 +104,9 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task,
|
||||
}
|
||||
|
||||
new.Env = &ast.Vars{}
|
||||
new.Env.Merge(templater.ReplaceVars(e.Taskfile.Env, cache))
|
||||
new.Env.Merge(templater.ReplaceVars(dotenvEnvs, cache))
|
||||
new.Env.Merge(templater.ReplaceVars(origTask.Env, cache))
|
||||
new.Env.Merge(templater.ReplaceVars(e.Taskfile.Env, cache), nil)
|
||||
new.Env.Merge(templater.ReplaceVars(dotenvEnvs, cache), nil)
|
||||
new.Env.Merge(templater.ReplaceVars(origTask.Env, cache), nil)
|
||||
if evaluateShVars {
|
||||
err = new.Env.Range(func(k string, v ast.Var) error {
|
||||
// If the variable is not dynamic, we can set it and return
|
||||
|
Loading…
x
Reference in New Issue
Block a user