Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: requires with task-level vars #1769

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2548,3 +2548,12 @@ func TestReference(t *testing.T) {
})
}
}

func TestRequires(t *testing.T) {
e := task.Executor{
Dir: "testdata/requires",
}
require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "requires-set"}))
require.Error(t, e.Run(context.Background(), &ast.Call{Task: "requires-not-set"}))
}
16 changes: 16 additions & 0 deletions testdata/requires/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3'

vars:
FILE_VAR: 'file_var'

tasks:
requires-set:
vars:
TASK_VAR: 'task_var'
requires:
vars: [FILE_VAR, TASK_VAR]
requires-not-set:
vars:
TASK_VAR: 'task_var'
requires:
vars: [FILE_VAR, TASK_VAR, NOT_SET_VAR]
2 changes: 1 addition & 1 deletion variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task,
Dir: templater.Replace(origTask.Dir, cache),
Set: origTask.Set,
Shopt: origTask.Shopt,
Vars: nil,
Vars: vars,
Env: nil,
Dotenv: templater.Replace(origTask.Dotenv, cache),
Silent: origTask.Silent,
Expand Down
Loading