mirror of
https://github.com/go-task/task.git
synced 2025-12-16 19:57:43 +01:00
fix(interactive): collect vars before checking visited to handle duplicate task calls
This commit is contained in:
17
requires.go
17
requires.go
@@ -17,19 +17,13 @@ func (e *Executor) collectAllRequiredVars(calls []*Call) ([]*ast.VarsWithValidat
|
|||||||
|
|
||||||
var collect func(call *Call) error
|
var collect func(call *Call) error
|
||||||
collect = func(call *Call) error {
|
collect = func(call *Call) error {
|
||||||
// Avoid infinite loops
|
// Always compile to resolve variables (also fetches the task)
|
||||||
if visited[call.Task] {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
visited[call.Task] = true
|
|
||||||
|
|
||||||
// Compile to resolve variables (also fetches the task)
|
|
||||||
compiledTask, err := e.FastCompiledTask(call)
|
compiledTask, err := e.FastCompiledTask(call)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect required vars from this task
|
// Always collect required vars from this task
|
||||||
if compiledTask.Requires != nil {
|
if compiledTask.Requires != nil {
|
||||||
for _, v := range compiledTask.Requires.Vars {
|
for _, v := range compiledTask.Requires.Vars {
|
||||||
// Check if var is already set
|
// Check if var is already set
|
||||||
@@ -42,6 +36,13 @@ func (e *Executor) collectAllRequiredVars(calls []*Call) ([]*ast.VarsWithValidat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only skip recursion if already visited (to avoid infinite loops)
|
||||||
|
// We already collected the vars above, so we're good
|
||||||
|
if visited[call.Task] {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
visited[call.Task] = true
|
||||||
|
|
||||||
// Recurse into deps
|
// Recurse into deps
|
||||||
for _, dep := range compiledTask.Deps {
|
for _, dep := range compiledTask.Deps {
|
||||||
depCall := &Call{
|
depCall := &Call{
|
||||||
|
|||||||
71
testdata/interactive_vars/Taskfile.yml
vendored
71
testdata/interactive_vars/Taskfile.yml
vendored
@@ -1,66 +1,27 @@
|
|||||||
version: "3"
|
version: "3"
|
||||||
|
|
||||||
|
# Test case for the visited bug:
|
||||||
|
# - build is called twice with different vars
|
||||||
|
# - First call provides TARGET, second doesn't
|
||||||
|
# - BUG: we should prompt for TARGET but we don't
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
main:
|
main:
|
||||||
desc: Main task with nested deps
|
desc: Main task that calls build twice with different vars
|
||||||
deps:
|
deps:
|
||||||
- dep-a
|
- task: build
|
||||||
- dep-b
|
- task: build
|
||||||
cmds:
|
cmds:
|
||||||
- echo "Main task done!"
|
- echo "Main done"
|
||||||
|
|
||||||
dep-a:
|
build:
|
||||||
desc: Dependency A
|
desc: Build task requiring TARGET
|
||||||
deps:
|
|
||||||
- leaf-a1
|
|
||||||
- leaf-a2
|
|
||||||
cmds:
|
|
||||||
- echo "Dep A done"
|
|
||||||
|
|
||||||
dep-b:
|
|
||||||
desc: Dependency B
|
|
||||||
deps:
|
|
||||||
- leaf-b1
|
|
||||||
- leaf-b2
|
|
||||||
cmds:
|
|
||||||
- echo "Dep B done"
|
|
||||||
|
|
||||||
leaf-a1:
|
|
||||||
desc: Leaf A1 with enum
|
|
||||||
requires:
|
requires:
|
||||||
vars:
|
vars:
|
||||||
- name: VAR_A1
|
- name: TARGET
|
||||||
enum:
|
enum:
|
||||||
- alpha
|
- linux
|
||||||
- beta
|
- windows
|
||||||
- gamma
|
- darwin
|
||||||
cmds:
|
cmds:
|
||||||
- echo "Leaf A1 {{.VAR_A1}}"
|
- echo "Building for target = {{.TARGET}} (mode={{.MODE}})"
|
||||||
|
|
||||||
leaf-a2:
|
|
||||||
desc: Leaf A2 with text
|
|
||||||
requires:
|
|
||||||
vars:
|
|
||||||
- VAR_A2
|
|
||||||
cmds:
|
|
||||||
- echo "Leaf A2 {{.VAR_A2}}"
|
|
||||||
|
|
||||||
leaf-b1:
|
|
||||||
desc: Leaf B1 with enum
|
|
||||||
requires:
|
|
||||||
vars:
|
|
||||||
- name: VAR_B1
|
|
||||||
enum:
|
|
||||||
- one
|
|
||||||
- two
|
|
||||||
- three
|
|
||||||
cmds:
|
|
||||||
- echo "Leaf B1 {{.VAR_B1}}"
|
|
||||||
|
|
||||||
leaf-b2:
|
|
||||||
desc: Leaf B2 with text
|
|
||||||
requires:
|
|
||||||
vars:
|
|
||||||
- VAR_B2
|
|
||||||
cmds:
|
|
||||||
- echo "Leaf B2 {{.VAR_B2}}"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user